summaryrefslogtreecommitdiffstats
path: root/libc/arch-x86/string/bzero.S
diff options
context:
space:
mode:
Diffstat (limited to 'libc/arch-x86/string/bzero.S')
-rw-r--r--libc/arch-x86/string/bzero.S43
1 files changed, 43 insertions, 0 deletions
diff --git a/libc/arch-x86/string/bzero.S b/libc/arch-x86/string/bzero.S
new file mode 100644
index 0000000..2ec9c7d
--- /dev/null
+++ b/libc/arch-x86/string/bzero.S
@@ -0,0 +1,43 @@
+/* $OpenBSD: bzero.S,v 1.3 2005/08/07 11:30:38 espie Exp $ */
+/*
+ * Written by J.T. Conklin <jtc@netbsd.org>.
+ * Public domain.
+ */
+
+#include <machine/asm.h>
+
+ENTRY(bzero)
+ pushl %edi
+ movl 8(%esp),%edi
+ movl 12(%esp),%edx
+
+ cld /* set fill direction forward */
+ xorl %eax,%eax /* set fill data to 0 */
+
+ /*
+ * if the string is too short, it's really not worth the overhead
+ * of aligning to word boundries, etc. So we jump to a plain
+ * unaligned set.
+ */
+ cmpl $16,%edx
+ jb L1
+
+ movl %edi,%ecx /* compute misalignment */
+ negl %ecx
+ andl $3,%ecx
+ subl %ecx,%edx
+ rep /* zero until word aligned */
+ stosb
+
+ movl %edx,%ecx /* zero by words */
+ shrl $2,%ecx
+ andl $3,%edx
+ rep
+ stosl
+
+L1: movl %edx,%ecx /* zero remainder by bytes */
+ rep
+ stosb
+
+ popl %edi
+ ret