cbnz/cbz can not branch backwards so nuke 'em.
Use the same register usage in strlen as in strnlen
This commit is contained in:
parent
3c46e5578f
commit
ddea6e9586
@ -29,30 +29,22 @@
|
||||
|
||||
#include <machine/asm.h>
|
||||
|
||||
RCSID("$NetBSD: strcat_naive.S,v 1.2 2013/08/19 02:54:02 matt Exp $")
|
||||
RCSID("$NetBSD: strcat_naive.S,v 1.3 2013/08/19 17:02:25 matt Exp $")
|
||||
|
||||
ENTRY(strcat)
|
||||
mov ip, r0 /* need to preserve r0 */
|
||||
#if defined(__thumb__)
|
||||
1: ldrb r2, [r0] /* load next byte */
|
||||
adds r0, r0, #1 /* advance */
|
||||
#if defined(_ARM_ARCH_T2)
|
||||
cbnz r2, 1b /* was it a NUL? no, get next byte */
|
||||
#else
|
||||
cmp r2, #0 /* was it a NUL? */
|
||||
bne 1b /* no, get next byte */
|
||||
#endif
|
||||
subs r0, r0, #1 /* back up one to the NUL */
|
||||
subs r1, r1, r0 /* save one increment */
|
||||
2: ldrb r2, [r1, r0] /* load next byte from append */
|
||||
strb r2, [r0] /* store it */
|
||||
adds r0, r0, #1 /* advance */
|
||||
#if defined(_ARM_ARCH_T2)
|
||||
cbnz r2, 1b /* was it a NUL? no, get next byte */
|
||||
#else
|
||||
cmp r2, #0 /* was it a NUL? */
|
||||
bne 2b /* no, get next byte */
|
||||
#endif
|
||||
mov r0, ip /* restore dst address */
|
||||
RET /* return */
|
||||
#else /* !__thumb__ */
|
||||
|
@ -28,7 +28,7 @@
|
||||
*/
|
||||
#include <machine/asm.h>
|
||||
|
||||
RCSID("$NetBSD: strchr_naive.S,v 1.3 2013/08/19 02:22:25 matt Exp $")
|
||||
RCSID("$NetBSD: strchr_naive.S,v 1.4 2013/08/19 17:02:25 matt Exp $")
|
||||
|
||||
/* LINTSTUB: char * strchr(const char *, int) */
|
||||
ENTRY(strchr)
|
||||
@ -39,12 +39,8 @@ ENTRY(strchr)
|
||||
cmp r3, r1 /* does it match? */
|
||||
beq 2f /* yes, set return value */
|
||||
adds r0, r0, #1 /* advance to next byte */
|
||||
#ifdef _ARM_ARCH_T2
|
||||
cbnz r3, 1b /* was it a NUL? no, get next byte */
|
||||
#else
|
||||
cmp r3, #0 /* was it a NUL? */
|
||||
bne 1b /* no, get next byte */
|
||||
#endif
|
||||
movs r0, #0 /* set return to NULL */
|
||||
2: RET /* return */
|
||||
#else
|
||||
|
@ -28,7 +28,7 @@
|
||||
*/
|
||||
#include <machine/asm.h>
|
||||
|
||||
RCSID("$NetBSD: strlen_naive.S,v 1.7 2013/08/19 02:13:13 matt Exp $")
|
||||
RCSID("$NetBSD: strlen_naive.S,v 1.8 2013/08/19 17:02:25 matt Exp $")
|
||||
|
||||
#ifdef STRNLEN
|
||||
/* LINTSTUB: size_t strnlen(const char *, size_t) */
|
||||
@ -58,17 +58,17 @@ END(strnlen)
|
||||
#else /* STRNLEN */
|
||||
/* LINTSTUB: size_t strlen(const char *) */
|
||||
ENTRY(strlen)
|
||||
adds r2, r0, #1 /* start of src + NUL */
|
||||
adds r3, r0, #1 /* start of src + NUL */
|
||||
1:
|
||||
#ifdef __thumb__
|
||||
ldrb r3, [r0] /* read a byte */
|
||||
ldrb r2, [r0] /* read a byte */
|
||||
adds r0, r0, #1
|
||||
#else
|
||||
ldrb r3, [r0], #1 /* read a byte */
|
||||
ldrb r2, [r0], #1 /* read a byte */
|
||||
#endif
|
||||
cmp r3, #0 /* is it a NUL? */
|
||||
cmp r2, #0 /* is it a NUL? */
|
||||
bne 1b /* no, get next byte */
|
||||
subs r0, r0, r2 /* return difference between start and end */
|
||||
subs r0, r0, r3 /* return difference between start and end */
|
||||
RET
|
||||
END(strlen)
|
||||
#endif /* !STRNLEN */
|
||||
|
@ -28,7 +28,7 @@
|
||||
*/
|
||||
#include <machine/asm.h>
|
||||
|
||||
RCSID("$NetBSD: strrchr_naive.S,v 1.3 2013/08/19 02:36:27 matt Exp $")
|
||||
RCSID("$NetBSD: strrchr_naive.S,v 1.4 2013/08/19 17:02:25 matt Exp $")
|
||||
|
||||
/* LINTSTUB: char * strrchr(const char *, int) */
|
||||
ENTRY(strrchr)
|
||||
@ -42,12 +42,8 @@ ENTRY(strrchr)
|
||||
bne 2f /* no, go and advance */
|
||||
mov r0, r2 /* yes, set return value to point to it */
|
||||
2: adds r2, r2, #1 /* advance to next byte */
|
||||
#ifdef _ARM_ARCH_T2
|
||||
cbnz r3, 1b /* was it a NUL? no, get next byte */
|
||||
#else
|
||||
cmp r3, #0 /* was it a NUL? */
|
||||
bne 1b /* no, get next byte */
|
||||
#endif
|
||||
#else
|
||||
and r1, r1, #0xff /* restrict to a byte value */
|
||||
1: ldrb r3, [r2], #1 /* read a byte */
|
||||
|
Loading…
Reference in New Issue
Block a user