Deleted Added
full compact
memset.S (144730) memset.S (184547)
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>
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/memset.S 144730 2005-04-07 03:56:03Z alc $");
8__FBSDID("$FreeBSD: head/lib/libc/amd64/string/memset.S 184547 2008-11-02 01:10:54Z peter $");
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
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)