further simplify and optimize new cond var
[musl] / src / string / x86_64 / memset.s
1 .global memset
2 .type memset,@function
3 memset:
4         and $0xff,%esi
5         mov $0x101010101010101,%rax
6         mov %rdx,%rcx
7         mov %rdi,%r8
8         imul %rsi,%rax
9         cmp $16,%rcx
10         jb 1f
11
12         mov %rax,-8(%rdi,%rcx)
13         shr $3,%rcx
14         rep
15         stosq
16         mov %r8,%rax
17         ret
18
19 1:      test %ecx,%ecx
20         jz 1f
21
22         mov %al,(%rdi)
23         mov %al,-1(%rdi,%rcx)
24         cmp $2,%ecx
25         jbe 1f
26
27         mov %al,1(%rdi)
28         mov %al,-2(%rdi,%rcx)
29         cmp $4,%ecx
30         jbe 1f
31
32         mov %eax,(%rdi)
33         mov %eax,-4(%rdi,%rcx)
34         cmp $8,%ecx
35         jbe 1f
36
37         mov %eax,4(%rdi)
38         mov %eax,-8(%rdi,%rcx)
39
40 1:      mov %r8,%rax
41         ret