446cf2
commit 7793ad7a2c00434398aa8bb3f5932e2fdf43536a
446cf2
Author: Rajalakshmi Srinivasaraghavan <raji@linux.vnet.ibm.com>
446cf2
Date:   Thu Aug 16 12:12:02 2018 +0530
446cf2
446cf2
    powerpc: Rearrange little endian specific files
446cf2
    
446cf2
    This patch moves little endian specific POWER9 optimization files to
446cf2
    sysdeps/powerpc/powerpc64/le and creates POWER9 ifunc functions
446cf2
    only for little endian.
446cf2
446cf2
diff --git a/sysdeps/powerpc/powerpc64/power9/strcmp.S b/sysdeps/powerpc/powerpc64/le/power9/strcmp.S
446cf2
similarity index 93%
446cf2
rename from sysdeps/powerpc/powerpc64/power9/strcmp.S
446cf2
rename to sysdeps/powerpc/powerpc64/le/power9/strcmp.S
446cf2
index 98243a9d51e1577f..bf057f598ef2aa55 100644
446cf2
--- a/sysdeps/powerpc/powerpc64/power9/strcmp.S
446cf2
+++ b/sysdeps/powerpc/powerpc64/le/power9/strcmp.S
446cf2
@@ -15,7 +15,6 @@
446cf2
    You should have received a copy of the GNU Lesser General Public
446cf2
    License along with the GNU C Library; if not, see
446cf2
    <http://www.gnu.org/licenses/>.  */
446cf2
-#ifdef __LITTLE_ENDIAN__
446cf2
 #include <sysdep.h>
446cf2
 
446cf2
 #ifndef STRCMP
446cf2
@@ -30,16 +29,16 @@
446cf2
    as in POWER8 patch and uses vectorised loops after that.  */
446cf2
 
446cf2
 /* TODO: Change this to actual instructions when minimum binutils is upgraded
446cf2
-   to 2.27. Macros are defined below for these newer instructions in order
446cf2
+   to 2.27.  Macros are defined below for these newer instructions in order
446cf2
    to maintain compatibility.  */
446cf2
-# define VCTZLSBB(r,v) .long (0x10010602 | ((r)<<(32-11)) | ((v)<<(32-21)))
446cf2
+#define VCTZLSBB(r,v) .long (0x10010602 | ((r)<<(32-11)) | ((v)<<(32-21)))
446cf2
 
446cf2
-# define VEXTUBRX(t,a,b) .long (0x1000070d \
446cf2
+#define VEXTUBRX(t,a,b) .long (0x1000070d \
446cf2
 				| ((t)<<(32-11))  \
446cf2
 				| ((a)<<(32-16))  \
446cf2
 				| ((b)<<(32-21)) )
446cf2
 
446cf2
-# define VCMPNEZB(t,a,b) .long (0x10000507 \
446cf2
+#define VCMPNEZB(t,a,b) .long (0x10000507 \
446cf2
 				| ((t)<<(32-11))  \
446cf2
 				| ((a)<<(32-16))  \
446cf2
 				| ((b)<<(32-21)) )
446cf2
@@ -48,7 +47,7 @@
446cf2
    reg1: Vector to hold next 16 bytes.
446cf2
    reg2: Address to read from.
446cf2
    reg3: Permute control vector.  */
446cf2
-# define GET16BYTES(reg1, reg2, reg3) \
446cf2
+#define GET16BYTES(reg1, reg2, reg3) \
446cf2
 	lvx	reg1, 0, reg2; \
446cf2
 	vperm	v8, v2, reg1, reg3; \
446cf2
 	vcmpequb.	v8, v0, v8; \
446cf2
@@ -263,6 +262,3 @@ L(pagecross_nullfound):
446cf2
 	b	L(pagecross_retdiff)
446cf2
 END (STRCMP)
446cf2
 libc_hidden_builtin_def (strcmp)
446cf2
-#else
446cf2
-#include <sysdeps/powerpc/powerpc64/power8/strcmp.S>
446cf2
-#endif
446cf2
diff --git a/sysdeps/powerpc/powerpc64/power9/strncmp.S b/sysdeps/powerpc/powerpc64/le/power9/strncmp.S
446cf2
similarity index 95%
446cf2
rename from sysdeps/powerpc/powerpc64/power9/strncmp.S
446cf2
rename to sysdeps/powerpc/powerpc64/le/power9/strncmp.S
446cf2
index 40be98ff45c9f485..93a79343c6be1099 100644
446cf2
--- a/sysdeps/powerpc/powerpc64/power9/strncmp.S
446cf2
+++ b/sysdeps/powerpc/powerpc64/le/power9/strncmp.S
446cf2
@@ -15,7 +15,6 @@
446cf2
    You should have received a copy of the GNU Lesser General Public
