xref: /netbsd-src/lib/libc/arch/i386/string/bzero.S (revision 954b7961567b96e7f5bdebca46dec63f6369e771)
1/*
2 * Written by J.T. Conklin <jtc@netbsd.org>.
3 * Public domain.
4 */
5
6#include <machine/asm.h>
7
8#if defined(LIBC_SCCS)
9	RCSID("$Id: bzero.S,v 1.7 1995/04/28 22:54:05 jtc Exp $")
10#endif
11
12ENTRY(bzero)
13	pushl	%edi
14	movl	8(%esp),%edi
15	movl	12(%esp),%edx
16
17	cld				/* set fill direction forward */
18	xorl	%eax,%eax		/* set fill data to 0 */
19
20	/*
21	 * if the string is too short, it's really not worth the overhead
22	 * of aligning to word boundries, etc.  So we jump to a plain
23	 * unaligned set.
24	 */
25	cmpl	$16,%edx
26	jb	L1
27
28	movl	%edi,%ecx		/* compute misalignment */
29	negl	%ecx
30	andl	$3,%ecx
31	subl	%ecx,%edx
32	rep				/* zero until word aligned */
33	stosb
34
35	movl	%edx,%ecx		/* zero by words */
36	shrl	$2,%ecx
37	andl	$3,%edx
38	rep
39	stosl
40
41L1:	movl	%edx,%ecx		/* zero remainder by bytes */
42	rep
43	stosb
44
45	popl	%edi
46	ret
47