olga / rpms / glibc

Forked from rpms/glibc 5 years ago
Clone

Blame SOURCES/glibc-rh1385004-13.patch

00db10
From 7cb28f3e21ff0c9658fad3d021e5a5548e1e49ae Mon Sep 17 00:00:00 2001
00db10
From: Rajalakshmi Srinivasaraghavan <raji@linux.vnet.ibm.com>
00db10
Date: Wed, 20 Apr 2016 23:10:42 +0530
00db10
Subject: [PATCH] powerpc: strcasestr optmization for power8
00db10
00db10
This patch optimizes strcasestr function for power >= 8 systems.  The average
00db10
improvement of this optimization is ~40% and compares 16 bytes at a time
00db10
using vector instructions.  This patch is tested on powerpc64 and powerpc64le.
00db10
00db10
(cherry picked from commit e413b14e18ac635b5683ab7bbb1c901f79d1b06b)
00db10
---
00db10
 ChangeLog                                          |  15 +
00db10
 sysdeps/powerpc/locale-defines.sym                 |   4 +
00db10
 sysdeps/powerpc/powerpc64/multiarch/Makefile       |   3 +-
00db10
 .../powerpc/powerpc64/multiarch/ifunc-impl-list.c  |   8 +
00db10
 .../powerpc64/multiarch/strcasestr-power8.S        |  49 ++
00db10
 .../powerpc/powerpc64/multiarch/strcasestr-ppc64.c |  34 ++
00db10
 sysdeps/powerpc/powerpc64/multiarch/strcasestr.c   |  37 ++
00db10
 sysdeps/powerpc/powerpc64/power8/Makefile          |   3 +
00db10
 .../powerpc/powerpc64/power8/strcasestr-ppc64.c    |  29 ++
00db10
 sysdeps/powerpc/powerpc64/power8/strcasestr.S      | 531 +++++++++++++++++++++
00db10
 10 files changed, 712 insertions(+), 1 deletion(-)
00db10
 create mode 100644 sysdeps/powerpc/powerpc64/multiarch/strcasestr-power8.S
00db10
 create mode 100644 sysdeps/powerpc/powerpc64/multiarch/strcasestr-ppc64.c
00db10
 create mode 100644 sysdeps/powerpc/powerpc64/multiarch/strcasestr.c
00db10
 create mode 100644 sysdeps/powerpc/powerpc64/power8/Makefile
00db10
 create mode 100644 sysdeps/powerpc/powerpc64/power8/strcasestr-ppc64.c
00db10
 create mode 100644 sysdeps/powerpc/powerpc64/power8/strcasestr.S
00db10
00db10
diff --git a/ChangeLog b/ChangeLog
00db10
index e7ea58a..6677ea2 100644
00db10
diff --git a/sysdeps/powerpc/locale-defines.sym b/sysdeps/powerpc/locale-defines.sym
00db10
index af64b92..5c5379c 100644
00db10
--- a/sysdeps/powerpc/locale-defines.sym
00db10
+++ b/sysdeps/powerpc/locale-defines.sym
00db10
@@ -3,3 +3,7 @@
00db10
 --
00db10
 
00db10
 LOCALE_CTYPE_TOLOWER	offsetof (struct __locale_struct, __ctype_tolower)
00db10
+LOCALE_CTYPE_TOUPPER	offsetof (struct __locale_struct, __ctype_toupper)
00db10
+_NL_CTYPE_NONASCII_CASE
00db10
+LOCALE_DATA_VALUES	offsetof (struct __locale_data, values)
00db10
+SIZEOF_VALUES		sizeof (((struct __locale_data *) 0)->values[0])
00db10
diff --git a/sysdeps/powerpc/powerpc64/multiarch/Makefile b/sysdeps/powerpc/powerpc64/multiarch/Makefile
00db10
index 57abe8f..7f70ceb 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
                   mempcpy-power7 mempcpy-ppc64 memchr-power7 memchr-ppc64 \
00db10
                   memrchr-power7 memrchr-ppc64 rawmemchr-power7 \
00db10
                   stpcpy-power8 stpcpy-power7 stpcpy-ppc64 \
00db10
+                  strcasestr-power8 strcasestr-ppc64 \
00db10
                   strcat-power8 strcat-power7 strcat-ppc64 \
00db10
                   strcmp-power8 strcmp-power7 strcmp-ppc64 \
00db10
                   strcpy-power8 strcpy-power7 strcpy-ppc64 \
