Commit ca5d0674 authored by Andreas Schwab's avatar Andreas Schwab Committed by Benjamin Herrenschmidt

powerpc: Fix string library functions

The powerpc strncmp implementation does not correctly handle a zero
length, despite the claim in 0119536c
(Add hand-coded assembly strcmp).

Additionally, all the length arguments are size_t, not int, so use
PPC_LCMPI and eq instead of cmpwi and le throughout.
Signed-off-by: default avatarAndreas Schwab <schwab@linux-m68k.org>
Acked-by: default avatarPaul Mackerras <paulus@samba.org>
Signed-off-by: default avatarBenjamin Herrenschmidt <benh@kernel.crashing.org>
parent 7358650e
...@@ -28,7 +28,7 @@ _GLOBAL(strcpy) ...@@ -28,7 +28,7 @@ _GLOBAL(strcpy)
/* This clears out any unused part of the destination buffer, /* This clears out any unused part of the destination buffer,
just as the libc version does. -- paulus */ just as the libc version does. -- paulus */
_GLOBAL(strncpy) _GLOBAL(strncpy)
cmpwi 0,r5,0 PPC_LCMPI 0,r5,0
beqlr beqlr
mtctr r5 mtctr r5
addi r6,r3,-1 addi r6,r3,-1
...@@ -39,7 +39,7 @@ _GLOBAL(strncpy) ...@@ -39,7 +39,7 @@ _GLOBAL(strncpy)
bdnzf 2,1b /* dec ctr, branch if ctr != 0 && !cr0.eq */ bdnzf 2,1b /* dec ctr, branch if ctr != 0 && !cr0.eq */
bnelr /* if we didn't hit a null char, we're done */ bnelr /* if we didn't hit a null char, we're done */
mfctr r5 mfctr r5
cmpwi 0,r5,0 /* any space left in destination buffer? */ PPC_LCMPI 0,r5,0 /* any space left in destination buffer? */
beqlr /* we know r0 == 0 here */ beqlr /* we know r0 == 0 here */
2: stbu r0,1(r6) /* clear it out if so */ 2: stbu r0,1(r6) /* clear it out if so */
bdnz 2b bdnz 2b
...@@ -70,8 +70,8 @@ _GLOBAL(strcmp) ...@@ -70,8 +70,8 @@ _GLOBAL(strcmp)
blr blr
_GLOBAL(strncmp) _GLOBAL(strncmp)
PPC_LCMPI r5,0 PPC_LCMPI 0,r5,0
ble- 2f beq- 2f
mtctr r5 mtctr r5
addi r5,r3,-1 addi r5,r3,-1
addi r4,r4,-1 addi r4,r4,-1
...@@ -94,8 +94,8 @@ _GLOBAL(strlen) ...@@ -94,8 +94,8 @@ _GLOBAL(strlen)
blr blr
_GLOBAL(memcmp) _GLOBAL(memcmp)
cmpwi 0,r5,0 PPC_LCMPI 0,r5,0
ble- 2f beq- 2f
mtctr r5 mtctr r5
addi r6,r3,-1 addi r6,r3,-1
addi r4,r4,-1 addi r4,r4,-1
...@@ -108,8 +108,8 @@ _GLOBAL(memcmp) ...@@ -108,8 +108,8 @@ _GLOBAL(memcmp)
blr blr
_GLOBAL(memchr) _GLOBAL(memchr)
cmpwi 0,r5,0 PPC_LCMPI 0,r5,0
ble- 2f beq- 2f
mtctr r5 mtctr r5
addi r3,r3,-1 addi r3,r3,-1
1: lbzu r0,1(r3) 1: lbzu r0,1(r3)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment