Optimize strcpy(): 1- Conditional moves (I keep forgetting about them) 2- Better setting of RCX (better accounting for EOS)
This commit is contained in:
@@ -27,26 +27,23 @@ strlen:
|
||||
; Return value: Pointer to dest
|
||||
; Used registers:
|
||||
; rax* (ret) Pointer to dest[]
|
||||
; rdi (arg) Pointer to dest[]
|
||||
; rsi (arg) Pointer to src[]
|
||||
; rdx (arg) Max amount of characters to copy / size of dest[] <!>Must never be greater than size of dest[]!
|
||||
; rdi* (arg) Pointer to dest[]
|
||||
; rsi* (arg) Pointer to src[]
|
||||
; rdx (arg) Size of dest[]
|
||||
; rcx* Counter for movsb
|
||||
; r8* Backup for rdi
|
||||
strcpy:
|
||||
mov r8, rdi
|
||||
mov rdi, rsi
|
||||
call strlen
|
||||
mov rcx, rdx
|
||||
cmp rcx, rax
|
||||
je .decMaxLen ;rcx-1 for EOS
|
||||
ja .setMaxLen ;set rcx to strlen(src)
|
||||
jmp .copy
|
||||
.decMaxLen:
|
||||
inc rax
|
||||
cmp rax, rdx
|
||||
cmova rcx, rdx
|
||||
cmovbe rcx, rax
|
||||
cmp rcx, rdx
|
||||
jb .copy
|
||||
dec rcx
|
||||
jmp .copy
|
||||
.setMaxLen:
|
||||
mov rcx, rax
|
||||
.copy:
|
||||
.copy
|
||||
mov rdi, r8
|
||||
rep movsb
|
||||
mov byte [rdi], EOS
|
||||
|
Reference in New Issue
Block a user