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