00db10
# commit 8a7413f9b036da83ffde491a37d9d2340bc321a7
00db10
# Author: Alan Modra <amodra@gmail.com>
00db10
# Date:   Sat Aug 17 18:41:17 2013 +0930
00db10
# 
00db10
#     PowerPC LE strcmp and strncmp
00db10
#     http://sourceware.org/ml/libc-alpha/2013-08/msg00099.html
00db10
#     
00db10
#     More little-endian support.  I leave the main strcmp loops unchanged,
00db10
#     (well, except for renumbering rTMP to something other than r0 since
00db10
#     it's needed in an addi insn) and modify the tail for little-endian.
00db10
#     
00db10
#     I noticed some of the big-endian tail code was a little untidy so have
00db10
#     cleaned that up too.
00db10
#     
00db10
#         * sysdeps/powerpc/powerpc64/strcmp.S (rTMP2): Define as r0.
00db10
#         (rTMP): Define as r11.
00db10
#         (strcmp): Add little-endian support.  Optimise tail.
00db10
#         * sysdeps/powerpc/powerpc32/strcmp.S: Similarly.
00db10
#         * sysdeps/powerpc/powerpc64/strncmp.S: Likewise.
00db10
#         * sysdeps/powerpc/powerpc32/strncmp.S: Likewise.
00db10
#         * sysdeps/powerpc/powerpc64/power4/strncmp.S: Likewise.
00db10
#         * sysdeps/powerpc/powerpc32/power4/strncmp.S: Likewise.
00db10
#         * sysdeps/powerpc/powerpc64/power7/strncmp.S: Likewise.
00db10
#         * sysdeps/powerpc/powerpc32/power7/strncmp.S: Likewise.
00db10
# 
00db10
diff -urN glibc-2.17-c758a686/sysdeps/powerpc/powerpc32/power4/strncmp.S glibc-2.17-c758a686/sysdeps/powerpc/powerpc32/power4/strncmp.S
00db10
--- glibc-2.17-c758a686/sysdeps/powerpc/powerpc32/power4/strncmp.S	2014-05-28 13:26:59.000000000 -0500
00db10
+++ glibc-2.17-c758a686/sysdeps/powerpc/powerpc32/power4/strncmp.S	2014-05-28 13:27:02.000000000 -0500
00db10
@@ -26,7 +26,7 @@
00db10
 
00db10
 EALIGN (BP_SYM(strncmp), 4, 0)
00db10
 
00db10
-#define rTMP	r0
00db10
+#define rTMP2	r0
00db10
 #define rRTN	r3
00db10
 #define rSTR1	r3	/* first string arg */
00db10
 #define rSTR2	r4	/* second string arg */
00db10
@@ -42,6 +42,7 @@
00db10
 #define r7F7F	r9	/* constant 0x7f7f7f7f */
00db10
 #define rNEG	r10	/* ~(word in s1 | 0x7f7f7f7f) */
00db10
 #define rBITDIF	r11	/* bits that differ in s1 & s2 words */
00db10
+#define rTMP	r12
00db10
 
00db10
 	dcbt	0,rSTR1
00db10
 	or	rTMP, rSTR2, rSTR1
00db10
@@ -80,12 +81,45 @@
00db10
    we don't compare two strings as different because of gunk beyond
00db10
    the end of the strings...  */
00db10
 
00db10
+#ifdef __LITTLE_ENDIAN__
00db10
+L(endstring):
00db10
+	slwi	rTMP, rTMP, 1
00db10
+	addi    rTMP2, rTMP, -1
00db10
+	andc    rTMP2, rTMP2, rTMP
00db10
+	and	rWORD2, rWORD2, rTMP2		/* Mask off gunk.  */
00db10
+	and	rWORD1, rWORD1, rTMP2
00db10
+	rlwinm	rTMP2, rWORD2, 8, 0xffffffff	/* Byte reverse word.  */
00db10
+	rlwinm	rTMP, rWORD1, 8, 0xffffffff
00db10
+	rldimi	rTMP2, rWORD2, 24, 32
00db10
+	rldimi	rTMP, rWORD1, 24, 32
00db10
+	rlwimi	rTMP2, rWORD2, 24, 16, 23
00db10
+	rlwimi	rTMP, rWORD1, 24, 16, 23
00db10
+	xor.	rBITDIF, rTMP, rTMP2
00db10
+	sub	rRTN, rTMP, rTMP2
00db10
+	bgelr+
00db10
+	ori	rRTN, rTMP2, 1
00db10
+	blr
00db10
+
00db10
+L(different):
00db10
+	lwz	rWORD1, -4(rSTR1)
00db10
+	rlwinm	rTMP2, rWORD2, 8, 0xffffffff	/* Byte reverse word.  */
00db10
+	rlwinm	rTMP, rWORD1, 8, 0xffffffff
00db10
+	rldimi	rTMP2, rWORD2, 24, 32
00db10
+	rldimi	rTMP, rWORD1, 24, 32
00db10
+	rlwimi	rTMP2, rWORD2, 24, 16, 23
00db10
+	rlwimi	rTMP, rWORD1, 24, 16, 23
00db10
+	xor.	rBITDIF, rTMP, rTMP2
00db10
+	sub	rRTN, rTMP, rTMP2
00db10
+	bgelr+
00db10
+	ori	rRTN, rTMP2, 1
00db10
+	blr
00db10
+
00db10
+#else
00db10
 L(endstring):
00db10
 	and	rTMP, r7F7F, rWORD1
00db10
 	beq	cr1, L(equal)
00db10
 	add	rTMP, rTMP, r7F7F
00db10
 	xor.	rBITDIF, rWORD1, rWORD2
00db10
-
00db10
 	andc	rNEG, rNEG, rTMP
00db10
 	blt-	L(highbit)
00db10
 	cntlzw	rBITDIF, rBITDIF
00db10
@@ -93,28 +127,20 @@
00db10
 	addi	rNEG, rNEG, 7
00db10
 	cmpw	cr1, rNEG, rBITDIF
00db10
 	sub	rRTN, rWORD1, rWORD2
00db10
-	blt-	cr1, L(equal)
00db10
-	srawi	rRTN, rRTN, 31
00db10
-	ori	rRTN, rRTN, 1
00db10
-	blr
00db10
+	bgelr+	cr1
00db10
 L(equal):
