xref: /freebsd/lib/libc/amd64/string/memset.S (revision b1f9167f94059fd55c630891d359bcff987bd7eb)
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$");
9
10#if 0
11	RCSID("$NetBSD: memset.S,v 1.3 2004/02/26 20:50:06 drochner Exp $")
12#endif
13
14ENTRY(memset)
15	movq	%rsi,%rax
16	andq	$0xff,%rax
17	movq	%rdx,%rcx
18	movq	%rdi,%r11
19
20	cld				/* set fill direction forward */
21
22	/*
23	 * if the string is too short, it's really not worth the overhead
24	 * of aligning to word boundries, etc.  So we jump to a plain
25	 * unaligned set.
26	 */
27	cmpq	$0x0f,%rcx
28	jle	L1
29
30	movb	%al,%ah			/* copy char to all bytes in word */
31	movl	%eax,%edx
32	sall	$16,%eax
33	orl	%edx,%eax
34
35	movl	%eax,%edx
36	salq	$32,%rax
37	orq	%rdx,%rax
38
39	movq	%rdi,%rdx		/* compute misalignment */
40	negq	%rdx
41	andq	$7,%rdx
42	movq	%rcx,%r8
43	subq	%rdx,%r8
44
45	movq	%rdx,%rcx		/* set until word aligned */
46	rep
47	stosb
48
49	movq	%r8,%rcx
50	shrq	$3,%rcx			/* set by words */
51	rep
52	stosq
53
54	movq	%r8,%rcx		/* set remainder by bytes */
55	andq	$7,%rcx
56L1:	rep
57	stosb
58	movq	%r11,%rax
59
60	ret
61END(memset)
62
63	.section .note.GNU-stack,"",%progbits
64