Super User's BSD Cross Reference: /OpenBSD/sys/lib/libkern/arch/amd64/memset.S

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
9 ENTRY(memset)
10 RETGUARD_SETUP(memset, r10)
11 movq %rsi,%rax
12 andq $0xff,%rax
13 movq %rdx,%rcx
14 movq %rdi,%r11
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 $0x0f,%rcx
22 jle 1f
23
24 movb %al,%ah /* copy char to all bytes in word */
25 movl %eax,%edx
26 sall $16,%eax
27 orl %edx,%eax
28
29 movl %eax,%edx
30 salq $32,%rax
31 orq %rdx,%rax
32
33 movq %rdi,%rdx /* compute misalignment */
34 negq %rdx
35 andq $7,%rdx
36 movq %rcx,%r8
37 subq %rdx,%r8
38
39 movq %rdx,%rcx /* set until word aligned */
40 rep
41 stosb
42
43 movq %r8,%rcx
44 shrq $3,%rcx /* set by words */
45 rep
46 stosq
47
48 movq %r8,%rcx /* set remainder by bytes */
49 andq $7,%rcx
50 1: rep
51 stosb
52 movq %r11,%rax
53 RETGUARD_CHECK(memset, r10)
54 ret
55 lfence
56 END(memset)
57 

AltStyle によって変換されたページ (->オリジナル) /