00db10
 	li	rRTN, 0
00db10
 	blr
00db10
 
00db10
 L(different):
00db10
-	lwzu	rWORD1, -4(rSTR1)
00db10
+	lwz	rWORD1, -4(rSTR1)
00db10
 	xor.	rBITDIF, rWORD1, rWORD2
00db10
 	sub	rRTN, rWORD1, rWORD2
00db10
-	blt-	L(highbit)
00db10
-	srawi	rRTN, rRTN, 31
00db10
-	ori	rRTN, rRTN, 1
00db10
-	blr
00db10
+	bgelr+
00db10
 L(highbit):
00db10
-	srwi	rWORD2, rWORD2, 24
00db10
-	srwi	rWORD1, rWORD1, 24
00db10
-	sub	rRTN, rWORD1, rWORD2
00db10
+	ori	rRTN, rWORD2, 1
00db10
 	blr
00db10
-
00db10
+#endif
00db10
 
00db10
 /* Oh well.  In this case, we just do a byte-by-byte comparison.  */
00db10
 	.align 4
00db10
diff -urN glibc-2.17-c758a686/sysdeps/powerpc/powerpc32/power7/strncmp.S glibc-2.17-c758a686/sysdeps/powerpc/powerpc32/power7/strncmp.S
00db10
--- glibc-2.17-c758a686/sysdeps/powerpc/powerpc32/power7/strncmp.S	2014-05-28 13:26:59.000000000 -0500
00db10
+++ glibc-2.17-c758a686/sysdeps/powerpc/powerpc32/power7/strncmp.S	2014-05-28 13:27:02.000000000 -0500
00db10
@@ -28,7 +28,7 @@
00db10
 
00db10
 EALIGN (BP_SYM(strncmp),5,0)
00db10
 
00db10
-#define rTMP	r0
00db10
+#define rTMP2	r0
00db10
 #define rRTN	r3
00db10
 #define rSTR1	r3	/* first string arg */
00db10
 #define rSTR2	r4	/* second string arg */
00db10
@@ -44,6 +44,7 @@
00db10
 #define r7F7F	r9	/* constant 0x7f7f7f7f */
00db10
 #define rNEG	r10	/* ~(word in s1 | 0x7f7f7f7f) */
00db10
 #define rBITDIF	r11	/* bits that differ in s1 & s2 words */
00db10
+#define rTMP	r12
00db10
 
00db10
 	dcbt	0,rSTR1
00db10
 	nop
00db10
@@ -83,13 +84,45 @@
00db10
 /* OK. We've hit the end of the string. We need to be careful that
00db10
    we don't compare two strings as different because of gunk beyond
00db10
    the end of the strings...  */
00db10
+#ifdef __LITTLE_ENDIAN__
00db10
+L(endstring):
00db10
+	slwi	rTMP, rTMP, 1
00db10
+	addi    rTMP2, rTMP, -1
00db10
+	andc    rTMP2, rTMP2, rTMP
00db10
+	and	rWORD2, rWORD2, rTMP2		/* Mask off gunk.  */
00db10
+	and	rWORD1, rWORD1, rTMP2
00db10
+	rlwinm	rTMP2, rWORD2, 8, 0xffffffff	/* Byte reverse word.  */
00db10
+	rlwinm	rTMP, rWORD1, 8, 0xffffffff
00db10
+	rldimi	rTMP2, rWORD2, 24, 32
00db10
+	rldimi	rTMP, rWORD1, 24, 32
00db10
+	rlwimi	rTMP2, rWORD2, 24, 16, 23
00db10
+	rlwimi	rTMP, rWORD1, 24, 16, 23
00db10
+	xor.	rBITDIF, rTMP, rTMP2
00db10
+	sub	rRTN, rTMP, rTMP2
00db10
+	bgelr
00db10
+	ori	rRTN, rTMP2, 1
00db10
+	blr
00db10
+
00db10
+L(different):
00db10
+	lwz	rWORD1, -4(rSTR1)
00db10
+	rlwinm	rTMP2, rWORD2, 8, 0xffffffff	/* Byte reverse word.  */
00db10
+	rlwinm	rTMP, rWORD1, 8, 0xffffffff
00db10
+	rldimi	rTMP2, rWORD2, 24, 32
00db10
+	rldimi	rTMP, rWORD1, 24, 32
00db10
+	rlwimi	rTMP2, rWORD2, 24, 16, 23
00db10
+	rlwimi	rTMP, rWORD1, 24, 16, 23
00db10
+	xor.	rBITDIF, rTMP, rTMP2
00db10
+	sub	rRTN, rTMP, rTMP2
00db10
+	bgelr
00db10
+	ori	rRTN, rTMP2, 1
00db10
+	blr
00db10
 
00db10
+#else
00db10
 L(endstring):
00db10
 	and	rTMP,r7F7F,rWORD1
00db10
 	beq	cr1,L(equal)
00db10
 	add	rTMP,rTMP,r7F7F
00db10
 	xor.	rBITDIF,rWORD1,rWORD2
00db10
-
00db10
 	andc	rNEG,rNEG,rTMP
00db10
 	blt	L(highbit)
00db10
 	cntlzw	rBITDIF,rBITDIF
00db10
@@ -97,28 +130,20 @@
00db10
 	addi	rNEG,rNEG,7
00db10
 	cmpw	cr1,rNEG,rBITDIF
00db10
 	sub	rRTN,rWORD1,rWORD2
00db10
-	blt	cr1,L(equal)
00db10
-	srawi	rRTN,rRTN,31
00db10
-	ori	rRTN,rRTN,1
00db10
-	blr
00db10
+	bgelr	cr1
00db10
 L(equal):
00db10
 	li	rRTN,0
00db10
 	blr
00db10
 
00db10
 L(different):
00db10
-	lwzu	rWORD1,-4(rSTR1)
00db10
+	lwz	rWORD1,-4(rSTR1)
00db10
 	xor.	rBITDIF,rWORD1,rWORD2
00db10
 	sub	rRTN,rWORD1,rWORD2