00db10
diff --git a/sysdeps/powerpc/powerpc64/multiarch/ifunc-impl-list.c b/sysdeps/powerpc/powerpc64/multiarch/ifunc-impl-list.c
00db10
index 583885c..994e852 100644
00db10
--- a/sysdeps/powerpc/powerpc64/multiarch/ifunc-impl-list.c
00db10
+++ b/sysdeps/powerpc/powerpc64/multiarch/ifunc-impl-list.c
00db10
@@ -341,6 +341,14 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array,
00db10
              IFUNC_IMPL_ADD (array, i, strstr, 1,
00db10
                              __strstr_ppc))
00db10
00db10
+  /* Support sysdeps/powerpc/powerpc64/multiarch/strcasestr.c.  */
00db10
+  IFUNC_IMPL (i, name, strcasestr,
00db10
+             IFUNC_IMPL_ADD (array, i, strcasestr,
00db10
+                             hwcap2 & PPC_FEATURE2_ARCH_2_07,
00db10
+                             __strcasestr_power8)
00db10
+             IFUNC_IMPL_ADD (array, i, strcasestr, 1,
00db10
+                             __strcasestr_ppc))
00db10
+
00db10
   /* Support sysdeps/powerpc/powerpc64/multiarch/wcschr.c.  */
00db10
   IFUNC_IMPL (i, name, wcschr,
00db10
              IFUNC_IMPL_ADD (array, i, wcschr,
00db10
diff --git a/sysdeps/powerpc/powerpc64/multiarch/strcasestr-power8.S b/sysdeps/powerpc/powerpc64/multiarch/strcasestr-power8.S
00db10
new file mode 100644
00db10
index 0000000..c77ff9f
00db10
--- /dev/null
00db10
+++ b/sysdeps/powerpc/powerpc64/multiarch/strcasestr-power8.S
00db10
@@ -0,0 +1,49 @@
00db10
+/* Optimized strcasestr 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
+#undef EALIGN
00db10
+#define EALIGN(name, alignt, words)				\
00db10
+  .section ".text";						\
00db10
+  ENTRY_2(__strcasestr_power8)					\
00db10
+  .align ALIGNARG(alignt);					\
00db10
+  EALIGN_W_##words;						\
00db10
+  BODY_LABEL(__strcasestr_power8):				\
00db10
+  cfi_startproc;						\
00db10
+  LOCALENTRY(__strcasestr_power8)
00db10
+
00db10
+#undef END
00db10
+#define END(name)						\
00db10
+  cfi_endproc;							\
00db10
+  TRACEBACK(__strcasestr_power8)				\
00db10
+  END_2(__strcasestr_power8)
00db10
+
00db10
+#undef libc_hidden_builtin_def
00db10
+#define libc_hidden_builtin_def(name)
00db10
+
00db10
+/* The following definitions are used in strcasestr optimization.  */
00db10
+
00db10
+/* strlen is used to calculate len of r4.  */
00db10
+#define STRLEN __strlen_power8
00db10
+/* strnlen is used to check if len of r3 is more than r4.  */
00db10
+#define STRNLEN __strnlen_power7
00db10
+/* strchr is used to check if first char of r4 is present in r3.  */
00db10
+#define STRCHR __strchr_power7
00db10
+
00db10
+#include <sysdeps/powerpc/powerpc64/power8/strcasestr.S>
00db10
diff --git a/sysdeps/powerpc/powerpc64/multiarch/strcasestr-ppc64.c b/sysdeps/powerpc/powerpc64/multiarch/strcasestr-ppc64.c
00db10
new file mode 100644
00db10
index 0000000..7f7bb9e
00db10
--- /dev/null
00db10
+++ b/sysdeps/powerpc/powerpc64/multiarch/strcasestr-ppc64.c
00db10
@@ -0,0 +1,34 @@
00db10
+/* PowerPC64 default implementation of strcasestr.
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
+
00db10
+#define STRCASESTR  __strcasestr_ppc
00db10
+#if IS_IN (libc) && defined(SHARED)
00db10
+# undef libc_hidden_builtin_def
00db10
+# define libc_hidden_builtin_def(name) \
00db10
+  __hidden_ver1(__strcasestr_ppc, __GI_strcasestr, __strcasestr_ppc);
00db10
+#endif
00db10
+
00db10
+
00db10
+#undef weak_alias
00db10
+#define weak_alias(a,b)
00db10
+
00db10
+extern __typeof (strcasestr) __strcasestr_ppc attribute_hidden;
00db10
+
00db10
+#include <string/strcasestr.c>
00db10
diff --git a/sysdeps/powerpc/powerpc64/multiarch/strcasestr.c b/sysdeps/powerpc/powerpc64/multiarch/strcasestr.c
00db10
new file mode 100644
00db10
index 0000000..17ba188
00db10
--- /dev/null
00db10
+++ b/sysdeps/powerpc/powerpc64/multiarch/strcasestr.c
00db10
@@ -0,0 +1,37 @@
00db10
+/* Multiple versions of strcasestr.
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
+#if IS_IN (libc)
00db10
+# include <string.h>
00db10
+# include <shlib-compat.h>
00db10
+# include "init-arch.h"
00db10
+
00db10
+extern __typeof (__strcasestr) __strcasestr_ppc attribute_hidden;
00db10
+extern __typeof (__strcasestr) __strcasestr_power8 attribute_hidden;
00db10
+
00db10
+/* Avoid DWARF definition DIE on ifunc symbol so that GDB can handle
00db10
+   ifunc symbol properly.  */
00db10
+libc_ifunc (__strcasestr,
00db10
+		(hwcap2 & PPC_FEATURE2_ARCH_2_07)
00db10
+		? __strcasestr_power8
00db10
+		: __strcasestr_ppc);
00db10
+
00db10
+weak_alias (__strcasestr, strcasestr)
00db10
+#else
00db10
+#include <string/strcasestr.c>
00db10
+#endif
00db10
diff --git a/sysdeps/powerpc/powerpc64/power8/Makefile b/sysdeps/powerpc/powerpc64/power8/Makefile
00db10
new file mode 100644
00db10
index 0000000..71a5952
00db10
--- /dev/null
00db10
+++ b/sysdeps/powerpc/powerpc64/power8/Makefile
00db10
@@ -0,0 +1,3 @@
00db10
+ifeq ($(subdir),string)
00db10
+sysdep_routines += strcasestr-ppc64
00db10
+endif
00db10
diff --git a/sysdeps/powerpc/powerpc64/power8/strcasestr-ppc64.c b/sysdeps/powerpc/powerpc64/power8/strcasestr-ppc64.c
00db10
new file mode 100644
00db10
index 0000000..09a07b0
00db10
--- /dev/null
00db10
+++ b/sysdeps/powerpc/powerpc64/power8/strcasestr-ppc64.c
00db10
@@ -0,0 +1,29 @@
00db10
+/* Optimized strcasestr 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
+#include <string.h>
00db10
+
00db10
+#define STRCASESTR __strcasestr_ppc
00db10
+#undef libc_hidden_builtin_def
00db10
+#define libc_hidden_builtin_def(__name)
00db10
+
00db10
+#undef weak_alias
00db10
+#define weak_alias(a,b)
00db10
+extern __typeof (strcasestr) __strcasestr_ppc attribute_hidden;
00db10
+
00db10
+#include <string/strcasestr.c>
00db10
diff --git a/sysdeps/powerpc/powerpc64/power8/strcasestr.S b/sysdeps/powerpc/powerpc64/power8/strcasestr.S
00db10
new file mode 100644
00db10
index 0000000..24b2b76
00db10
--- /dev/null
00db10
+++ b/sysdeps/powerpc/powerpc64/power8/strcasestr.S
00db10
@@ -0,0 +1,531 @@
00db10
+/* Optimized strcasestr 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
+#include <sysdep.h>
00db10
+#include <locale-defines.h>
00db10
+
00db10
+/* Char * [r3] strcasestr (char *s [r3], char * pat[r4])  */
00db10
+
00db10
+/* The performance gain is obtained by comparing 16 bytes.  */
00db10
+
00db10
+/* When the first char of r4 is hit ITERATIONS times in r3
00db10
+   fallback to default.  */
00db10
+#define ITERATIONS	64
00db10
+
00db10
+#ifndef STRLEN
00db10
+/* For builds without IFUNC support, local calls should be made to internal
00db10
+   GLIBC symbol (created by libc_hidden_builtin_def).  */
00db10
+# ifdef SHARED
00db10
+#  define STRLEN   __GI_strlen
00db10
+# else
00db10
+#  define STRLEN   strlen
00db10
+# endif
00db10
+#endif
00db10
+
00db10
+#ifndef STRNLEN
00db10
+/* For builds without IFUNC support, local calls should be made to internal
00db10
+   GLIBC symbol (created by libc_hidden_builtin_def).  */
00db10
+# ifdef SHARED
00db10
+#  define STRNLEN   __GI_strnlen
00db10
+# else
00db10
+#  define STRNLEN    __strnlen
00db10
+# endif
00db10
+#endif
00db10
+
00db10
+#ifndef STRCHR
00db10
+# ifdef SHARED
00db10
+#  define STRCHR   __GI_strchr
00db10
+# else
00db10
+#  define STRCHR   strchr
00db10
+# endif
00db10
+#endif
00db10
+
00db10
+/* Convert 16 bytes of v4 and reg to lowercase and compare.  */
00db10
+#define TOLOWER(reg)     \
00db10
+	vcmpgtub	v6, v4, v1; \
00db10
+	vcmpgtub	v7, v2, v4; \
00db10
+	vand	v8, v7, v6; \
00db10
+	vand	v8, v8, v3; \
00db10
+	vor	v4, v8, v4; \
00db10
+	vcmpgtub	v6, reg, v1; \
00db10
+	vcmpgtub	v7, v2, reg; \
00db10
+	vand	v8, v7, v6; \
00db10
+	vand	v8, v8, v3; \
00db10
+	vor	reg, v8, reg; \
00db10
+	vcmpequb.	v6, reg, v4;
00db10
+
00db10
+/* TODO: change these to the actual instructions when the minimum required
00db10
+   binutils allows it.  */
00db10
+#ifdef _ARCH_PWR8
00db10
+#define VCLZD_V8_v7	vclzd	v8, v7;
00db10
+#else
00db10
+#define VCLZD_V8_v7	.long	0x11003fc2
00db10
+#endif
00db10
+
00db10
+#define	FRAMESIZE	(FRAME_MIN_SIZE+48)
00db10
+/* TODO: change this to .machine power8 when the minimum required binutils
00db10
+   allows it.  */
00db10
+	.machine  power7
00db10
+EALIGN (strcasestr, 4, 0)
00db10
+	CALL_MCOUNT 2
00db10
+	mflr	r0			/* Load link register LR to r0.  */
00db10
+	std	r31, -8(r1)		/* Save callers register r31.  */
00db10
+	std	r30, -16(r1)		/* Save callers register r30.  */
00db10
+	std	r29, -24(r1)		/* Save callers register r29.  */
00db10
+	std	r28, -32(r1)		/* Save callers register r28.  */
00db10
+	std	r27, -40(r1)		/* Save callers register r27.  */
00db10
+	std	r0, 16(r1)		/* Store the link register.  */
00db10
+	cfi_offset(r31, -8)
00db10
+	cfi_offset(r30, -16)
00db10
+	cfi_offset(r29, -24)
00db10
+	cfi_offset(r28, -32)
00db10
+	cfi_offset(r27, -40)
00db10
+	cfi_offset(lr, 16)
00db10
+	stdu	r1, -FRAMESIZE(r1)	/* Create the stack frame.  */
00db10
+	cfi_adjust_cfa_offset(FRAMESIZE)
00db10
+
00db10
+	dcbt	0, r3
00db10
+	dcbt	0, r4
00db10
+	cmpdi	cr7, r3, 0		/* Input validation.  */
00db10
+	beq	cr7, L(retnull)
00db10
+	cmpdi	cr7, r4, 0
00db10
+	beq	cr7, L(retnull)
00db10
+
00db10
+	mr	r29, r3
00db10
+	mr	r30, r4
00db10
+	/* Load first byte from r4 and check if its null.  */
00db10
+	lbz	r6, 0(r4)
00db10
+	cmpdi	cr7, r6, 0
00db10
+	beq	cr7, L(ret_r3)
00db10
+
00db10
+	ld	r10, __libc_tsd_LOCALE@got@tprel(r2)
00db10
+	add	r9, r10, __libc_tsd_LOCALE@tls
00db10
+	ld	r9, 0(r9)
00db10
+	ld	r9, LOCALE_CTYPE_TOUPPER(r9)
00db10
+	sldi	r10, r6, 2		/* Convert to upper case.  */
00db10
+	lwzx	r28, r9, r10
00db10
+
00db10
+	ld	r10, __libc_tsd_LOCALE@got@tprel(r2)
00db10
+	add	r11, r10, __libc_tsd_LOCALE@tls
00db10
+	ld	r11, 0(r11)
00db10
+	ld	r11, LOCALE_CTYPE_TOLOWER(r11)
00db10
+	sldi	r10, r6, 2              /* Convert to lower case.  */
00db10
+	lwzx	r27, r11, r10
00db10
+
00db10
+	/* Check if the first char is present.  */
00db10
+	mr	r4, r27
00db10
+	bl	STRCHR
00db10
+	nop
00db10
+	mr	r5, r3
00db10
+	mr	r3, r29
00db10
+	mr	r29, r5
00db10
+	mr	r4, r28
00db10
+	bl	STRCHR
00db10
+	nop
00db10
+	cmpdi	cr7, r29, 0
00db10
+	beq	cr7, L(firstpos)
00db10
+	cmpdi	cr7, r3, 0
00db10
+	beq	cr7, L(skipcheck)
00db10
+	cmpw	cr7, r3, r29
00db10
+	ble 	cr7, L(firstpos)
00db10
+	/* Move r3 to the first occurence.  */
00db10
+L(skipcheck):
00db10
+	mr	r3, r29
00db10
+L(firstpos):
00db10
+	mr	r29, r3
00db10
+
00db10
+	sldi	r9, r27, 8
00db10
+	or	r28, r9, r28
00db10
+	/* Reg r27 is used to count the number of iterations.  */
00db10
+	li	r27, 0
00db10
+	/* If first char of search str is not present.  */
00db10
+	cmpdi	cr7, r3, 0
00db10
+	ble	cr7, L(end)
00db10
+
00db10
+	/* Find the length of pattern.  */
00db10
+	mr	r3, r30
00db10
+	bl	STRLEN
00db10
+	nop
00db10
+
00db10
+	cmpdi	cr7, r3, 0	/* If search str is null.  */
00db10
+	beq	cr7, L(ret_r3)
00db10
+
00db10
+	mr	r31, r3
00db10
+	mr	r4, r3
00db10
+	mr	r3, r29
00db10
+	bl	STRNLEN
00db10
+	nop
00db10
+
00db10
+	cmpd	cr7, r3, r31 	/* If len(r3) < len(r4).  */
00db10
+	blt	cr7, L(retnull)
00db10
+
00db10
+	mr	r3, r29
00db10
+
00db10
+	/* Locales not matching ASCII for single bytes.  */
00db10
+	ld	r10, __libc_tsd_LOCALE@got@tprel(r2)
00db10
+	add	r9, r10, __libc_tsd_LOCALE@tls
00db10
+	ld	r9, 0(r9)
00db10
+	ld	r7, 0(r9)
00db10
+	addi	r7, r7, LOCALE_DATA_VALUES+_NL_CTYPE_NONASCII_CASE*SIZEOF_VALUES
00db10
+	lwz	r8, 0(r7)
00db10
+	cmpdi	cr7, r8, 1
00db10
+	beq	cr7, L(bytebybyte)
00db10
+
00db10
+	/* If len(r4) < 16 handle byte by byte.  */
00db10
+	/* For shorter strings we will not use vector registers.  */
00db10
+	cmpdi	cr7, r31, 16
00db10
+	blt	cr7, L(bytebybyte)
00db10
+
00db10
+	/* Comparison values used for TOLOWER.  */
00db10
+	/* Load v1 = 64('A' - 1), v2 = 91('Z' + 1), v3 = 32 in each byte.  */
00db10
+	vspltish	v0, 0
00db10
+	vspltisb	v5, 2
00db10
+	vspltisb	v4, 4
00db10
+	vsl	v3, v5, v4
00db10
+	vaddubm	v1, v3, v3
00db10
+	vspltisb	v5, 15
00db10
+	vaddubm	v2, v5, v5
00db10
+	vaddubm	v2, v1, v2
00db10
+	vspltisb	v4, -3
00db10
+	vaddubm	v2, v2, v4
00db10
+
00db10
+	/*
00db10
+	1. Load 16 bytes from r3 and r4
00db10
+	2. Check if there is null, If yes, proceed byte by byte path.
00db10
+	3. Else,Convert both to lowercase and compare.
00db10
+	4. If they are same proceed to 1.
00db10
+	5. If they dont match, find if first char of r4 is present in the
00db10
+	   loaded 16 byte of r3.
00db10
+	6. If yes, move position, load next 16 bytes of r3 and proceed to 2.
00db10
+	*/
00db10
+
00db10
+	mr	r8, r3		/* Save r3 for future use.  */
00db10
+	mr	r4, r30		/* Restore r4.  */
00db10
+	clrldi	r10, r4, 60
00db10
+	lvx	v5, 0, r4	/* Load 16 bytes from r4.  */
00db10
+	cmpdi	cr7, r10, 0
00db10
+	beq	cr7, L(begin2)
00db10
+	/* If r4 is unaligned, load another 16 bytes.  */
00db10
+#ifdef __LITTLE_ENDIAN__
00db10
+	lvsr	v7, 0, r4
00db10
+#else
00db10
+	lvsl	v7, 0, r4
00db10
+#endif
00db10
+	addi	r5, r4, 16
00db10
+	lvx	v9, 0, r5
00db10
+#ifdef __LITTLE_ENDIAN__
00db10
+	vperm	v5, v9, v5, v7
00db10
+#else
00db10
+	vperm	v5, v5, v9, v7
00db10
+#endif
00db10
+L(begin2):
00db10
+	lvx	v4, 0, r3
00db10
+	vcmpequb.	v7, v0, v4	/* Check for null.  */
00db10
+	beq	cr6, L(nullchk6)
00db10
+	b	L(trailcheck)
00db10
+
00db10
+        .align  4
00db10
+L(nullchk6):
00db10
+	clrldi	r10, r3, 60
00db10
+	cmpdi	cr7, r10, 0
00db10
+	beq	cr7, L(next16)
00db10
+#ifdef __LITTLE_ENDIAN__
00db10
+	lvsr	v7, 0, r3
00db10
+#else
00db10
+	lvsl	v7, 0, r3
00db10
+#endif
00db10
+	addi	r5, r3, 16
00db10
+	/* If r3 is unaligned, load another 16 bytes.  */
00db10
+	lvx	v10, 0, r5
00db10
+#ifdef __LITTLE_ENDIAN__
00db10
+	vperm	v4, v10, v4, v7
00db10
+#else
00db10
+	vperm	v4, v4, v10, v7
00db10
+#endif
00db10
+L(next16):
00db10
+	vcmpequb.	v6, v0, v5	/* Check for null.  */
00db10
+	beq	cr6, L(nullchk)
00db10
+	b	L(trailcheck)
00db10
+
00db10
+	.align	4
00db10
+L(nullchk):
00db10
+	vcmpequb.	v6, v0, v4
00db10
+	beq	cr6, L(nullchk1)
00db10
+	b	L(retnull)
00db10
+
00db10
+	.align	4
00db10
+L(nullchk1):
00db10
+	/* Convert both v3 and v4 to lower.  */
00db10
+	TOLOWER(v5)
00db10
+	/* If both are same, branch to match.  */
00db10
+	blt	cr6, L(match)
00db10
+	/* Find if the first char is present in next 15 bytes.  */
00db10
+#ifdef __LITTLE_ENDIAN__
00db10
+	vspltb	v6, v5, 15
00db10
+	vsldoi	v7, v0, v4, 15
00db10
+#else
00db10
+	vspltb	v6, v5, 0
00db10
+	vspltisb	v7, 8
00db10
+	vslo	v7, v4, v7
00db10
+#endif
00db10
+	vcmpequb	v7, v6, v7
00db10
+	vcmpequb.	v6, v0, v7
00db10
+	/* Shift r3 by 16 bytes and proceed.  */
00db10
+	blt	cr6, L(shift16)
00db10
+	VCLZD_V8_v7
00db10
+#ifdef __LITTLE_ENDIAN__
00db10
+	vspltb	v6, v8, 15
00db10
+#else
00db10
+	vspltb	v6, v8, 7
00db10
+#endif
00db10
+	vcmpequb.	v6, v6, v1
00db10
+	/* Shift r3 by 8  bytes and proceed.  */
00db10
+	blt	cr6, L(shift8)
00db10
+	b	L(begin)
00db10
+
00db10
+	.align	4
00db10
+L(match):
00db10
+	/* There is a match of 16 bytes, check next bytes.  */
00db10
+	cmpdi	cr7, r31, 16
00db10
+	mr	r29, r3
00db10
+	beq	cr7, L(ret_r3)
00db10
+
00db10
+L(secondmatch):
00db10
+	addi	r3, r3, 16
00db10
+	addi	r4, r4, 16
00db10
+	/* Load next 16 bytes of r3 and r4 and compare.  */
00db10
+	clrldi	r10, r4, 60
00db10
+	cmpdi	cr7, r10, 0
00db10
+	beq	cr7, L(nextload)
00db10
+	/* Handle unaligned case.  */
00db10
+	vor	v6, v9, v9
00db10
+	vcmpequb.	v7, v0, v6
00db10
+	beq	cr6, L(nullchk2)
00db10
+	b	L(trailcheck)
00db10
+
00db10
+	.align	4
00db10
+L(nullchk2):
00db10
+#ifdef __LITTLE_ENDIAN__
00db10
+	lvsr	v7, 0, r4
00db10
+#else
00db10
+	lvsl	v7, 0, r4
00db10
+#endif
00db10
+	addi	r5, r4, 16
00db10
+	/* If r4 is unaligned, load another 16 bytes.  */
00db10
+	lvx	v9, 0, r5
00db10
+#ifdef __LITTLE_ENDIAN__
00db10
+	vperm	v11, v9, v6, v7
00db10
+#else
00db10
+	vperm	v11, v6, v9, v7
00db10
+#endif
00db10
+	b	L(compare)
00db10
+
00db10
+	.align	4
00db10
+L(nextload):
00db10
+	lvx	v11, 0, r4
00db10
+L(compare):
00db10
+	vcmpequb.	v7, v0, v11
00db10
+	beq	cr6, L(nullchk3)
00db10
+	b	L(trailcheck)
00db10
+
00db10
+	.align	4
00db10
+L(nullchk3):
00db10
+	clrldi	r10, r3, 60
00db10
+	cmpdi 	cr7, r10, 0
00db10
+	beq 	cr7, L(nextload1)
00db10
+	/* Handle unaligned case.  */
00db10
+	vor	v4, v10, v10
00db10
+	vcmpequb.	v7, v0, v4
00db10
+	beq	cr6, L(nullchk4)
00db10
+	b	L(retnull)
00db10
+
00db10
+	.align	4
00db10
+L(nullchk4):
00db10
+#ifdef __LITTLE_ENDIAN__
00db10
+	lvsr	v7, 0, r3
00db10
+#else
00db10
+	lvsl	v7, 0, r3
00db10
+#endif
00db10
+	addi	r5, r3, 16
00db10
+	/* If r3 is unaligned, load another 16 bytes.  */
00db10
+	lvx	v10, 0, r5
00db10
+#ifdef __LITTLE_ENDIAN__
00db10
+	vperm	v4, v10, v4, v7
00db10
+#else
00db10
+	vperm	v4, v4, v10, v7
00db10
+#endif
00db10
+	b	L(compare1)
00db10
+
00db10
+	.align	4
00db10
+L(nextload1):
00db10
+	lvx	v4, 0, r3
00db10
+L(compare1):
00db10
+	vcmpequb.	v7, v0, v4
00db10
+	beq	cr6, L(nullchk5)
00db10
+	b	L(retnull)
00db10
+
00db10
+	.align	4
00db10
+L(nullchk5):
00db10
+	/* Convert both v3 and v4 to lower.  */
00db10
+	TOLOWER(v11)
00db10
+	/* If both are same, branch to secondmatch.  */
00db10
+	blt 	cr6, L(secondmatch)
00db10
+	/* Continue the search.  */
00db10
+        b	L(begin)
00db10
+
00db10
+	.align	4
00db10
+L(trailcheck):
00db10
+	ld	r10, __libc_tsd_LOCALE@got@tprel(r2)
00db10
+	add	r11, r10, __libc_tsd_LOCALE@tls
00db10
+	ld	r11, 0(r11)
00db10
+	ld	r11, LOCALE_CTYPE_TOLOWER(r11)
00db10
+L(loop2):
00db10
+	lbz	r5, 0(r3)               /* Load byte from r3.  */
00db10
+	lbz	r6, 0(r4)               /* Load next byte from r4.  */
00db10
+	cmpdi 	cr7, r6, 0              /* Is it null?  */
00db10
+	beq 	cr7, L(updater3)
00db10
+	cmpdi 	cr7, r5, 0              /* Is it null?  */
00db10
+	beq 	cr7, L(retnull)         /* If yes, return.  */
00db10
+	addi	r3, r3, 1
00db10
+	addi	r4, r4, 1               /* Increment r4.  */
00db10
+	sldi	r10, r5, 2              /* Convert to lower case.  */
00db10
+	lwzx	r10, r11, r10
00db10
+	sldi	r7, r6, 2               /* Convert to lower case.  */
00db10
+	lwzx	r7, r11, r7
00db10
+	cmpw	cr7, r7, r10            /* Compare with byte from r4.  */
00db10
+	bne	cr7, L(begin)
00db10
+	b	L(loop2)
00db10
+
00db10
+	.align	4
00db10
+L(shift8):
00db10
+	addi	r8, r8, 7
00db10
+	b	L(begin)
00db10
+	.align	4
00db10
+L(shift16):
00db10
+	addi	r8, r8, 15
00db10
+	.align	4
00db10
+L(begin):
00db10
+	addi	r8, r8, 1
00db10
+	mr	r3, r8
00db10
+	/* When our iterations exceed ITERATIONS,fall back to default.  */
00db10
+	addi	r27, r27, 1
00db10
+	cmpdi	cr7, r27, ITERATIONS
00db10
+	beq	cr7, L(default)
00db10
+	mr	r4, r30         /* Restore r4.  */
00db10
+	b	L(begin2)
00db10
+
00db10
+	/* Handling byte by byte.  */
00db10
+	.align	4
00db10
+L(loop1):
00db10
+	mr	r3, r8
00db10
+	addi	r27, r27, 1
00db10
+	cmpdi	cr7, r27, ITERATIONS
00db10
+	beq	cr7, L(default)
00db10
+	mr	r29, r8
00db10
+	srdi	r4, r28, 8
00db10
+	/* Check if the first char is present.  */
00db10
+	bl	STRCHR
00db10
+	nop
00db10
+	mr	r5, r3
00db10
+	mr	r3, r29
00db10
+	mr	r29, r5
00db10
+	sldi	r4, r28, 56
00db10
+	srdi	r4, r4, 56
00db10
+	bl	STRCHR
00db10
+	nop
00db10
+	cmpdi	cr7, r29, 0
00db10
+	beq	cr7, L(nextpos)
00db10
+	cmpdi	cr7, r3, 0
00db10
+	beq	cr7, L(skipcheck1)
00db10
+	cmpw	cr7, r3, r29
00db10
+	ble 	cr7, L(nextpos)
00db10
+	/* Move r3 to first occurence.  */
00db10
+L(skipcheck1):
00db10
+	mr	r3, r29
00db10
+L(nextpos):
00db10
+	mr	r29, r3
00db10
+	cmpdi 	cr7, r3, 0
00db10
+	ble 	cr7, L(retnull)
00db10
+L(bytebybyte):
00db10
+	ld	r10, __libc_tsd_LOCALE@got@tprel(r2)
00db10
+	add	r11, r10, __libc_tsd_LOCALE@tls
00db10
+	ld	r11, 0(r11)
00db10
+	ld	r11, LOCALE_CTYPE_TOLOWER(r11)
00db10
+	mr	r4, r30                 /* Restore r4.  */
00db10
+	mr	r8, r3                  /* Save r3.  */
00db10
+	addi	r8, r8, 1
00db10
+
00db10
+L(loop):
00db10
+	addi	r3, r3, 1
00db10
+	lbz	r5, 0(r3)               /* Load byte from r3.  */
00db10
+	addi	r4, r4, 1               /* Increment r4.  */
00db10
+	lbz	r6, 0(r4)               /* Load next byte from r4.  */
00db10
+	cmpdi 	cr7, r6, 0              /* Is it null?  */
00db10
+	beq 	cr7, L(updater3)
00db10
+	cmpdi 	cr7, r5, 0              /* Is it null?  */
00db10
+	beq 	cr7, L(retnull)         /* If yes, return.  */
00db10
+	sldi	r10, r5, 2              /* Convert to lower case.  */
00db10
+	lwzx	r10, r11, r10
00db10
+	sldi	r7, r6, 2               /* Convert to lower case.  */
00db10
+	lwzx	r7, r11, r7
00db10
+	cmpw	cr7, r7, r10            /* Compare with byte from r4.  */
00db10
+	bne 	cr7, L(loop1)
00db10
+	b	L(loop)
00db10
+
00db10
+	/* Handling return values.  */
00db10
+	.align	4
00db10
+L(updater3):
00db10
+	subf	r3, r31, r3	/* Reduce r31 (len of r4) from r3.  */
00db10
+	b	L(end)
00db10
+
00db10
+	.align	4
00db10
+L(ret_r3):
00db10
+	mr	r3, r29		/* Return point of match.  */
00db10
+	b	L(end)
00db10
+
00db10
+	.align	4
00db10
+L(retnull):
00db10
+	li	r3, 0		/* Substring was not found.  */
00db10
+	b	L(end)
00db10
+
00db10
+	.align	4
00db10
+L(default):
00db10
+	mr	r4, r30
00db10
+	bl	__strcasestr_ppc
00db10
+	nop
00db10
+
00db10
+	.align	4
00db10
+L(end):
00db10
+	addi	r1, r1, FRAMESIZE	/* Restore stack pointer.  */
00db10
+	cfi_adjust_cfa_offset(-FRAMESIZE)
00db10
+	ld	r0, 16(r1)	/* Restore the saved link register.  */
00db10
+	ld	r27, -40(r1)
00db10
+	ld	r28, -32(r1)
00db10
+	ld	r29, -24(r1)	/* Restore callers save register r29.  */
00db10
+	ld	r30, -16(r1)	/* Restore callers save register r30.  */
00db10
+	ld	r31, -8(r1)	/* Restore callers save register r31.  */
00db10
+	cfi_restore(lr)
00db10
+	cfi_restore(r27)
00db10
+	cfi_restore(r28)
00db10
+	cfi_restore(r29)
00db10
+	cfi_restore(r30)
00db10
+	cfi_restore(r31)
00db10
+	mtlr	r0		/* Branch to link register.  */
00db10
+	blr
00db10
+END (strcasestr)
00db10
+libc_hidden_builtin_def (strcasestr)
00db10
-- 
00db10
2.1.0
00db10