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