00db10
From f4f918430b6b74f1801ebe39a8824cc5437ba9d4 Mon Sep 17 00:00:00 2001
00db10
From: "Paul E. Murphy" <murphyp@linux.vnet.ibm.com>
00db10
Date: Mon, 25 Apr 2016 09:11:02 -0500
00db10
Subject: [PATCH] powerpc: Add optimized strcspn for P8
00db10
00db10
A few minor adjustments to the P8 strspn gives us
00db10
an almost equally optimized P8 strcspn.
00db10
00db10
(cherry picked from commit 8f1b841e452dbb083112fd036033b7f4af506ba0)
00db10
---
00db10
 ChangeLog                                          | 25 ++++++++++++
00db10
 sysdeps/powerpc/powerpc64/multiarch/Makefile       |  4 +-
00db10
 .../powerpc/powerpc64/multiarch/ifunc-impl-list.c  |  8 ++++
00db10
 .../powerpc/powerpc64/multiarch/strcspn-power8.S   | 25 ++++++++++++
00db10
 .../powerpc/powerpc64/multiarch/strcspn-ppc64.c    | 26 +++++++++++++
00db10
 sysdeps/powerpc/powerpc64/multiarch/strcspn.c      | 35 +++++++++++++++++
00db10
 .../powerpc/powerpc64/multiarch/strspn-power8.S    | 17 +-------
00db10
 sysdeps/powerpc/powerpc64/power8/strcspn.S         | 20 ++++++++++
00db10
 sysdeps/powerpc/powerpc64/power8/strspn.S          | 45 ++++++++++++++++------
00db10
 9 files changed, 176 insertions(+), 29 deletions(-)
00db10
 create mode 100644 sysdeps/powerpc/powerpc64/multiarch/strcspn-power8.S
00db10
 create mode 100644 sysdeps/powerpc/powerpc64/multiarch/strcspn-ppc64.c
00db10
 create mode 100644 sysdeps/powerpc/powerpc64/multiarch/strcspn.c
00db10
 create mode 100644 sysdeps/powerpc/powerpc64/power8/strcspn.S
00db10
00db10
diff --git a/ChangeLog b/ChangeLog
00db10
index 6677ea2..5537fc6 100644
00db10
diff --git a/sysdeps/powerpc/powerpc64/multiarch/Makefile b/sysdeps/powerpc/powerpc64/multiarch/Makefile
00db10
index 7f70ceb..9ee9bc2 100644
00db10
--- a/sysdeps/powerpc/powerpc64/multiarch/Makefile
00db10
+++ b/sysdeps/powerpc/powerpc64/multiarch/Makefile
00db10
@@ -20,6 +20,7 @@ sysdep_routines += memcpy-power7 memcpy-a2 memcpy-power6 memcpy-cell \
00db10
                   strcat-power8 strcat-power7 strcat-ppc64 \
00db10
                   strcmp-power8 strcmp-power7 strcmp-ppc64 \
00db10
                   strcpy-power8 strcpy-power7 strcpy-ppc64 \
00db10
+                  strcspn-power8 strcspn-ppc64 \
00db10
                   stpncpy-power8 stpncpy-power7 stpncpy-ppc64 \
00db10
                   strncpy-power8 strncpy-power7 strncpy-ppc64 \
00db10
                   strncat-power7 \
00db10
diff --git a/sysdeps/powerpc/powerpc64/multiarch/ifunc-impl-list.c b/sysdeps/powerpc/powerpc64/multiarch/ifunc-impl-list.c
00db10
index 994e852..228891f 100644
00db10
--- a/sysdeps/powerpc/powerpc64/multiarch/ifunc-impl-list.c
00db10
+++ b/sysdeps/powerpc/powerpc64/multiarch/ifunc-impl-list.c
00db10
@@ -332,6 +332,14 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array,
00db10
              IFUNC_IMPL_ADD (array, i, strspn, 1,
00db10
                              __strspn_ppc))
00db10
 
00db10
+  /* Support sysdeps/powerpc/powerpc64/multiarch/strcspn.c.  */
00db10
+  IFUNC_IMPL (i, name, strcspn,
00db10
+             IFUNC_IMPL_ADD (array, i, strcspn,
00db10
+                             hwcap2 & PPC_FEATURE2_ARCH_2_07,
00db10
+                             __strcspn_power8)
00db10
+             IFUNC_IMPL_ADD (array, i, strcspn, 1,
00db10
+                             __strcspn_ppc))
00db10
+
00db10
   /* Support sysdeps/powerpc/powerpc64/multiarch/strstr.c.  */