446cf2
    License along with the GNU C Library; if not, see
446cf2
    <http://www.gnu.org/licenses/>.  */
446cf2
-#ifdef __LITTLE_ENDIAN__
446cf2
 #include <sysdep.h>
446cf2
 
446cf2
 /* Implements the function
446cf2
@@ -31,16 +30,16 @@
446cf2
 #endif
446cf2
 
446cf2
 /* TODO: Change this to actual instructions when minimum binutils is upgraded
446cf2
-   to 2.27. Macros are defined below for these newer instructions in order
446cf2
+   to 2.27.  Macros are defined below for these newer instructions in order
446cf2
    to maintain compatibility.  */
446cf2
-# define VCTZLSBB(r,v) .long (0x10010602 | ((r)<<(32-11)) | ((v)<<(32-21)))
446cf2
+#define VCTZLSBB(r,v) .long (0x10010602 | ((r)<<(32-11)) | ((v)<<(32-21)))
446cf2
 
446cf2
-# define VEXTUBRX(t,a,b) .long (0x1000070d \
446cf2
+#define VEXTUBRX(t,a,b) .long (0x1000070d \
446cf2
 				| ((t)<<(32-11))  \
446cf2
 				| ((a)<<(32-16))  \
446cf2
 				| ((b)<<(32-21)) )
446cf2
 
446cf2
-# define VCMPNEZB(t,a,b) .long (0x10000507 \
446cf2
+#define VCMPNEZB(t,a,b) .long (0x10000507 \
446cf2
 				| ((t)<<(32-11))  \
446cf2
 				| ((a)<<(32-16))  \
446cf2
 				| ((b)<<(32-21)) )
446cf2
@@ -49,7 +48,7 @@
446cf2
    reg1: Vector to hold next 16 bytes.
446cf2
    reg2: Address to read from.
446cf2
    reg3: Permute control vector.  */
446cf2
-# define GET16BYTES(reg1, reg2, reg3) \
446cf2
+#define GET16BYTES(reg1, reg2, reg3) \
446cf2
 	lvx	reg1, 0, reg2; \
446cf2
 	vperm	v8, v2, reg1, reg3; \
446cf2
 	vcmpequb.	v8, v0, v8; \
446cf2
@@ -374,6 +373,3 @@ L(byte_ne_3):
446cf2
 	b	L(byte_ne_1)
446cf2
 END(STRNCMP)
446cf2
 libc_hidden_builtin_def(strncmp)
446cf2
-#else
446cf2
-#include <sysdeps/powerpc/powerpc64/power8/strncmp.S>
446cf2
-#endif
446cf2
diff --git a/sysdeps/powerpc/powerpc64/multiarch/Makefile b/sysdeps/powerpc/powerpc64/multiarch/Makefile
446cf2
index 4df6b45c4c1c495a..963ea84dbfa98c74 100644
446cf2
--- a/sysdeps/powerpc/powerpc64/multiarch/Makefile
446cf2
+++ b/sysdeps/powerpc/powerpc64/multiarch/Makefile
446cf2
@@ -12,7 +12,7 @@ sysdep_routines += memcpy-power8-cached memcpy-power7 memcpy-a2 memcpy-power6 \
446cf2
 		   strnlen-power8 strnlen-power7 strnlen-ppc64 \
446cf2
 		   strcasecmp-power7 strcasecmp_l-power7 \
446cf2
 		   strncase-power7 strncase_l-power7 \
446cf2
-		   strncmp-power9 strncmp-power8 strncmp-power7 \
446cf2
+		   strncmp-power8 strncmp-power7 \
446cf2
 		   strncmp-power4 strncmp-ppc64 \
446cf2
 		   strchr-power8 strchr-power7 strchr-ppc64 \
446cf2
 		   strchrnul-power8 strchrnul-power7 strchrnul-ppc64 \
446cf2
@@ -22,7 +22,7 @@ sysdep_routines += memcpy-power8-cached memcpy-power7 memcpy-a2 memcpy-power6 \
446cf2
 		   strncat-power8 strncat-power7 strncat-ppc64 \
446cf2
 		   strncpy-power7 strncpy-ppc64 \
446cf2
 		   stpncpy-power8 stpncpy-power7 stpncpy-ppc64 \
