xref: /openbsd-src/lib/libc/arch/i386/string/bzero.S (revision b2ea75c1b17e1a9a339660e7ed45cd24946b230e)
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	.text
10	.asciz "$OpenBSD: bzero.S,v 1.2 1996/08/19 08:12:56 tholo Exp $"
11#endif
12
13ENTRY(bzero)
14	pushl	%edi
15	movl	8(%esp),%edi
16	movl	12(%esp),%edx
17
18	cld				/* set fill direction forward */
19	xorl	%eax,%eax		/* set fill data to 0 */
20
21	/*
22	 * if the string is too short, it's really not worth the overhead
23	 * of aligning to word boundries, etc.  So we jump to a plain
24	 * unaligned set.
25	 */
26	cmpl	$16,%edx
27	jb	L1
28
29	movl	%edi,%ecx		/* compute misalignment */
30	negl	%ecx
31	andl	$3,%ecx
32	subl	%ecx,%edx
33	rep				/* zero until word aligned */
34	stosb
35
36	movl	%edx,%ecx		/* zero by words */
37	shrl	$2,%ecx
38	andl	$3,%edx
39	rep
40	stosl
41
42L1:	movl	%edx,%ecx		/* zero remainder by bytes */
43	rep
44	stosb
45
46	popl	%edi
47	ret
48