LibC: Write memchr, memcmp and strlen with sse
This commit is contained in:
@@ -1,35 +1,3 @@
|
||||
.global memchr
|
||||
memchr:
|
||||
xchgl 4(%esp), %edi
|
||||
movl 8(%esp), %eax
|
||||
movl 12(%esp), %ecx
|
||||
movl $1, %edx
|
||||
cmpl $1, %ecx # clear ZF if count is zero
|
||||
repne scasb
|
||||
cmovel %edi, %edx
|
||||
leal -1(%edx), %eax
|
||||
movl 4(%esp), %edi
|
||||
ret
|
||||
|
||||
.global memcmp
|
||||
memcmp:
|
||||
xchgl 4(%esp), %edi
|
||||
xchgl 8(%esp), %esi
|
||||
movl 12(%esp), %ecx
|
||||
testl %ecx, %ecx # set ZF if count is zero
|
||||
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
|
||||
@@ -74,14 +42,3 @@ memset:
|
||||
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