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