00db10
-	blt	L(highbit)
00db10
-	srawi	rRTN,rRTN,31
00db10
-	ori	rRTN,rRTN,1
00db10
-	blr
00db10
+	bgelr
00db10
 L(highbit):
00db10
-	srwi	rWORD2,rWORD2,24
00db10
-	srwi	rWORD1,rWORD1,24
00db10
-	sub	rRTN,rWORD1,rWORD2
00db10
+	ori	rRTN, rWORD2, 1
00db10
 	blr
00db10
-
00db10
+#endif
00db10
 
00db10
 /* Oh well. In this case, we just do a byte-by-byte comparison.  */
00db10
 	.align	4
00db10
diff -urN glibc-2.17-c758a686/sysdeps/powerpc/powerpc32/strcmp.S glibc-2.17-c758a686/sysdeps/powerpc/powerpc32/strcmp.S
00db10
--- glibc-2.17-c758a686/sysdeps/powerpc/powerpc32/strcmp.S	2014-05-28 13:26:59.000000000 -0500
00db10
+++ glibc-2.17-c758a686/sysdeps/powerpc/powerpc32/strcmp.S	2014-05-28 13:27:02.000000000 -0500
00db10
@@ -26,7 +26,7 @@
00db10
 
00db10
 EALIGN (BP_SYM (strcmp), 4, 0)
00db10
 
00db10
-#define rTMP	r0
00db10
+#define rTMP2	r0
00db10
 #define rRTN	r3
00db10
 #define rSTR1	r3	/* first string arg */
00db10
 #define rSTR2	r4	/* second string arg */
00db10
@@ -40,6 +40,7 @@
00db10
 #define r7F7F	r8	/* constant 0x7f7f7f7f */
00db10
 #define rNEG	r9	/* ~(word in s1 | 0x7f7f7f7f) */
00db10
 #define rBITDIF	r10	/* bits that differ in s1 & s2 words */
00db10
+#define rTMP	r11
00db10
 
00db10
 	CHECK_BOUNDS_LOW (rSTR1, rTMP, rHIGH1)
00db10
 	CHECK_BOUNDS_LOW (rSTR2, rTMP, rHIGH2)
00db10
@@ -64,10 +65,45 @@
00db10
 	and.	rTMP, rTMP, rNEG
00db10
 	cmpw	cr1, rWORD1, rWORD2
00db10
 	beq+	L(g0)
00db10
-L(endstring):
00db10
+
00db10
 /* OK. We've hit the end of the string. We need to be careful that
00db10
    we don't compare two strings as different because of gunk beyond
00db10
    the end of the strings...  */
00db10
+#ifdef __LITTLE_ENDIAN__
00db10
+L(endstring):
00db10
+	addi    rTMP2, rTMP, -1
00db10
+	andc    rTMP2, rTMP2, rTMP
00db10
+	rlwimi	rTMP2, rTMP2, 1, 0, 30
00db10
+	and	rWORD2, rWORD2, rTMP2		/* Mask off gunk.  */
00db10
+	and	rWORD1, rWORD1, rTMP2
00db10
+	rlwinm	rTMP2, rWORD2, 8, 0xffffffff	/* Byte reverse word.  */
00db10
+	rlwinm	rTMP, rWORD1, 8, 0xffffffff
00db10
+	rlwimi	rTMP2, rWORD2, 24, 0, 7
00db10
+	rlwimi	rTMP, rWORD1, 24, 0, 7
00db10
+	rlwimi	rTMP2, rWORD2, 24, 16, 23
00db10
+	rlwimi	rTMP, rWORD1, 24, 16, 23
00db10
+	xor.	rBITDIF, rTMP, rTMP2
00db10
+	sub	rRTN, rTMP, rTMP2
00db10
+	bgelr+
00db10
+	ori	rRTN, rTMP2, 1
00db10
+	blr
00db10
+
00db10
+L(different):
00db10
+	lwz	rWORD1, -4(rSTR1)
00db10
+	rlwinm	rTMP2, rWORD2, 8, 0xffffffff	/* Byte reverse word.  */
00db10
+	rlwinm	rTMP, rWORD1, 8, 0xffffffff
00db10
+	rlwimi	rTMP2, rWORD2, 24, 0, 7
00db10
+	rlwimi	rTMP, rWORD1, 24, 0, 7
00db10
+	rlwimi	rTMP2, rWORD2, 24, 16, 23
00db10
+	rlwimi	rTMP, rWORD1, 24, 16, 23
00db10
+	xor.	rBITDIF, rTMP, rTMP2
00db10
+	sub	rRTN, rTMP, rTMP2
00db10
+	bgelr+
00db10
+	ori	rRTN, rTMP2, 1
00db10
+	blr
00db10
+
00db10
+#else
00db10
+L(endstring):
00db10
 	and	rTMP, r7F7F, rWORD1
00db10
 	beq	cr1, L(equal)
00db10
 	add	rTMP, rTMP, r7F7F
00db10
@@ -94,7 +130,7 @@
00db10
 	ori	rRTN, rWORD2, 1
00db10
 	/* GKM FIXME: check high bounds.  */
00db10
 	blr
00db10
-
00db10
+#endif
00db10
 
00db10
 /* Oh well.  In this case, we just do a byte-by-byte comparison.  */
00db10
 	.align 4
00db10
diff -urN glibc-2.17-c758a686/sysdeps/powerpc/powerpc32/strncmp.S glibc-2.17-c758a686/sysdeps/powerpc/powerpc32/strncmp.S
00db10
--- glibc-2.17-c758a686/sysdeps/powerpc/powerpc32/strncmp.S	2014-05-28 13:26:59.000000000 -0500
00db10
+++ glibc-2.17-c758a686/sysdeps/powerpc/powerpc32/strncmp.S	2014-05-28 13:27:02.000000000 -0500
00db10
@@ -26,7 +26,7 @@
00db10
 
00db10
 EALIGN (BP_SYM(strncmp), 4, 0)
00db10
 
00db10
-#define rTMP	r0
00db10
+#define rTMP2	r0
00db10
 #define rRTN	r3
00db10
 #define rSTR1	r3	/* first string arg */
00db10
 #define rSTR2	r4	/* second string arg */
00db10
@@ -40,6 +40,7 @@
00db10
 #define r7F7F	r9	/* constant 0x7f7f7f7f */
