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