446cf2
-		   strcmp-power9 strcmp-power8 strcmp-power7 strcmp-ppc64 \
446cf2
+		   strcmp-power8 strcmp-power7 strcmp-ppc64 \
446cf2
 		   strcat-power8 strcat-power7 strcat-ppc64 \
446cf2
 		   memmove-power7 memmove-ppc64 wordcopy-ppc64 bcopy-ppc64 \
446cf2
 		   strncpy-power8 strstr-power7 strstr-ppc64 \
446cf2
@@ -31,6 +31,9 @@ sysdep_routines += memcpy-power8-cached memcpy-power7 memcpy-a2 memcpy-power6 \
446cf2
 		   strcasecmp-ppc64 strcasecmp-power8 strncase-ppc64 \
446cf2
 		   strncase-power8
446cf2
 
446cf2
+ifneq (,$(filter %le,$(config-machine)))
446cf2
+sysdep_routines += strcmp-power9 strncmp-power9
446cf2
+endif
446cf2
 CFLAGS-strncase-power7.c += -mcpu=power7 -funroll-loops
446cf2
 CFLAGS-strncase_l-power7.c += -mcpu=power7 -funroll-loops
446cf2
 endif
446cf2
diff --git a/sysdeps/powerpc/powerpc64/multiarch/ifunc-impl-list.c b/sysdeps/powerpc/powerpc64/multiarch/ifunc-impl-list.c
446cf2
index 38a21e478e2527f5..1d374f2ae48165bd 100644
446cf2
--- a/sysdeps/powerpc/powerpc64/multiarch/ifunc-impl-list.c
446cf2
+++ b/sysdeps/powerpc/powerpc64/multiarch/ifunc-impl-list.c
446cf2
@@ -112,8 +112,10 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array,
446cf2
 
446cf2
   /* Support sysdeps/powerpc/powerpc64/multiarch/strncmp.c.  */