00db10
 #define rNEG	r10	/* ~(word in s1 | 0x7f7f7f7f) */
00db10
 #define rBITDIF	r11	/* bits that differ in s1 & s2 words */
00db10
+#define rTMP	r12
00db10
 
00db10
 	dcbt	0,rSTR1
00db10
 	or	rTMP, rSTR2, rSTR1
00db10
@@ -78,12 +79,45 @@
00db10
    we don't compare two strings as different because of gunk beyond
00db10
    the end of the strings...  */
00db10
 
00db10
+#ifdef __LITTLE_ENDIAN__
00db10
+L(endstring):
00db10
+	slwi	rTMP, rTMP, 1
00db10
+	addi    rTMP2, rTMP, -1
00db10
+	andc    rTMP2, rTMP2, rTMP
00db10
+	and	rWORD2, rWORD2, rTMP2		/* Mask off gunk.  */
00db10
+	and	rWORD1, rWORD1, rTMP2
00db10
+	rlwinm	rTMP2, rWORD2, 8, 0xffffffff	/* Byte reverse word.  */
00db10
+	rlwinm	rTMP, rWORD1, 8, 0xffffffff
00db10
+	rlwimi	rTMP2, rWORD2, 24, 0, 7
00db10
+	rlwimi	rTMP, rWORD1, 24, 0, 7
00db10
+	rlwimi	rTMP2, rWORD2, 24, 16, 23
00db10
+	rlwimi	rTMP, rWORD1, 24, 16, 23
00db10
+	xor.	rBITDIF, rTMP, rTMP2
00db10
+	sub	rRTN, rTMP, rTMP2
00db10
+	bgelr+
00db10
+	ori	rRTN, rTMP2, 1
00db10
+	blr
00db10
+
00db10
+L(different):
00db10
+	lwz	rWORD1, -4(rSTR1)
00db10
+	rlwinm	rTMP2, rWORD2, 8, 0xffffffff	/* Byte reverse word.  */
00db10
+	rlwinm	rTMP, rWORD1, 8, 0xffffffff
00db10
+	rlwimi	rTMP2, rWORD2, 24, 0, 7
00db10
+	rlwimi	rTMP, rWORD1, 24, 0, 7
00db10
+	rlwimi	rTMP2, rWORD2, 24, 16, 23
00db10
+	rlwimi	rTMP, rWORD1, 24, 16, 23
00db10
+	xor.	rBITDIF, rTMP, rTMP2
00db10
+	sub	rRTN, rTMP, rTMP2
00db10
+	bgelr+
00db10
+	ori	rRTN, rTMP2, 1
00db10
+	blr
00db10
+
00db10
+#else
00db10
 L(endstring):
00db10
 	and	rTMP, r7F7F, rWORD1
00db10
 	beq	cr1, L(equal)
00db10
 	add	rTMP, rTMP, r7F7F
00db10
 	xor.	rBITDIF, rWORD1, rWORD2
00db10
-
00db10
 	andc	rNEG, rNEG, rTMP
00db10
 	blt-	L(highbit)
00db10
 	cntlzw	rBITDIF, rBITDIF
00db10
@@ -91,28 +125,20 @@
00db10
 	addi	rNEG, rNEG, 7
00db10
 	cmpw	cr1, rNEG, rBITDIF
00db10
 	sub	rRTN, rWORD1, rWORD2
00db10
-	blt-	cr1, L(equal)
00db10
-	srawi	rRTN, rRTN, 31
00db10
-	ori	rRTN, rRTN, 1
00db10
-	blr
00db10
+	bgelr+	cr1
00db10
 L(equal):
00db10
 	li	rRTN, 0
00db10
 	blr
00db10
 
00db10
 L(different):
00db10
-	lwzu	rWORD1, -4(rSTR1)
00db10
+	lwz	rWORD1, -4(rSTR1)
00db10
 	xor.	rBITDIF, rWORD1, rWORD2
00db10
 	sub	rRTN, rWORD1, rWORD2
00db10
-	blt-	L(highbit)
00db10
-	srawi	rRTN, rRTN, 31
00db10
-	ori	rRTN, rRTN, 1
00db10
-	blr
00db10
+	bgelr+
00db10
 L(highbit):
00db10
-	srwi	rWORD2, rWORD2, 24
00db10
-	srwi	rWORD1, rWORD1, 24
00db10
-	sub	rRTN, rWORD1, rWORD2
00db10
+	ori	rRTN, rWORD2, 1
00db10
 	blr
00db10
-
00db10
+#endif
00db10
 
00db10
 /* Oh well.  In this case, we just do a byte-by-byte comparison.  */
00db10
 	.align 4
00db10
diff -urN glibc-2.17-c758a686/sysdeps/powerpc/powerpc64/power4/strncmp.S glibc-2.17-c758a686/sysdeps/powerpc/powerpc64/power4/strncmp.S
00db10
--- glibc-2.17-c758a686/sysdeps/powerpc/powerpc64/power4/strncmp.S	2014-05-28 13:26:59.000000000 -0500
00db10
+++ glibc-2.17-c758a686/sysdeps/powerpc/powerpc64/power4/strncmp.S	2014-05-28 13:27:02.000000000 -0500
00db10
@@ -27,7 +27,7 @@
00db10
 EALIGN (BP_SYM(strncmp), 4, 0)
00db10
 	CALL_MCOUNT 3
00db10
 
00db10
-#define rTMP	r0
00db10
+#define rTMP2	r0
00db10
 #define rRTN	r3
00db10
 #define rSTR1	r3	/* first string arg */
00db10
 #define rSTR2	r4	/* second string arg */
00db10
@@ -43,6 +43,7 @@
00db10
 #define r7F7F	r9	/* constant 0x7f7f7f7f7f7f7f7f */
00db10
 #define rNEG	r10	/* ~(word in s1 | 0x7f7f7f7f7f7f7f7f) */
00db10
 #define rBITDIF	r11	/* bits that differ in s1 & s2 words */
00db10
+#define rTMP	r12
00db10
 
00db10
 	dcbt	0,rSTR1
00db10
 	or	rTMP, rSTR2, rSTR1
