bzero.S revision 144730
1/*
2 * Written by J.T. Conklin <jtc@NetBSD.org>.
3 * Public domain.
4 * Adapted for NetBSD/x86_64 by Frank van der Linden <fvdl@wasabisystems.com>
5 */
6
7#include <machine/asm.h>
8__FBSDID("$FreeBSD: head/lib/libc/amd64/string/bzero.S 144730 2005-04-07 03:56:03Z alc $");
9
10#if 0
11	RCSID("$NetBSD: bzero.S,v 1.2 2003/07/26 19:24:38 salo Exp $")
12#endif
13
14ENTRY(bzero)
15	movq	%rsi,%rdx
16
17	cld				/* set fill direction forward */
18	xorq	%rax,%rax		/* 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	cmpq	$16,%rdx
26	jb	L1
27
28	movq	%rdi,%rcx		/* compute misalignment */
29	negq	%rcx
30	andq	$7,%rcx
31	subq	%rcx,%rdx
32	rep				/* zero until word aligned */
33	stosb
34
35	movq	%rdx,%rcx		/* zero by words */
36	shrq	$3,%rcx
37	andq	$7,%rdx
38	rep
39	stosq
40
41L1:	movq	%rdx,%rcx		/* zero remainder by bytes */
42	rep
43	stosb
44
45	ret
46