|
|
bca718 |
Backport of
|
|
|
bca718 |
commit 72607db038df1a1a7987af814aad8d2ed466c45c
|
|
|
bca718 |
Author: Rajalakshmi Srinivasaraghavan <raji@linux.vnet.ibm.com>
|
|
|
bca718 |
Date: Fri Jan 9 11:56:35 2015 -0500
|
|
|
bca718 |
|
|
|
bca718 |
powerpc: Optimize POWER7 strcmp trailing checks
|
|
|
bca718 |
|
|
|
bca718 |
This patch optimized the POWER7 trailing check by avoiding using byte
|
|
|
bca718 |
read operations and instead use the doubleword already readed with
|
|
|
bca718 |
bitwise operations.
|
|
|
bca718 |
|
|
|
bca718 |
ChangeLog:
|
|
|
bca718 |
2015-01-13 Rajalakshmi Srinivasaraghavan <raji@linux.vnet.ibm.com>
|
|
|
bca718 |
Adhemerval Zanella <azanella@linux.vnet.ibm.com>
|
|
|
bca718 |
|
|
|
bca718 |
* sysdeps/powerpc/powerpc64/power7/strcmp.S (strcmp): Optimize
|
|
|
bca718 |
trailing byte check.
|
|
|
bca718 |
|
|
|
bca718 |
diff --git a/sysdeps/powerpc/powerpc64/power7/strcmp.S b/sysdeps/powerpc/powerpc64/power7/strcmp.S
|
|
|
bca718 |
index f16a9d8..ade2811 100644
|
|
|
bca718 |
--- a/sysdeps/powerpc/powerpc64/power7/strcmp.S
|
|
|
bca718 |
+++ b/sysdeps/powerpc/powerpc64/power7/strcmp.S
|
|
|
bca718 |
@@ -25,122 +25,96 @@
|
|
|
bca718 |
|
|
|
bca718 |
/* int [r3] strcmp (const char *s1 [r3], const char *s2 [r4]) */
|
|
|
bca718 |
|
|
|
bca718 |
+ .machine power7
|
|
|
bca718 |
EALIGN (strcmp, 4, 0)
|
|
|
bca718 |
CALL_MCOUNT 2
|
|
|
bca718 |
|
|
|
bca718 |
or r9, r3, r4
|
|
|
bca718 |
rldicl. r10, r9, 0, 61 /* are s1 and s2 8 byte aligned..? */
|
|
|
bca718 |
bne cr0, L(process_unaligned_bytes)
|
|
|
bca718 |
+ li r5, 0
|
|
|
bca718 |
|
|
|
bca718 |
+ .align 4
|
|
|
bca718 |
/* process input parameters on double word aligned boundary */
|
|
|
bca718 |
- ld r9, 0(r4) /* load s2 at offset=0 */
|
|
|
bca718 |
- li r10, 0 /* load mask=0 */
|
|
|
bca718 |
- cmpb r10, r9, r10 /* compare bytes at s2 with mask */
|
|
|
bca718 |
- cmpdi cr7, r10, 0 /* is NULL found ..? is end of string HIT */
|
|
|
bca718 |
- bne cr7, L(process_unaligned_bytes) /* process byte by byte */
|
|
|
bca718 |
-
|
|
|
bca718 |
- ld r10, 0(r3) /* load s1 at offset=0 */
|
|
|
bca718 |
- li r8, 0 /* load mask=0 */
|
|
|
bca718 |
- cmpb r8, r10, r8 /* compare bytes at s1 with mask */
|
|
|
bca718 |
- cmpdi cr7, r8, 0 /* is NULL found ..? is end of string HIT */
|
|
|
bca718 |
- bne cr7, L(process_unaligned_bytes) /* process byte by byte */
|
|
|
bca718 |
-
|
|
|
bca718 |
-/*s1 and s2 does not contain NULL now , so compare all 8 bytes in a GO */
|
|
|
bca718 |
- cmpb r9, r10, r9 /* compare s1 and s2 */
|
|
|
bca718 |
- cmpdi cr7, r9, -1 /* compare result with 0xFFFFFFFFFFFFFFFF */
|
|
|
bca718 |
- bne cr7, L(process_unaligned_bytes) /* s1,s2 mismatch found */
|
|
|
bca718 |
-
|
|
|
bca718 |
- addi r5, r3, 8 /* save next offset of s2 */
|
|
|
bca718 |
- addi r11, r4, 8 /* save next offset of s1 */
|
|
|
bca718 |
- ld r8, 8(r4) /* load s2 at offset=8 */
|
|
|
bca718 |
- li r9, 0 /* load mask=0 */
|
|
|
bca718 |
- cmpb r9, r8, r9 /* compare bytes at s2 with mask */
|
|
|
bca718 |
- cmpdi cr7, r9, 0 /* NULL found ..? */
|
|
|
bca718 |
- bne cr7, L(processBytes)/* update input and process bytes one by one */
|
|
|
bca718 |
-
|
|
|
bca718 |
- mr r9, r4 /* save s2 */
|
|
|
bca718 |
- li r10, 0 /* load mask=0 */
|
|
|
bca718 |
-
|
|
|
bca718 |
- ld r7, 8(r3) /* load s1 at offset=8 */
|
|
|
bca718 |
- cmpb r6, r7, r10 /* compare bytes at s1 with mask */
|
|
|
bca718 |
- cmpdi cr7, r6, 0 /* is NULL found */
|
|
|
bca718 |
- bne cr7, L(processBytes)/* mismatch, so process one by one */
|
|
|
bca718 |
-
|
|
|
bca718 |
L(unrollDword):
|
|
|
bca718 |
- cmpb r8, r7, r8 /* compare s1 and s2 */
|
|
|
bca718 |
- cmpdi cr7, r8, -1 /* compare result with 0xFFFFFFFFFFFFFFFF */
|
|
|
bca718 |
- bne cr7, L(processBytes)/* mismatch with s1 and s2 */
|
|
|
bca718 |
-
|
|
|
bca718 |
- addi r5, r3, 16 /* save offset=16 of s1 */
|
|
|
bca718 |
- addi r4, r9, 16 /* save offset=16 of s2 */
|
|
|
bca718 |
- ld r8, 16(r9) /* load s2 at offset=16 */
|
|
|
bca718 |
- cmpb r7, r8, r10 /* compare bytes at s2 with mask */
|
|
|
bca718 |
- cmpdi cr7, r7, 0 /* NULL found ..? */
|
|
|
bca718 |
- bne cr7, L(update2processBytes)
|
|
|
bca718 |
-
|
|
|
bca718 |
- ld r7, 16(r3) /* load s1 at offset=16 */
|
|
|
bca718 |
- cmpb r6, r7, r10 /* check s1 for end of string */
|
|
|
bca718 |
- cmpdi cr7, r6, 0 /* end of s1 ?,then handle byte by byte */
|
|
|
bca718 |
- bne 7,L(update2processBytes)
|
|
|
bca718 |
-
|
|
|
bca718 |
- cmpb r8, r7, r8 /* compare s1 and s2 double words */
|
|
|
bca718 |
- cmpdi cr7, r8, -1 /* compare results with 0xFFFFFFFFFFFFFFFF */
|
|
|
bca718 |
- bne cr7,L(update2processBytes)
|
|
|
bca718 |
-
|
|
|
bca718 |
- addi r5, r3, 24 /* update s1 to offset=24 */
|
|
|
bca718 |
- addi r4, r9, 24 /* update s2 to offset=24 */
|
|
|
bca718 |
-
|
|
|
bca718 |
- ld r8, 24(r9) /* load s2 */
|
|
|
bca718 |
- cmpb r7, r8, r10 /* compare s2 for NULL */
|
|
|
bca718 |
- cmpdi cr7, r7, 0 /* verify if s2 is ending now */
|
|
|
bca718 |
- bne cr7,L(update2processBytes)
|
|
|
bca718 |
-
|
|
|
bca718 |
- ld r7, 24(r3) /* load s1 at offset=24 */
|
|
|
bca718 |
- cmpb r6, r7, r10 /* verify for NULL */
|
|
|
bca718 |
- cmpdi cr7, r6, 0 /* is NULL found */
|
|
|
bca718 |
- bne cr7, L(update2processBytes)
|
|
|
bca718 |
-
|
|
|
bca718 |
- cmpb r8, r7, r8 /* compare s1 and s2 */
|
|
|
bca718 |
- cmpdi cr7, r8, -1 /* are s1 and s2 same ..? */
|
|
|
bca718 |
- bne cr7, L(update2processBytes)
|
|
|
bca718 |
-
|
|
|
bca718 |
- addi r7, r9, 32 /* update s2 to next double word */
|
|
|
bca718 |
- addi r3, r3, 32 /* update s1 to next double word */
|
|
|
bca718 |
-
|
|
|
bca718 |
- ld r8, 32(r9) /* load s2 */
|
|
|
bca718 |
- mr r4, r7 /* save s2 */
|
|
|
bca718 |
- cmpb r6, r8, r10 /* compare s2 with NULL */
|
|
|
bca718 |
- cmpdi cr7, r6, 0 /* end of s2 ..? */
|
|
|
bca718 |
- bne cr7, L(process_unaligned_bytes)
|
|
|
bca718 |
-
|
|
|
bca718 |
- ld r6, 0(r3) /* load and compare s1 for NULL */
|
|
|
bca718 |
- cmpb r5, r6, r10
|
|
|
bca718 |
- cmpdi cr7, r5, 0
|
|
|
bca718 |
- bne cr7, L(process_unaligned_bytes)
|
|
|
bca718 |
-
|
|
|
bca718 |
- cmpb r8, r6, r8 /* compare s1 and s2 */
|
|
|
bca718 |
- cmpdi cr7, r8, -1
|
|
|
bca718 |
- bne cr7, L(process_unaligned_bytes)
|
|
|
bca718 |
-
|
|
|
bca718 |
- addi r5, r3, 8 /* increment s1 and d2 here */
|
|
|
bca718 |
- addi r11, r9, 40
|
|
|
bca718 |
-
|
|
|
bca718 |
- ld r8, 40(r9) /* process s2 now */
|
|
|
bca718 |
- cmpb r9, r8, r10
|
|
|
bca718 |
- cmpdi cr7, r9, 0
|
|
|
bca718 |
- bne cr7, L(processBytes)
|
|
|
bca718 |
-
|
|
|
bca718 |
- mr r9, r7
|
|
|
bca718 |
- ld r7, 8(r3) /* process s1 now */
|
|
|
bca718 |
- cmpb r6, r7, r10
|
|
|
bca718 |
- cmpdi cr7, r6, 0
|
|
|
bca718 |
- beq cr7, L(unrollDword) /* unroll to compare s1 and s2 */
|
|
|
bca718 |
-
|
|
|
bca718 |
-L(processBytes):
|
|
|
bca718 |
- mr r4, r11 /* update input params */
|
|
|
bca718 |
- mr r3, r5
|
|
|
bca718 |
-
|
|
|
bca718 |
- .p2align 4
|
|
|
bca718 |
+ ld r8,0(r3)
|
|
|
bca718 |
+ ld r10,0(r4)
|
|
|
bca718 |
+ cmpb r7,r8,r5
|
|
|
bca718 |
+ cmpdi cr7,r7,0
|
|
|
bca718 |
+ mr r9,r7
|
|
|
bca718 |
+ bne cr7,L(null_found)
|
|
|
bca718 |
+ cmpld cr7,r8,r10
|
|
|
bca718 |
+ bne cr7,L(different)
|
|
|
bca718 |
+
|
|
|
bca718 |
+ ld r8,8(r3)
|
|
|
bca718 |
+ ld r10,8(r4)
|
|
|
bca718 |
+ cmpb r7,r8,r5
|
|
|
bca718 |
+ cmpdi cr7,r7,0
|
|
|
bca718 |
+ mr r9,r7
|
|
|
bca718 |
+ bne cr7,L(null_found)
|
|
|
bca718 |
+ cmpld cr7,r8,r10
|
|
|
bca718 |
+ bne cr7,L(different)
|
|
|
bca718 |
+
|
|
|
bca718 |
+ ld r8,16(r3)
|
|
|
bca718 |
+ ld r10,16(r4)
|
|
|
bca718 |
+ cmpb r7,r8,r5
|
|
|
bca718 |
+ cmpdi cr7,r7,0
|
|
|
bca718 |
+ mr r9,r7
|
|
|
bca718 |
+ bne cr7,L(null_found)
|
|
|
bca718 |
+ cmpld cr7,r8,r10
|
|
|
bca718 |
+ bne cr7,L(different)
|
|
|
bca718 |
+
|
|
|
bca718 |
+ ld r8,24(r3)
|
|
|
bca718 |
+ ld r10,24(r4)
|
|
|
bca718 |
+ cmpb r7,r8,r5
|
|
|
bca718 |
+ cmpdi cr7,r7,0
|
|
|
bca718 |
+ mr r9,r7
|
|
|
bca718 |
+ bne cr7,L(null_found)
|
|
|
bca718 |
+ cmpld cr7,r8,r10
|
|
|
bca718 |
+ bne cr7,L(different)
|
|
|
bca718 |
+
|
|
|
bca718 |
+ addi r3, r3, 32
|
|
|
bca718 |
+ addi r4, r4, 32
|
|
|
bca718 |
+ beq cr7, L(unrollDword)
|
|
|
bca718 |
+
|
|
|
bca718 |
+ .align 4
|
|
|
bca718 |
+L(null_found):
|
|
|
bca718 |
+#ifdef __LITTLE_ENDIAN__
|
|
|
bca718 |
+ neg r7,r9
|
|
|
bca718 |
+ and r9,r9,r7
|
|
|
bca718 |
+ li r7,-1
|
|
|
bca718 |
+ cntlzd r9,r9
|
|
|
bca718 |
+ subfic r9,r9,71
|
|
|
bca718 |
+ sld r9,r7,r9
|
|
|
bca718 |
+#else
|
|
|
bca718 |
+ cntlzd r9,r9
|
|
|
bca718 |
+ li r7,-1
|
|
|
bca718 |
+ addi r9,r9,8
|
|
|
bca718 |
+ srd r9,r7,r9
|
|
|
bca718 |
+#endif
|
|
|
bca718 |
+ or r8,r8,r9
|
|
|
bca718 |
+ or r10,r10,r9
|
|
|
bca718 |
+
|
|
|
bca718 |
+L(different):
|
|
|
bca718 |
+ cmpb r9,r8,r10
|
|
|
bca718 |
+#ifdef __LITTLE_ENDIAN__
|
|
|
bca718 |
+ addi r7,r9,1
|
|
|
bca718 |
+ andc r9,r7,r9
|
|
|
bca718 |
+ cntlzd r9,r9
|
|
|
bca718 |
+ subfic r9,r9,63
|
|
|
bca718 |
+#else
|
|
|
bca718 |
+ not r9,r9
|
|
|
bca718 |
+ cntlzd r9,r9
|
|
|
bca718 |
+ subfic r9,r9,56
|
|
|
bca718 |
+#endif
|
|
|
bca718 |
+ srd r3,r8,r9
|
|
|
bca718 |
+ srd r10,r10,r9
|
|
|
bca718 |
+ rldicl r10,r10,0,56
|
|
|
bca718 |
+ rldicl r3,r3,0,56
|
|
|
bca718 |
+ subf r3,r10,r3
|
|
|
bca718 |
+ blr
|
|
|
bca718 |
+
|
|
|
bca718 |
+ .align 4
|
|
|
bca718 |
L(process_unaligned_bytes):
|
|
|
bca718 |
lbz r9, 0(r3) /* load byte from s1 */
|
|
|
bca718 |
lbz r10, 0(r4) /* load byte from s2 */
|
|
|
bca718 |
@@ -172,24 +146,19 @@ L(process_unaligned_bytes):
|
|
|
bca718 |
addi r4, r4, 4 /* increment s2 by unroll factor */
|
|
|
bca718 |
beq cr6, L(process_unaligned_bytes) /* unroll byte processing */
|
|
|
bca718 |
|
|
|
bca718 |
- .p2align 4
|
|
|
bca718 |
+ .align 4
|
|
|
bca718 |
L(ComputeDiff):
|
|
|
bca718 |
extsw r9, r9
|
|
|
bca718 |
subf r10, r10, r9 /* compute s1 - s2 */
|
|
|
bca718 |
extsw r3, r10
|
|
|
bca718 |
blr /* return */
|
|
|
bca718 |
|
|
|
bca718 |
- .p2align 4
|
|
|
bca718 |
+ .align 4
|
|
|
bca718 |
L(diffOfNULL):
|
|
|
bca718 |
li r9, 0
|
|
|
bca718 |
subf r10, r10, r9 /* compute s1 - s2 */
|
|
|
bca718 |
extsw r3, r10 /* sign extend result */
|
|
|
bca718 |
blr /* return */
|
|
|
bca718 |
|
|
|
bca718 |
- .p2align 4
|
|
|
bca718 |
-L(update2processBytes):
|
|
|
bca718 |
- mr r3, r5 /* update and proceed */
|
|
|
bca718 |
- b L(process_unaligned_bytes)
|
|
|
bca718 |
-
|
|
|
bca718 |
END (strcmp)
|
|
|
bca718 |
libc_hidden_builtin_def (strcmp)
|