00db10
@@ -84,12 +85,59 @@
00db10
    we don't compare two strings as different because of gunk beyond
00db10
    the end of the strings...  */
00db10
 
00db10
+#ifdef __LITTLE_ENDIAN__
00db10
+L(endstring):
00db10
+	addi    rTMP2, rTMP, -1
00db10
+	beq	cr1, L(equal)
00db10
+	andc    rTMP2, rTMP2, rTMP
00db10
+	rldimi	rTMP2, rTMP2, 1, 0
00db10
+	and	rWORD2, rWORD2, rTMP2	/* Mask off gunk.  */
00db10
+	and	rWORD1, rWORD1, rTMP2
00db10
+	cmpd	cr1, rWORD1, rWORD2
00db10
+	beq	cr1, L(equal)
00db10
+	xor	rBITDIF, rWORD1, rWORD2	/* rBITDIF has bits that differ.  */
00db10
+	neg	rNEG, rBITDIF
00db10
+	and	rNEG, rNEG, rBITDIF	/* rNEG has LS bit that differs.  */
00db10
+	cntlzd	rNEG, rNEG		/* bitcount of the bit.  */
00db10
+	andi.	rNEG, rNEG, 56		/* bitcount to LS byte that differs. */
00db10
+	sld	rWORD1, rWORD1, rNEG	/* shift left to clear MS bytes.  */
00db10
+	sld	rWORD2, rWORD2, rNEG
00db10
+	xor.	rBITDIF, rWORD1, rWORD2
00db10
+	sub	rRTN, rWORD1, rWORD2
00db10
+	blt-	L(highbit)
00db10
+	sradi	rRTN, rRTN, 63		/* must return an int.  */
00db10
+	ori	rRTN, rRTN, 1
00db10
+	blr
00db10
+L(equal):
00db10
+	li	rRTN, 0
00db10
+	blr
00db10
+
00db10
+L(different):
00db10
+	ld	rWORD1, -8(rSTR1)
00db10
+	xor	rBITDIF, rWORD1, rWORD2	/* rBITDIF has bits that differ.  */
00db10
+	neg	rNEG, rBITDIF
00db10
+	and	rNEG, rNEG, rBITDIF	/* rNEG has LS bit that differs.  */
00db10
+	cntlzd	rNEG, rNEG		/* bitcount of the bit.  */
00db10
+	andi.	rNEG, rNEG, 56		/* bitcount to LS byte that differs. */
00db10
+	sld	rWORD1, rWORD1, rNEG	/* shift left to clear MS bytes.  */
00db10
+	sld	rWORD2, rWORD2, rNEG
00db10
+	xor.	rBITDIF, rWORD1, rWORD2
00db10
+	sub	rRTN, rWORD1, rWORD2
00db10
+	blt-	L(highbit)
00db10
+	sradi	rRTN, rRTN, 63
00db10
+	ori	rRTN, rRTN, 1
00db10
+	blr
00db10
+L(highbit):
00db10
+	sradi	rRTN, rWORD2, 63
00db10
+	ori	rRTN, rRTN, 1
00db10
+	blr
00db10
+
00db10
+#else
00db10
 L(endstring):
00db10
 	and	rTMP, r7F7F, rWORD1
00db10
 	beq	cr1, L(equal)
00db10
 	add	rTMP, rTMP, r7F7F
00db10
 	xor.	rBITDIF, rWORD1, rWORD2
00db10
-
00db10
 	andc	rNEG, rNEG, rTMP
00db10
 	blt-	L(highbit)
00db10
 	cntlzd	rBITDIF, rBITDIF
00db10
@@ -98,7 +146,7 @@
00db10
 	cmpd	cr1, rNEG, rBITDIF
00db10
 	sub	rRTN, rWORD1, rWORD2
00db10
 	blt-	cr1, L(equal)
00db10
-	sradi	rRTN, rRTN, 63
00db10
+	sradi	rRTN, rRTN, 63		/* must return an int.  */
00db10
 	ori	rRTN, rRTN, 1
00db10
 	blr
00db10
 L(equal):
00db10
@@ -106,7 +154,7 @@
00db10
 	blr
00db10
 
00db10
 L(different):
00db10
-	ldu	rWORD1, -8(rSTR1)
00db10
+	ld	rWORD1, -8(rSTR1)
00db10
 	xor.	rBITDIF, rWORD1, rWORD2
00db10
 	sub	rRTN, rWORD1, rWORD2
00db10
 	blt-	L(highbit)
00db10
@@ -114,11 +162,10 @@
00db10
 	ori	rRTN, rRTN, 1
00db10
 	blr
00db10
 L(highbit):
00db10
-	srdi	rWORD2, rWORD2, 56
00db10
-	srdi	rWORD1, rWORD1, 56
00db10
-	sub	rRTN, rWORD1, rWORD2
00db10
+	sradi	rRTN, rWORD2, 63
00db10
+	ori	rRTN, rRTN, 1
00db10
 	blr
00db10
-
00db10
+#endif
00db10
 
00db10
 /* Oh well.  In this case, we just do a byte-by-byte comparison.  */
00db10
 	.align 4
00db10
diff -urN glibc-2.17-c758a686/sysdeps/powerpc/powerpc64/power7/strncmp.S glibc-2.17-c758a686/sysdeps/powerpc/powerpc64/power7/strncmp.S
00db10
--- glibc-2.17-c758a686/sysdeps/powerpc/powerpc64/power7/strncmp.S	2014-05-28 13:26:59.000000000 -0500
00db10
+++ glibc-2.17-c758a686/sysdeps/powerpc/powerpc64/power7/strncmp.S	2014-05-28 13:27:02.000000000 -0500
00db10
@@ -29,7 +29,7 @@
00db10
 EALIGN (BP_SYM(strncmp),5,0)
00db10
 	CALL_MCOUNT 3
00db10
 
00db10
-#define rTMP	r0
00db10
+#define rTMP2	r0
00db10
 #define rRTN	r3
00db10
 #define rSTR1	r3	/* first string arg */
00db10
 #define rSTR2	r4	/* second string arg */
00db10
@@ -45,6 +45,7 @@
00db10
 #define r7F7F	r9	/* constant 0x7f7f7f7f7f7f7f7f */
