LibC: Implement some mem* and str* functions in assembly
This made them a lot faster on modern cpus with optimized rep stos and rep movs
This commit is contained in:
85
userspace/libraries/LibC/arch/i686/string.S
Normal file
85
userspace/libraries/LibC/arch/i686/string.S
Normal file
@@ -0,0 +1,85 @@
|
||||
.global memchr
|
||||
memchr:
|
||||
xchgl 4(%esp), %edi
|
||||
movl 8(%esp), %eax
|
||||
movl 12(%esp), %ecx
|
||||
repne scasb
|
||||
xorl %eax, %eax
|
||||
testl %ecx, %ecx
|
||||
cmovnzl %edi, %eax
|
||||
movl 4(%esp), %edi
|
||||
ret
|
||||
|
||||
.global memcmp
|
||||
memcmp:
|
||||
xchgl 4(%esp), %edi
|
||||
xchgl 8(%esp), %esi
|
||||
movl 12(%esp), %ecx
|
||||
repe cmpsb
|
||||
jne .memcmp_not_equal
|
||||
xorl %eax, %eax
|
||||
jmp .memcmp_done
|
||||
.memcmp_not_equal:
|
||||
movzbl -1(%edi), %eax
|
||||
movzbl -1(%esi), %ecx
|
||||
subl %ecx, %eax
|
||||
.memcmp_done:
|
||||
movl 4(%esp), %edi
|
||||
movl 8(%esp), %esi
|
||||
ret
|
||||
|
||||
.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
|
||||
|
||||
.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
|
||||
|
||||
.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
|
||||
|
||||
.global strlen
|
||||
strlen:
|
||||
xchgl 4(%esp), %edi
|
||||
xorb %al, %al
|
||||
movl $-1, %ecx
|
||||
repne scasb
|
||||
movl 4(%esp), %edi
|
||||
movl $-2, %eax
|
||||
subl %ecx, %eax
|
||||
ret
|
||||
Reference in New Issue
Block a user