fxlibc/src/libc/string/target/sh-generic/strlen.S

37 lines
537 B
ArmAsm

.global _strlen
.type _strlen, @function
_strlen:
mov r4, r0
mov #0, r2
/* Check 3 bytes to make sure we don't skip any when aligning */
mov.b @r0+, r1
tst r1, r1
bt .end
mov.b @r0+, r1
tst r1, r1
bt .end
mov.b @r0+, r1
tst r1, r1
bt .end
/* Align to a 4-byte boundary */
or #3, r0
xor #3, r0
/* Read bytes by groups of 4 */
1: mov.l @r0+, r1
cmp/str r1, r2
bf 1b
/* Go back to find out which of the last 4 bytes is the NUL */
add #-4, r0
2: mov.b @r0+, r1
tst r1, r1
bf 2b
.end: add #-1, r0
rts
sub r4, r0