string: use gint's (not-so-optimized-yet) memmove (DONE)

This commit is contained in:
Lephenixnoir 2021-05-23 16:47:31 +02:00
parent fd0d67191c
commit ab8bcc6928
Signed by: Lephenixnoir
GPG Key ID: 1BBA026E13FC0495
2 changed files with 61 additions and 0 deletions

View File

@ -177,6 +177,7 @@ if(sh-generic IN_LIST TARGET_FOLDERS)
src/libc/string/target/sh-generic/memchr.S
src/libc/string/target/sh-generic/memcmp.S
src/libc/string/target/sh-generic/memcpy.S
src/libc/string/target/sh-generic/memmove.S
src/libc/string/target/sh-generic/memset.S
src/libc/string/target/sh-generic/strlen.S
src/target/sh-generic/cpucap.c)

View File

@ -0,0 +1,60 @@
.global _memmove
.text
_memmove:
tst r6, r6
bt .zero
/* Simple optimization: if regions do not overlap, use memcpy() */
mov r4, r0
add r6, r0
cmp/ge r0, r5
bt _memmove_memcpy
mov r5, r0
add r6, r0
cmp/ge r0, r4
bt _memmove_memcpy
mov r4, r3
cmp/ge r4, r5
bf .backwards
.forwards:
/* If the destination starts before the source, copy forwards */
mov.b @r5+, r0
mov.b r0, @r4
dt r6
bf/s .forwards
add #1, r4
rts
mov r3, r0
.backwards:
/* Otherwise, copy backwards */
add r6, r4
add r6, r5
.backwards_loop:
add #-1, r5
mov.b @r5, r0
dt r6
bf/s .backwards_loop
mov.b r0, @-r4
rts
mov r3, r0
_memmove_memcpy:
mov.l .memcpy, r1
jmp @r1
nop
.zero:
rts
mov r4, r0
.align 4
.memcpy:
.long _memcpy