8ae002
From 2fd1041a8d9684978546886d58fdf8add8c8d9f7 Mon Sep 17 00:00:00 2001
8ae002
From: Rajalakshmi Srinivasaraghavan <raji@linux.vnet.ibm.com>
8ae002
Date: Tue, 5 Jul 2016 21:20:41 +0530
8ae002
Subject: [PATCH] powerpc: Fix return code of strcasecmp for unaligned inputs
8ae002
8ae002
If the input values are unaligned and if there are null characters in the
8ae002
memory before the starting address of the input values, strcasecmp
8ae002
gives incorrect return code. Fixed it by adding mask the bits that
8ae002
are not part of the string.
8ae002
8ae002
(cherry picked from commit 30e4cc5413f72c2c728a544389da0c48500d9904)
8ae002
---
8ae002
 ChangeLog                                     |  6 ++++++
8ae002
 sysdeps/powerpc/powerpc64/power8/strcasecmp.S | 17 ++++++++++++++---
8ae002
 2 files changed, 20 insertions(+), 3 deletions(-)
8ae002
8ae002
diff --git a/ChangeLog b/ChangeLog
8ae002
index 9385bd0..af5f694 100644
8ae002
diff --git a/sysdeps/powerpc/powerpc64/power8/strcasecmp.S b/sysdeps/powerpc/powerpc64/power8/strcasecmp.S
8ae002
index 63f6217..c83dc52 100644
8ae002
--- a/sysdeps/powerpc/powerpc64/power8/strcasecmp.S
8ae002
+++ b/sysdeps/powerpc/powerpc64/power8/strcasecmp.S
8ae002
@@ -40,11 +40,20 @@
8ae002
 	vsel	v5, v7, v5, v8; \
8ae002
 	vcmpequb.	v7, v5, v4;
8ae002
 
8ae002
-/* Get 16 bytes for unaligned case.  */
8ae002
+/*
8ae002
+ * Get 16 bytes for unaligned case.
8ae002
+ * reg1: Vector to hold next 16 bytes.
8ae002
+ * reg2: Address to read from.
8ae002
+ * reg3: Permute control vector.
8ae002
+ * v8: Tmp vector used to mask unwanted bytes.
8ae002
+ * v9: Tmp vector,0 when null is found on first 16 bytes
8ae002
+ */
8ae002
 #ifdef __LITTLE_ENDIAN__
8ae002
 #define GET16BYTES(reg1, reg2, reg3) \
8ae002
 	lvx	reg1, 0, reg2; \
8ae002
-	vcmpequb.	v8, v0, reg1; \
8ae002
+	vspltisb	v8, -1; \
8ae002
+	vperm	v8, v8, reg1, reg3; \
8ae002
+	vcmpequb.	v8, v0, v8; \
8ae002
 	beq	cr6, 1f; \
8ae002
 	vspltisb	v9, 0; \
8ae002
 	b	2f; \
8ae002
@@ -57,7 +66,9 @@
8ae002
 #else
8ae002
 #define GET16BYTES(reg1, reg2, reg3) \
8ae002
 	lvx	reg1, 0, reg2; \
8ae002
-	vcmpequb.	v8, v0, reg1; \
8ae002
+	vspltisb	 v8, -1; \
8ae002
+	vperm	v8, reg1, v8,  reg3; \
8ae002
+	vcmpequb.	v8, v0, v8; \
8ae002
 	beq	cr6, 1f; \
8ae002
 	vspltisb	v9, 0; \
8ae002
 	b	2f; \
8ae002
-- 
8ae002
2.1.0
8ae002