xref: /openbsd/lib/libc/arch/amd64/string/bzero.S (revision 274d7c50)
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 "DEFS.h"
8
9ENTRY(bzero)
10	RETGUARD_SETUP(bzero, r11)
11	movq	%rsi,%rdx
12
13	cld				/* set fill direction forward */
14	xorq	%rax,%rax		/* set fill data to 0 */
15
16	/*
17	 * if the string is too short, it's really not worth the overhead
18	 * of aligning to word boundaries, etc.  So we jump to a plain
19	 * unaligned set.
20	 */
21	cmpq	$16,%rdx
22	jb	L1
23
24	movq	%rdi,%rcx		/* compute misalignment */
25	negq	%rcx
26	andq	$7,%rcx
27	subq	%rcx,%rdx
28	rep				/* zero until word aligned */
29	stosb
30
31	movq	%rdx,%rcx		/* zero by words */
32	shrq	$3,%rcx
33	andq	$7,%rdx
34	rep
35	stosq
36
37L1:	movq	%rdx,%rcx		/* zero remainder by bytes */
38	rep
39	stosb
40
41	RETGUARD_CHECK(bzero, r11)
42	ret
43END_WEAK(bzero)
44