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

1 /* $OpenBSD: memset.S,v 1.4 2014年11月29日 18:51:23 tedu Exp $ */
2
3 /*
4 * Written by J.T. Conklin <jtc@netbsd.org>.
5 * Public domain.
6 */
7
8#include <machine/asm.h>
9
10 ENTRY(memset)
11 pushl %edi
12 pushl %ebx
13 movl 12(%esp),%edi
14 movzbl 16(%esp),%eax /* unsigned char, zero extend */
15 movl 20(%esp),%ecx
16 pushl %edi /* push address of buffer */
17
18 /*
19 * if the string is too short, it's really not worth the overhead
20 * of aligning to word boundaries, etc. So we jump to a plain
21 * unaligned set.
22 */
23 cmpl $0x0f,%ecx
24 jle L1
25
26 movb %al,%ah /* copy char to all bytes in word */
27 movl %eax,%edx
28 sall $16,%eax
29 orl %edx,%eax
30
31 movl %edi,%edx /* compute misalignment */
32 negl %edx
33 andl $3,%edx
34 movl %ecx,%ebx
35 subl %edx,%ebx
36
37 movl %edx,%ecx /* set until word aligned */
38 rep
39 stosb
40
41 movl %ebx,%ecx
42 shrl $2,%ecx /* set by words */
43 rep
44 stosl
45
46 movl %ebx,%ecx /* set remainder by bytes */
47 andl $3,%ecx
48 L1: rep
49 stosb
50
51 popl %eax /* pop address of buffer */
52 popl %ebx
53 popl %edi
54 ret
55 

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