00db10
 #define rNEG	r10	/* ~(word in s1 | 0x7f7f7f7f7f7f7f7f) */
00db10
 #define rBITDIF	r11	/* bits that differ in s1 & s2 words */
00db10
+#define rTMP	r12
00db10
 
00db10
 	dcbt	0,rSTR1
00db10
 	nop
00db10
@@ -88,12 +89,57 @@
00db10
    we don't compare two strings as different because of gunk beyond
00db10
    the end of the strings...  */
00db10
 
00db10
+#ifdef __LITTLE_ENDIAN__
00db10
+L(endstring):
00db10
+	addi    rTMP2, rTMP, -1
00db10
+	beq	cr1, L(equal)
00db10
+	andc    rTMP2, rTMP2, rTMP
00db10
+	rldimi	rTMP2, rTMP2, 1, 0
00db10
+	and	rWORD2, rWORD2, rTMP2	/* Mask off gunk.  */
00db10
+	and	rWORD1, rWORD1, rTMP2
00db10
+	cmpd	cr1, rWORD1, rWORD2
00db10
+	beq	cr1, L(equal)
00db10
+	cmpb	rBITDIF, rWORD1, rWORD2	/* 0xff on equal bytes.  */
00db10
+	addi	rNEG, rBITDIF, 1
00db10
+	orc	rNEG, rNEG, rBITDIF	/* 0's below LS differing byte.  */
00db10
+	sldi	rNEG, rNEG, 8		/* 1's above LS differing byte.  */
00db10
+	andc	rWORD1, rWORD1, rNEG	/* mask off MS bytes.  */
00db10
+	andc	rWORD2, rWORD2, rNEG
00db10
+	xor.	rBITDIF, rWORD1, rWORD2
00db10
+	sub	rRTN, rWORD1, rWORD2
00db10
+	blt	L(highbit)
00db10
+	sradi	rRTN, rRTN, 63		/* must return an int.  */
00db10
+	ori	rRTN, rRTN, 1
00db10
+	blr
00db10
+L(equal):
00db10
+	li	rRTN, 0
00db10
+	blr
00db10
+
00db10
+L(different):
00db10
+	ld	rWORD1, -8(rSTR1)
00db10
+	cmpb	rBITDIF, rWORD1, rWORD2	/* 0xff on equal bytes.  */
00db10
+	addi	rNEG, rBITDIF, 1
00db10
+	orc	rNEG, rNEG, rBITDIF	/* 0's below LS differing byte.  */
00db10
+	sldi	rNEG, rNEG, 8		/* 1's above LS differing byte.  */
00db10
+	andc	rWORD1, rWORD1, rNEG	/* mask off MS bytes.  */
00db10
+	andc	rWORD2, rWORD2, rNEG
00db10
+	xor.	rBITDIF, rWORD1, rWORD2
00db10
+	sub	rRTN, rWORD1, rWORD2
00db10
+	blt	L(highbit)
00db10
+	sradi	rRTN, rRTN, 63
00db10
+	ori	rRTN, rRTN, 1
00db10
+	blr
00db10
+L(highbit):
00db10
+	sradi	rRTN, rWORD2, 63
00db10
+	ori	rRTN, rRTN, 1
00db10
+	blr
00db10
+
00db10
+#else
00db10
 L(endstring):
00db10
 	and	rTMP,r7F7F,rWORD1
00db10
 	beq	cr1,L(equal)
00db10
 	add	rTMP,rTMP,r7F7F
00db10
 	xor.	rBITDIF,rWORD1,rWORD2
00db10
-
00db10
 	andc	rNEG,rNEG,rTMP
00db10
 	blt	L(highbit)
00db10
 	cntlzd	rBITDIF,rBITDIF
00db10
@@ -102,7 +148,7 @@
00db10
 	cmpd	cr1,rNEG,rBITDIF
00db10
 	sub	rRTN,rWORD1,rWORD2
00db10
 	blt	cr1,L(equal)
00db10
-	sradi	rRTN,rRTN,63
00db10
+	sradi	rRTN,rRTN,63		/* must return an int.  */
00db10
 	ori	rRTN,rRTN,1
00db10
 	blr
00db10
 L(equal):
00db10
@@ -110,7 +156,7 @@
00db10
 	blr
00db10
 
00db10
 L(different):
00db10
-	ldu	rWORD1,-8(rSTR1)
00db10
+	ld	rWORD1,-8(rSTR1)
00db10
 	xor.	rBITDIF,rWORD1,rWORD2
00db10
 	sub	rRTN,rWORD1,rWORD2
00db10
 	blt	L(highbit)
00db10
@@ -118,11 +164,10 @@
00db10
 	ori	rRTN,rRTN,1
00db10
 	blr
00db10
 L(highbit):
00db10
-	srdi	rWORD2,rWORD2,56
00db10
-	srdi	rWORD1,rWORD1,56
00db10
-	sub	rRTN,rWORD1,rWORD2
00db10
+	sradi	rRTN,rWORD2,63
00db10
+	ori	rRTN,rRTN,1
00db10
 	blr
00db10
-
00db10
+#endif
00db10
 
00db10
 /* Oh well.  In this case, we just do a byte-by-byte comparison.  */
00db10
 	.align	4
00db10
diff -urN glibc-2.17-c758a686/sysdeps/powerpc/powerpc64/strcmp.S glibc-2.17-c758a686/sysdeps/powerpc/powerpc64/strcmp.S
00db10
--- glibc-2.17-c758a686/sysdeps/powerpc/powerpc64/strcmp.S	2014-05-28 13:26:59.000000000 -0500
00db10
+++ glibc-2.17-c758a686/sysdeps/powerpc/powerpc64/strcmp.S	2014-05-28 13:37:15.000000000 -0500
00db10
@@ -27,7 +27,7 @@
00db10
 EALIGN (BP_SYM(strcmp), 4, 0)
00db10
 	CALL_MCOUNT 2
00db10
 
00db10
-#define rTMP	r0
00db10
+#define rTMP2	r0
00db10
 #define rRTN	r3
00db10
 #define rSTR1	r3	/* first string arg */
00db10
 #define rSTR2	r4	/* second string arg */
00db10
@@ -46,6 +46,7 @@
00db10
 #define r7F7F	r8	/* constant 0x7f7f7f7f7f7f7f7f */
