LibC: Add SSE2 non-temporal memset and memcpy
Also cleanup other assembly by using local labels to emit them from the assembled program.
This commit is contained in:
47
kernel/klibc/arch/i686/string.S
Normal file
47
kernel/klibc/arch/i686/string.S
Normal file
@@ -0,0 +1,47 @@
|
||||
.align 16
|
||||
.global memcpy
|
||||
memcpy:
|
||||
xchgl 4(%esp), %edi
|
||||
xchgl 8(%esp), %esi
|
||||
movl 12(%esp), %ecx
|
||||
movl %edi, %edx
|
||||
rep movsb
|
||||
movl 4(%esp), %edi
|
||||
movl 8(%esp), %esi
|
||||
movl %edx, %eax
|
||||
ret
|
||||
|
||||
.align 16
|
||||
.global memmove
|
||||
memmove:
|
||||
xchgl 4(%esp), %edi
|
||||
xchgl 8(%esp), %esi
|
||||
movl 12(%esp), %ecx
|
||||
movl %edi, %edx
|
||||
cmpl %edi, %esi
|
||||
jb .memmove_slow
|
||||
rep movsb
|
||||
.memmove_done:
|
||||
movl 4(%esp), %edi
|
||||
movl 8(%esp), %esi
|
||||
movl %edx, %eax
|
||||
ret
|
||||
.memmove_slow:
|
||||
leal -1(%edi, %ecx), %edi
|
||||
leal -1(%esi, %ecx), %esi
|
||||
std
|
||||
rep movsb
|
||||
cld
|
||||
jmp .memmove_done
|
||||
|
||||
.align 16
|
||||
.global memset
|
||||
memset:
|
||||
xchgl 4(%esp), %edi
|
||||
movl 8(%esp), %eax
|
||||
movl 12(%esp), %ecx
|
||||
movl %edi, %edx
|
||||
rep stosb
|
||||
movl 4(%esp), %edi
|
||||
movl %edx, %eax
|
||||
ret
|
||||
31
kernel/klibc/arch/x86_64/string.S
Normal file
31
kernel/klibc/arch/x86_64/string.S
Normal file
@@ -0,0 +1,31 @@
|
||||
.align 16
|
||||
.global memcpy
|
||||
memcpy:
|
||||
movq %rdi, %rax
|
||||
movq %rdx, %rcx
|
||||
rep movsb
|
||||
ret
|
||||
|
||||
.align 16
|
||||
.global memmove
|
||||
memmove:
|
||||
cmpq %rdi, %rsi
|
||||
jae memcpy
|
||||
movq %rdi, %rax
|
||||
leaq -1(%rdi, %rdx), %rdi
|
||||
leaq -1(%rsi, %rdx), %rsi
|
||||
movq %rdx, %rcx
|
||||
std
|
||||
rep movsb
|
||||
cld
|
||||
ret
|
||||
|
||||
.align 16
|
||||
.global memset
|
||||
memset:
|
||||
movq %rdi, %r8
|
||||
movb %sil, %al
|
||||
movq %rdx, %rcx
|
||||
rep stosb
|
||||
movq %r8, %rax
|
||||
ret
|
||||
Reference in New Issue
Block a user