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