00db10
 #define rNEG	r9	/* ~(word in s1 | 0x7f7f7f7f7f7f7f7f) */
00db10
 #define rBITDIF	r10	/* bits that differ in s1 & s2 words */
00db10
+#define rTMP	r11
00db10
 
00db10
 	CHECK_BOUNDS_LOW (rSTR1, rTMP, rHIGH1)
00db10
 	CHECK_BOUNDS_LOW (rSTR2, rTMP, rHIGH2)
00db10
@@ -72,19 +73,66 @@
00db10
 	ldu	rWORD2, 8(rSTR2)
00db10
 L(g1):	add	rTMP, rFEFE, rWORD1
00db10
 	nor	rNEG, r7F7F, rWORD1
00db10
-
00db10
 	and.	rTMP, rTMP, rNEG
00db10
 	cmpd	cr1, rWORD1, rWORD2
00db10
 	beq+	L(g0)
00db10
-L(endstring):
00db10
+
00db10
 /* OK. We've hit the end of the string. We need to be careful that
00db10
    we don't compare two strings as different because of gunk beyond
00db10
    the end of the strings...  */
00db10
+#ifdef __LITTLE_ENDIAN__
00db10
+L(endstring):
00db10
+	addi    rTMP2, rTMP, -1
00db10
+	beq	cr1, L(equal)
00db10
+	andc    rTMP2, rTMP2, rTMP
00db10
+	rldimi	rTMP2, rTMP2, 1, 0
00db10
+	and	rWORD2, rWORD2, rTMP2	/* Mask off gunk.  */
00db10
+	and	rWORD1, rWORD1, rTMP2
00db10
+	cmpd	cr1, rWORD1, rWORD2
00db10
+	beq	cr1, L(equal)
00db10
+	xor	rBITDIF, rWORD1, rWORD2	/* rBITDIF has bits that differ.  */
00db10
+	neg	rNEG, rBITDIF
00db10
+	and	rNEG, rNEG, rBITDIF	/* rNEG has LS bit that differs.  */
00db10
+	cntlzd	rNEG, rNEG		/* bitcount of the bit.  */
00db10
+	andi.	rNEG, rNEG, 56		/* bitcount to LS byte that differs. */
00db10
+	sld	rWORD1, rWORD1, rNEG	/* shift left to clear MS bytes.  */
00db10
+	sld	rWORD2, rWORD2, rNEG
00db10
+	xor.	rBITDIF, rWORD1, rWORD2
00db10
+	sub	rRTN, rWORD1, rWORD2
00db10
+	blt-	L(highbit)
00db10
+	sradi	rRTN, rRTN, 63		/* must return an int.  */
00db10
+	ori	rRTN, rRTN, 1
00db10
+	blr
00db10
+L(equal):
00db10
+	li	rRTN, 0
00db10
+	blr
00db10
+
00db10
+L(different):
00db10
+	ld	rWORD1, -8(rSTR1)
00db10
+	xor	rBITDIF, rWORD1, rWORD2	/* rBITDIF has bits that differ.  */
00db10
+	neg	rNEG, rBITDIF
00db10
+	and	rNEG, rNEG, rBITDIF	/* rNEG has LS bit that differs.  */
00db10
+	cntlzd	rNEG, rNEG		/* bitcount of the bit.  */
00db10
+	andi.	rNEG, rNEG, 56		/* bitcount to LS byte that differs. */
00db10
+	sld	rWORD1, rWORD1, rNEG	/* shift left to clear MS bytes.  */
00db10
+	sld	rWORD2, rWORD2, rNEG
00db10
+	xor.	rBITDIF, rWORD1, rWORD2
00db10
+	sub	rRTN, rWORD1, rWORD2
00db10
+	blt-	L(highbit)
00db10
+	sradi	rRTN, rRTN, 63
00db10
+	ori	rRTN, rRTN, 1
00db10
+	blr
00db10
+L(highbit):
00db10
+	sradi	rRTN, rWORD2, 63
00db10
+	ori	rRTN, rRTN, 1
00db10
+	blr
00db10
+
00db10
+#else
00db10
+L(endstring):
00db10
 	and	rTMP, r7F7F, rWORD1
00db10
 	beq	cr1, L(equal)
00db10
 	add	rTMP, rTMP, r7F7F
00db10
 	xor.	rBITDIF, rWORD1, rWORD2
00db10
-
00db10
 	andc	rNEG, rNEG, rTMP
00db10
 	blt-	L(highbit)
00db10
 	cntlzd	rBITDIF, rBITDIF
00db10
@@ -93,7 +141,7 @@
00db10
 	cmpd	cr1, rNEG, rBITDIF
00db10
 	sub	rRTN, rWORD1, rWORD2
00db10
 	blt-	cr1, L(equal)
00db10
-	sradi	rRTN, rRTN, 63
00db10
+	sradi	rRTN, rRTN, 63		/* must return an int.  */
00db10
 	ori	rRTN, rRTN, 1
00db10
 	blr
00db10
 L(equal):
00db10
@@ -110,12 +158,11 @@
00db10
 	ori	rRTN, rRTN, 1
00db10
 	blr
00db10
 L(highbit):
00db10
-	srdi	rWORD2, rWORD2, 56
00db10
-	srdi	rWORD1, rWORD1, 56
00db10
-	sub	rRTN, rWORD1, rWORD2
00db10
+	sradi	rRTN, rWORD2, 63
00db10
+	ori	rRTN, rRTN, 1
00db10
 	/* GKM FIXME: check high bounds.  */
00db10
 	blr
00db10
-
00db10
+#endif
00db10
 
00db10
 /* Oh well.  In this case, we just do a byte-by-byte comparison.  */
00db10
 	.align 4
00db10
diff -urN glibc-2.17-c758a686/sysdeps/powerpc/powerpc64/strncmp.S glibc-2.17-c758a686/sysdeps/powerpc/powerpc64/strncmp.S
00db10
--- glibc-2.17-c758a686/sysdeps/powerpc/powerpc64/strncmp.S	2014-05-28 13:26:59.000000000 -0500
00db10
+++ glibc-2.17-c758a686/sysdeps/powerpc/powerpc64/strncmp.S	2014-05-28 13:38:31.000000000 -0500
00db10
@@ -27,7 +27,7 @@
00db10
 EALIGN (BP_SYM(strncmp), 4, 0)
