Blame SOURCES/glibc-rh1385004-13.patch

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