446cf2
   IFUNC_IMPL (i, name, strncmp,
446cf2
+#ifdef __LITTLE_ENDIAN__
446cf2
 	      IFUNC_IMPL_ADD (array, i, strncmp, hwcap2 & PPC_FEATURE2_ARCH_3_00,
446cf2
 			      __strncmp_power9)
446cf2
+#endif
446cf2
 	      IFUNC_IMPL_ADD (array, i, strncmp, hwcap2 & PPC_FEATURE2_ARCH_2_07,
446cf2
 			      __strncmp_power8)
446cf2
 	      IFUNC_IMPL_ADD (array, i, strncmp, hwcap & PPC_FEATURE_HAS_VSX,
446cf2
@@ -337,9 +339,11 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array,
446cf2
 
446cf2
   /* Support sysdeps/powerpc/powerpc64/multiarch/strcmp.c.  */
446cf2
   IFUNC_IMPL (i, name, strcmp,
446cf2
+#ifdef __LITTLE_ENDIAN__
446cf2
 	      IFUNC_IMPL_ADD (array, i, strcmp,
446cf2
 			      hwcap2 & PPC_FEATURE2_ARCH_3_00,
446cf2
 			      __strcmp_power9)
446cf2
+#endif
446cf2
 	      IFUNC_IMPL_ADD (array, i, strcmp,
446cf2
 			      hwcap2 & PPC_FEATURE2_ARCH_2_07,
446cf2
 			      __strcmp_power8)
446cf2
diff --git a/sysdeps/powerpc/powerpc64/multiarch/strcmp-power9.S b/sysdeps/powerpc/powerpc64/multiarch/strcmp-power9.S
446cf2
index 8b569d38be783316..545e6cee91e61311 100644
446cf2
--- a/sysdeps/powerpc/powerpc64/multiarch/strcmp-power9.S
446cf2
+++ b/sysdeps/powerpc/powerpc64/multiarch/strcmp-power9.S
446cf2
@@ -16,11 +16,11 @@
446cf2
    License along with the GNU C Library; if not, see
446cf2
    <http://www.gnu.org/licenses/>.  */
446cf2
 
446cf2
-#if IS_IN (libc)
446cf2
+#if defined __LITTLE_ENDIAN__ && IS_IN (libc)
446cf2
 #define STRCMP __strcmp_power9
446cf2
 
446cf2
 #undef libc_hidden_builtin_def
446cf2
 #define libc_hidden_builtin_def(name)
446cf2
 
446cf2
-#include <sysdeps/powerpc/powerpc64/power9/strcmp.S>
446cf2
+#include <sysdeps/powerpc/powerpc64/le/power9/strcmp.S>
446cf2
 #endif
446cf2
diff --git a/sysdeps/powerpc/powerpc64/multiarch/strcmp.c b/sysdeps/powerpc/powerpc64/multiarch/strcmp.c
446cf2
index b669053166771cae..2422c8d72cfdec83 100644
446cf2
--- a/sysdeps/powerpc/powerpc64/multiarch/strcmp.c
446cf2
+++ b/sysdeps/powerpc/powerpc64/multiarch/strcmp.c
446cf2
@@ -27,13 +27,17 @@
446cf2
 extern __typeof (strcmp) __strcmp_ppc attribute_hidden;
446cf2
 extern __typeof (strcmp) __strcmp_power7 attribute_hidden;
446cf2
 extern __typeof (strcmp) __strcmp_power8 attribute_hidden;
446cf2
+# ifdef __LITTLE_ENDIAN__
446cf2
 extern __typeof (strcmp) __strcmp_power9 attribute_hidden;
446cf2
+# endif
446cf2
 
446cf2
 # undef strcmp
446cf2
 
446cf2
 libc_ifunc_redirected (__redirect_strcmp, strcmp,
446cf2
+# ifdef __LITTLE_ENDIAN__
446cf2
 			(hwcap2 & PPC_FEATURE2_ARCH_3_00)
446cf2
 			? __strcmp_power9 :
446cf2
+# endif
446cf2
 		       (hwcap2 & PPC_FEATURE2_ARCH_2_07)
446cf2
 		       ? __strcmp_power8
446cf2
 		       : (hwcap & PPC_FEATURE_HAS_VSX)
446cf2
diff --git a/sysdeps/powerpc/powerpc64/multiarch/strncmp-power9.S b/sysdeps/powerpc/powerpc64/multiarch/strncmp-power9.S
446cf2
index 3356f7252771a043..c6f0128379c497b4 100644
446cf2
--- a/sysdeps/powerpc/powerpc64/multiarch/strncmp-power9.S
446cf2
+++ b/sysdeps/powerpc/powerpc64/multiarch/strncmp-power9.S
446cf2
@@ -15,11 +15,11 @@
446cf2
    License along with the GNU C Library; if not, see
446cf2
    <http://www.gnu.org/licenses/>.  */
446cf2
 
446cf2
-#if IS_IN (libc)
446cf2
+#if defined __LITTLE_ENDIAN__ && IS_IN (libc)
446cf2
 #define STRNCMP __strncmp_power9
446cf2
 
446cf2
 #undef libc_hidden_builtin_def
446cf2
 #define libc_hidden_builtin_def(name)
446cf2
 
446cf2
-#include <sysdeps/powerpc/powerpc64/power9/strncmp.S>
446cf2
+#include <sysdeps/powerpc/powerpc64/le/power9/strncmp.S>
446cf2
 #endif
446cf2
diff --git a/sysdeps/powerpc/powerpc64/multiarch/strncmp.c b/sysdeps/powerpc/powerpc64/multiarch/strncmp.c
446cf2
index c4a40d1ec7245a3b..9c887ee18186f070 100644
446cf2
--- a/sysdeps/powerpc/powerpc64/multiarch/strncmp.c
446cf2
+++ b/sysdeps/powerpc/powerpc64/multiarch/strncmp.c
446cf2
@@ -29,14 +29,18 @@ extern __typeof (strncmp) __strncmp_ppc attribute_hidden;
446cf2
 extern __typeof (strncmp) __strncmp_power4 attribute_hidden;
446cf2
 extern __typeof (strncmp) __strncmp_power7 attribute_hidden;
446cf2
 extern __typeof (strncmp) __strncmp_power8 attribute_hidden;
446cf2
+# ifdef __LITTLE_ENDIAN__
446cf2
 extern __typeof (strncmp) __strncmp_power9 attribute_hidden;
446cf2
+# endif
446cf2
 # undef strncmp
446cf2
 
446cf2
 /* Avoid DWARF definition DIE on ifunc symbol so that GDB can handle
446cf2
    ifunc symbol properly.  */
446cf2
 libc_ifunc_redirected (__redirect_strncmp, strncmp,
446cf2
+# ifdef __LITTLE_ENDIAN_
446cf2
 			(hwcap2 & PPC_FEATURE2_ARCH_3_00)
446cf2
 			? __strncmp_power9 :
446cf2
+# endif
446cf2
 		       (hwcap2 & PPC_FEATURE2_ARCH_2_07)
446cf2
 		       ? __strncmp_power8
446cf2
 		       : (hwcap & PPC_FEATURE_HAS_VSX)