00db10
 	CALL_MCOUNT 3
00db10
 
00db10
-#define rTMP	r0
00db10
+#define rTMP2	r0
00db10
 #define rRTN	r3
00db10
 #define rSTR1	r3	/* first string arg */
00db10
 #define rSTR2	r4	/* second string arg */
00db10
@@ -41,6 +41,7 @@
00db10
 #define r7F7F	r9	/* constant 0x7f7f7f7f7f7f7f7f */
00db10
 #define rNEG	r10	/* ~(word in s1 | 0x7f7f7f7f7f7f7f7f) */
00db10
 #define rBITDIF	r11	/* bits that differ in s1 & s2 words */
00db10
+#define rTMP	r12
00db10
 
00db10
 	dcbt	0,rSTR1
00db10
 	or	rTMP, rSTR2, rSTR1
00db10
@@ -81,13 +82,60 @@
00db10
 /* OK. We've hit the end of the string. We need to be careful that
00db10
    we don't compare two strings as different because of gunk beyond
00db10
    the end of the strings...  */
00db10
-	
00db10
+
00db10
+#ifdef __LITTLE_ENDIAN__
00db10
+L(endstring):
00db10
+	addi    rTMP2, rTMP, -1
00db10
+	beq	cr1, L(equal)
00db10
+	andc    rTMP2, rTMP2, rTMP
00db10
+	rldimi	rTMP2, rTMP2, 1, 0
00db10
+	and	rWORD2, rWORD2, rTMP2	/* Mask off gunk.  */
00db10
+	and	rWORD1, rWORD1, rTMP2
00db10
+	cmpd	cr1, rWORD1, rWORD2
00db10
+	beq	cr1, L(equal)
00db10
+	xor	rBITDIF, rWORD1, rWORD2	/* rBITDIF has bits that differ.  */
00db10
+	neg	rNEG, rBITDIF
00db10
+	and	rNEG, rNEG, rBITDIF	/* rNEG has LS bit that differs.  */
00db10
+	cntlzd	rNEG, rNEG		/* bitcount of the bit.  */
00db10
+	andi.	rNEG, rNEG, 56		/* bitcount to LS byte that differs. */
00db10
+	sld	rWORD1, rWORD1, rNEG	/* shift left to clear MS bytes.  */
00db10
+	sld	rWORD2, rWORD2, rNEG
00db10
+	xor.	rBITDIF, rWORD1, rWORD2
00db10
+	sub	rRTN, rWORD1, rWORD2
00db10
+	blt-	L(highbit)
00db10
+	sradi	rRTN, rRTN, 63		/* must return an int.  */
00db10
+	ori	rRTN, rRTN, 1
00db10
+	blr
00db10
+L(equal):
00db10
+	li	rRTN, 0
00db10
+	blr
00db10
+
00db10
+L(different):
00db10
+	ld	rWORD1, -8(rSTR1)
00db10
+	xor	rBITDIF, rWORD1, rWORD2	/* rBITDIF has bits that differ.  */
00db10
+	neg	rNEG, rBITDIF
00db10
+	and	rNEG, rNEG, rBITDIF	/* rNEG has LS bit that differs.  */
00db10
+	cntlzd	rNEG, rNEG		/* bitcount of the bit.  */
00db10
+	andi.	rNEG, rNEG, 56		/* bitcount to LS byte that differs. */
00db10
+	sld	rWORD1, rWORD1, rNEG	/* shift left to clear MS bytes.  */
00db10
+	sld	rWORD2, rWORD2, rNEG
00db10
+	xor.	rBITDIF, rWORD1, rWORD2
00db10
+	sub	rRTN, rWORD1, rWORD2
00db10
+	blt-	L(highbit)
00db10
+	sradi	rRTN, rRTN, 63
00db10
+	ori	rRTN, rRTN, 1
00db10
+	blr
00db10
+L(highbit):
00db10
+	sradi	rRTN, rWORD2, 63
00db10
+	ori	rRTN, rRTN, 1
00db10
+	blr
00db10
+
00db10
+#else
00db10
 L(endstring):
00db10
 	and	rTMP, r7F7F, rWORD1
00db10
 	beq	cr1, L(equal)
00db10
 	add	rTMP, rTMP, r7F7F
00db10
 	xor.	rBITDIF, rWORD1, rWORD2
00db10
-
00db10
 	andc	rNEG, rNEG, rTMP
00db10
 	blt-	L(highbit)
00db10
 	cntlzd	rBITDIF, rBITDIF
00db10
@@ -96,7 +144,7 @@
00db10
 	cmpd	cr1, rNEG, rBITDIF
00db10
 	sub	rRTN, rWORD1, rWORD2
00db10
 	blt-	cr1, L(equal)
00db10
-	sradi	rRTN, rRTN, 63
00db10
+	sradi	rRTN, rRTN, 63		/* must return an int.  */
00db10
 	ori	rRTN, rRTN, 1
00db10
 	blr
00db10
 L(equal):
00db10
@@ -104,7 +152,7 @@
00db10
 	blr
00db10
 
00db10
 L(different):
00db10
-	ldu	rWORD1, -8(rSTR1)
00db10
+	ld	rWORD1, -8(rSTR1)
00db10
 	xor.	rBITDIF, rWORD1, rWORD2
00db10
 	sub	rRTN, rWORD1, rWORD2
00db10
 	blt-	L(highbit)
00db10
@@ -112,11 +160,10 @@
00db10
 	ori	rRTN, rRTN, 1
00db10
 	blr
00db10
 L(highbit):
00db10
-	srdi	rWORD2, rWORD2, 56
00db10
-	srdi	rWORD1, rWORD1, 56
00db10
-	sub	rRTN, rWORD1, rWORD2
00db10
+	sradi	rRTN, rWORD2, 63
00db10
+	ori	rRTN, rRTN, 1
00db10
 	blr
00db10
-
00db10
+#endif
00db10
 
00db10
 /* Oh well.  In this case, we just do a byte-by-byte comparison.  */
00db10
 	.align 4