00db10
   IFUNC_IMPL (i, name, strstr,
00db10
              IFUNC_IMPL_ADD (array, i, strstr,
00db10
diff --git a/sysdeps/powerpc/powerpc64/multiarch/strcspn-power8.S b/sysdeps/powerpc/powerpc64/multiarch/strcspn-power8.S
00db10
new file mode 100644
00db10
index 0000000..25545f8
00db10
--- /dev/null
00db10
+++ b/sysdeps/powerpc/powerpc64/multiarch/strcspn-power8.S
00db10
@@ -0,0 +1,25 @@
00db10
+/* Optimized strcspn implementation for POWER8.
00db10
+   Copyright (C) 2016 Free Software Foundation, Inc.
00db10
+   This file is part of the GNU C Library.
00db10
+
00db10
+   The GNU C Library is free software; you can redistribute it and/or
00db10
+   modify it under the terms of the GNU Lesser General Public
00db10
+   License as published by the Free Software Foundation; either
00db10
+   version 2.1 of the License, or (at your option) any later version.
00db10
+
00db10
+   The GNU C Library is distributed in the hope that it will be useful,
00db10
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
00db10
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00db10
+   Lesser General Public License for more details.
00db10
+
00db10
+   You should have received a copy of the GNU Lesser General Public
00db10
+   License along with the GNU C Library; if not, see
00db10
+   <http://www.gnu.org/licenses/>.  */
00db10
+
00db10
+#include <sysdep.h>
00db10
+
00db10
+#define STRSPN __strcspn_power8
00db10
+#undef libc_hidden_builtin_def
00db10
+#define libc_hidden_builtin_def(name)
00db10
+
00db10
+#include <sysdeps/powerpc/powerpc64/power8/strcspn.S>
00db10
diff --git a/sysdeps/powerpc/powerpc64/multiarch/strcspn-ppc64.c b/sysdeps/powerpc/powerpc64/multiarch/strcspn-ppc64.c
00db10
new file mode 100644
00db10
index 0000000..4c16386
00db10
--- /dev/null
00db10
+++ b/sysdeps/powerpc/powerpc64/multiarch/strcspn-ppc64.c
00db10
@@ -0,0 +1,26 @@
00db10
+/* Default strcspn implementation for PowerPC64.
00db10
+   Copyright (C) 2016 Free Software Foundation, Inc.
00db10
+   This file is part of the GNU C Library.
00db10
+
00db10
+   The GNU C Library is free software; you can redistribute it and/or
00db10
+   modify it under the terms of the GNU Lesser General Public
00db10
+   License as published by the Free Software Foundation; either
00db10
+   version 2.1 of the License, or (at your option) any later version.
00db10
+
00db10
+   The GNU C Library is distributed in the hope that it will be useful,
00db10
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
00db10
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00db10
+   Lesser General Public License for more details.
00db10
+
00db10
+   You should have received a copy of the GNU Lesser General Public
00db10
+   License along with the GNU C Library; if not, see
00db10
+   <http://www.gnu.org/licenses/>.  */
00db10
+
00db10
+#define STRCSPN __strcspn_ppc
00db10
+
00db10
+#ifdef SHARED
00db10
+#  undef libc_hidden_def
00db10
+#  define libc_hidden_def(name)
00db10
+#endif
00db10
+
00db10
+#include <string/strcspn.c>
00db10
diff --git a/sysdeps/powerpc/powerpc64/multiarch/strcspn.c b/sysdeps/powerpc/powerpc64/multiarch/strcspn.c
00db10
new file mode 100644
00db10
index 0000000..e7343ee
00db10
--- /dev/null
00db10
+++ b/sysdeps/powerpc/powerpc64/multiarch/strcspn.c
00db10
@@ -0,0 +1,35 @@
00db10
+/* Multiple versions of strcspn. PowerPC64 version.
00db10
+   Copyright (C) 2016 Free Software Foundation, Inc.
00db10
+   This file is part of the GNU C Library.
00db10
+
00db10
+   The GNU C Library is free software; you can redistribute it and/or
00db10
+   modify it under the terms of the GNU Lesser General Public
00db10
+   License as published by the Free Software Foundation; either
00db10
+   version 2.1 of the License, or (at your option) any later version.
00db10
+
00db10
+   The GNU C Library is distributed in the hope that it will be useful,
00db10
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
00db10
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00db10
+   Lesser General Public License for more details.
00db10
+
00db10
+   You should have received a copy of the GNU Lesser General Public
00db10
+   License along with the GNU C Library; if not, see
00db10
+   <http://www.gnu.org/licenses/>.  */
00db10
+
00db10
+#include <string.h>
00db10
+#include <shlib-compat.h>
00db10
+#include "init-arch.h"
00db10
+
00db10
+#undef strcspn
00db10
+extern __typeof (strcspn) __libc_strcspn;
00db10
+
00db10
+extern __typeof (strcspn) __strcspn_ppc attribute_hidden;
00db10
+extern __typeof (strcspn) __strcspn_power8 attribute_hidden;
00db10
+
00db10
+libc_ifunc (__libc_strcspn,
00db10
+	    (hwcap2 & PPC_FEATURE2_ARCH_2_07)
00db10
+	    ? __strcspn_power8
00db10
+	    : __strcspn_ppc);
00db10
+
00db10
+weak_alias (__libc_strcspn, strcspn)
00db10
+libc_hidden_builtin_def (strcspn)
00db10
diff --git a/sysdeps/powerpc/powerpc64/multiarch/strspn-power8.S b/sysdeps/powerpc/powerpc64/multiarch/strspn-power8.S
00db10
index 86a4e09..27d25e0 100644
00db10
--- a/sysdeps/powerpc/powerpc64/multiarch/strspn-power8.S
00db10
+++ b/sysdeps/powerpc/powerpc64/multiarch/strspn-power8.S
00db10
@@ -18,22 +18,7 @@
00db10
 
00db10
 #include <sysdep.h>
00db10
 
00db10
-#undef EALIGN
00db10
-#define EALIGN(name, alignt, words)				\
00db10
-  .section ".text";						\
00db10
-  ENTRY_2(__strspn_power8)					\
00db10
-  .align ALIGNARG(alignt);					\
00db10
-  EALIGN_W_##words;						\
00db10
-  BODY_LABEL(__strspn_power8):					\
00db10
-  cfi_startproc;						\
00db10
-  LOCALENTRY(__strspn_power8)
00db10
-
00db10
-#undef END
00db10
-#define END(name)						\
00db10
-  cfi_endproc;							\
00db10
-  TRACEBACK(__strspn_power8)					\
00db10
-  END_2(__strspn_power8)
00db10
-
00db10
+#define STRSPN __strspn_power8
00db10
 #undef libc_hidden_builtin_def
00db10
 #define libc_hidden_builtin_def(name)
00db10
 
00db10
diff --git a/sysdeps/powerpc/powerpc64/power8/strcspn.S b/sysdeps/powerpc/powerpc64/power8/strcspn.S
00db10
new file mode 100644
00db10
index 0000000..bfc58a8
00db10
--- /dev/null
00db10
+++ b/sysdeps/powerpc/powerpc64/power8/strcspn.S
00db10
@@ -0,0 +1,20 @@
00db10
+/* Optimized strcspn implementation for PowerPC64/POWER8.
00db10
+   Copyright (C) 2016 Free Software Foundation, Inc.
00db10
+   This file is part of the GNU C Library.
00db10
+
00db10
+   The GNU C Library is free software; you can redistribute it and/or
00db10
+   modify it under the terms of the GNU Lesser General Public
00db10
+   License as published by the Free Software Foundation; either
00db10
+   version 2.1 of the License, or (at your option) any later version.
00db10
+
00db10
+   The GNU C Library is distributed in the hope that it will be useful,
00db10
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
00db10
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00db10
+   Lesser General Public License for more details.
00db10
+
00db10
+   You should have received a copy of the GNU Lesser General Public
00db10
+   License along with the GNU C Library; if not, see
00db10
+   <http://www.gnu.org/licenses/>.  */
00db10
+
00db10
+#define USE_AS_STRCSPN 1
00db10
+#include <sysdeps/powerpc/powerpc64/power8/strspn.S>
00db10
diff --git a/sysdeps/powerpc/powerpc64/power8/strspn.S b/sysdeps/powerpc/powerpc64/power8/strspn.S
00db10
index 0dda437..011081d 100644
00db10
--- a/sysdeps/powerpc/powerpc64/power8/strspn.S
00db10
+++ b/sysdeps/powerpc/powerpc64/power8/strspn.S
00db10
@@ -33,6 +33,21 @@
00db10
 
00db10
 #include "sysdep.h"
00db10
 
00db10
+#ifndef USE_AS_STRCSPN
00db10
+#  define USE_AS_STRCSPN 0
00db10
+#  ifndef STRSPN
00db10
+#    define STRSPN strspn
00db10
+#  endif
00db10
+#  define INITIAL_MASK 0
00db10
+#  define UPDATE_MASK(RA, RS, RB) or	RA, RS, RB
00db10
+#else
00db10
+#  ifndef STRSPN
00db10
+#    define STRSPN strcspn
00db10
+#  endif
00db10
+#  define INITIAL_MASK -1
00db10
+#  define UPDATE_MASK(RA, RS, RB) andc	RA, RS, RB
00db10
+#endif
00db10
+
00db10
 /* Simple macro to use VSX instructions in overlapping VR's.  */
00db10
 #define XXVR(insn, vrt, vra, vrb) \
00db10
 	insn 32+vrt, 32+vra, 32+vrb
00db10
@@ -53,7 +68,7 @@
00db10
 	/* This can be updated to power8 once the minimum version of
00db10
 	   binutils supports power8 and the above instructions.  */
00db10
 	.machine power7
00db10
-EALIGN(strspn, 4, 0)
00db10
+EALIGN(STRSPN, 4, 0)
00db10
 	CALL_MCOUNT 2
00db10
 
00db10
 	/* Generate useful constants for later on.  */
00db10
@@ -66,10 +81,18 @@ EALIGN(strspn, 4, 0)
00db10
 
00db10
 	/* Prepare to compute 256b mask.  */
00db10
 	addi	r4, r4, -1
00db10
-	li	r5, 0
00db10
-	li	r6, 0
00db10
-	li	r7, 0
00db10
-	li	r8, 0
00db10
+	li	r5, INITIAL_MASK
00db10
+	li	r6, INITIAL_MASK
00db10
+	li	r7, INITIAL_MASK
00db10
+	li	r8, INITIAL_MASK
00db10
+
00db10
+#if USE_AS_STRCSPN
00db10
+	/* Ensure the null character never matches by clearing ISA bit 0 in
00db10
+	   in r5 which is the bit which will check for it in the later usage
00db10
+	   of vbpermq.  */
00db10
+	srdi	r5, r5, 1
00db10
+#endif
00db10
+
00db10
 	li	r11, 1
00db10
 	sldi	r11, r11, 63
00db10
 
00db10
@@ -97,14 +120,14 @@ L(next_needle):
00db10
 
00db10
 	/* Now, or the value into the correct GPR.  */
00db10
 	bge cr1,L(needle_gt128)
00db10
-	or	r5, r5, r10	/* 0 - 63.  */
00db10
-	or	r6, r6, r12	/* 64 - 127.  */
00db10
+	UPDATE_MASK (r5, r5, r10)	/* 0 - 63.  */
00db10
+	UPDATE_MASK (r6, r6, r12)	/* 64 - 127.  */
00db10
 	b L(next_needle)
00db10
 
00db10
 	.align 4
00db10
 L(needle_gt128):
00db10
-	or	r7, r7, r10	/* 128 - 191.  */
00db10
-	or	r8, r8, r12	/* 192 - 255.  */
00db10
+	UPDATE_MASK (r7, r7, r10)	/* 128 - 191.  */
00db10
+	UPDATE_MASK (r8, r8, r12)	/* 192 - 255.  */
00db10
 	b L(next_needle)
00db10
 
00db10
 
00db10
@@ -175,5 +198,5 @@ L(done):
00db10
 	add	r3, r3, r10
00db10
 	blr
00db10
 
00db10
-END(strspn)
00db10
-libc_hidden_builtin_def (strspn)
00db10
+END(STRSPN)
00db10
+libc_hidden_builtin_def (STRSPN)
00db10
-- 
00db10
2.1.0
00db10