8ae002
From 5db5f0071917cf14b454596f847fc7ff6e63e317 Mon Sep 17 00:00:00 2001
8ae002
From: Rajalakshmi Srinivasaraghavan <raji@linux.vnet.ibm.com>
8ae002
Date: Wed, 24 Jun 2015 02:08:21 -0400
8ae002
Subject: [PATCH] powerpc: strstr optimization
8ae002
8ae002
This patch optimizes strstr function for power >= 7 systems.  Performance
8ae002
gain is obtained using aligned memory access and usage of cmpb
8ae002
instruction for quicker comparison.  The average improvement of this
8ae002
optimization is ~40%.  Tested on ppc64 and ppc64le.
8ae002
8ae002
2015-07-16  Rajalakshmi Srinivasaraghavan  <raji@linux.vnet.ibm.com>
8ae002
8ae002
	* sysdeps/powerpc/powerpc64/multiarch/Makefile: Add strstr().
8ae002
	* sysdeps/powerpc/powerpc64/multiarch/ifunc-impl-list.c: Likewise.
8ae002
	* sysdeps/powerpc/powerpc64/power7/strstr.S: New File.
8ae002
	* sysdeps/powerpc/powerpc64/multiarch/strstr-power7.S: New File.
8ae002
	* sysdeps/powerpc/powerpc64/multiarch/strstr-ppc64.c: New File.
8ae002
	* sysdeps/powerpc/powerpc64/multiarch/strstr.c: New File.
8ae002
8ae002
(cherry picked from commit b42f8cad52ebfbfd43ebf6e42e606b489ffbd466)
8ae002
---
8ae002
 ChangeLog                                          |  10 +
8ae002
 sysdeps/powerpc/powerpc64/multiarch/Makefile       |   2 +-
8ae002
 .../powerpc/powerpc64/multiarch/ifunc-impl-list.c  |   9 +
8ae002
 .../powerpc/powerpc64/multiarch/strstr-power7.S    |  44 ++
8ae002
 sysdeps/powerpc/powerpc64/multiarch/strstr-ppc64.c |  29 ++
8ae002
 sysdeps/powerpc/powerpc64/multiarch/strstr.c       |  34 ++
8ae002
 sysdeps/powerpc/powerpc64/power7/strstr.S          | 509 +++++++++++++++++++++
8ae002
 7 files changed, 636 insertions(+), 1 deletion(-)
8ae002
 create mode 100644 sysdeps/powerpc/powerpc64/multiarch/strstr-power7.S
8ae002
 create mode 100644 sysdeps/powerpc/powerpc64/multiarch/strstr-ppc64.c
8ae002
 create mode 100644 sysdeps/powerpc/powerpc64/multiarch/strstr.c
8ae002
 create mode 100644 sysdeps/powerpc/powerpc64/power7/strstr.S
8ae002
8ae002
diff --git a/ChangeLog b/ChangeLog
8ae002
index 1aeb84b..8e98192 100644
8ae002
8ae002
diff --git a/sysdeps/powerpc/powerpc64/multiarch/Makefile b/sysdeps/powerpc/powerpc64/multiarch/Makefile
8ae002
index 17265bd..3b0e3a0 100644
8ae002
--- a/sysdeps/powerpc/powerpc64/multiarch/Makefile
8ae002
+++ b/sysdeps/powerpc/powerpc64/multiarch/Makefile
8ae002
@@ -19,6 +19,7 @@ sysdep_routines += memcpy-power7 memcpy-a2 memcpy-power6 memcpy-cell \
8ae002
                   stpncpy-power8 stpncpy-power7 stpncpy-ppc64 \
8ae002
                   strncpy-power8 strncpy-power7 strncpy-ppc64 \
8ae002
                   strncat-power7 \
8ae002
+                  strstr-power7 strstr-ppc64 \
8ae002
                   rawmemchr-ppc64 strlen-power7 strlen-ppc64 strnlen-power7 \
8ae002
                   strnlen-ppc64 strcasecmp-power7 strcasecmp_l-power7 \
8ae002
                   strncase-power7 strncase_l-power7 \
8ae002
diff --git a/sysdeps/powerpc/powerpc64/multiarch/ifunc-impl-list.c b/sysdeps/powerpc/powerpc64/multiarch/ifunc-impl-list.c
8ae002
index f5fdea5..364385b 100644
8ae002
--- a/sysdeps/powerpc/powerpc64/multiarch/ifunc-impl-list.c
8ae002
+++ b/sysdeps/powerpc/powerpc64/multiarch/ifunc-impl-list.c
8ae002
@@ -322,6 +322,14 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array,
8ae002
                 IFUNC_IMPL_ADD (array, i, strcat, 1,
8ae002
                                 __strcat_ppc))
8ae002
 
8ae002
+  /* Support sysdeps/powerpc/powerpc64/multiarch/strstr.c.  */
8ae002
+  IFUNC_IMPL (i, name, strstr,
8ae002
+             IFUNC_IMPL_ADD (array, i, strstr,
8ae002
+                             hwcap & PPC_FEATURE_HAS_VSX,
8ae002
+                             __strstr_power7)
8ae002
+             IFUNC_IMPL_ADD (array, i, strstr, 1,
8ae002
+                             __strstr_ppc))
8ae002
+
8ae002
   /* Support sysdeps/powerpc/powerpc64/multiarch/wcschr.c.  */
8ae002
   IFUNC_IMPL (i, name, wcschr,
8ae002
              IFUNC_IMPL_ADD (array, i, wcschr,
8ae002
diff --git a/sysdeps/powerpc/powerpc64/multiarch/strstr-power7.S b/sysdeps/powerpc/powerpc64/multiarch/strstr-power7.S
8ae002
new file mode 100644
8ae002
index 0000000..94ce95b
8ae002
--- /dev/null
8ae002
+++ b/sysdeps/powerpc/powerpc64/multiarch/strstr-power7.S
8ae002
@@ -0,0 +1,44 @@
8ae002
+/* Optimized strstr implementation for POWER7.
8ae002
+   Copyright (C) 2015 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
+#undef EALIGN
8ae002
+#define EALIGN(name, alignt, words)				\
8ae002
+  .section ".text";						\
8ae002
+  ENTRY_2(__strstr_power7)					\
8ae002
+  .align ALIGNARG(alignt);					\
8ae002
+  EALIGN_W_##words;						\
8ae002
+  BODY_LABEL(__strstr_power7):					\
8ae002
+  cfi_startproc;						\
8ae002
+  LOCALENTRY(__strstr_power7)
8ae002
+
8ae002
+#undef END
8ae002
+#define END(name)						\
8ae002
+  cfi_endproc;							\
8ae002
+  TRACEBACK(__strstr_power7)					\
8ae002
+  END_2(__strstr_power7)
8ae002
+
8ae002
+#undef libc_hidden_builtin_def
8ae002
+#define libc_hidden_builtin_def(name)
8ae002
+
8ae002
+#define STRLEN __strlen_power7
8ae002
+#define STRNLEN __strnlen_power7
8ae002
+#define STRCHR __strchr_power7
8ae002
+
8ae002
+#include <sysdeps/powerpc/powerpc64/power7/strstr.S>
8ae002
diff --git a/sysdeps/powerpc/powerpc64/multiarch/strstr-ppc64.c b/sysdeps/powerpc/powerpc64/multiarch/strstr-ppc64.c
8ae002
new file mode 100644
8ae002
index 0000000..7fa2ace
8ae002
--- /dev/null
8ae002
+++ b/sysdeps/powerpc/powerpc64/multiarch/strstr-ppc64.c
8ae002
@@ -0,0 +1,29 @@
8ae002
+/* Copyright (C) 2015 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
+
8ae002
+#define STRSTR __strstr_ppc
8ae002
+#if IS_IN (libc) && defined(SHARED)
8ae002
+# undef libc_hidden_builtin_def
8ae002
+# define libc_hidden_builtin_def(name) \
8ae002
+  __hidden_ver1(__strstr_ppc, __GI_strstr, __strstr_ppc);
8ae002
+#endif
8ae002
+
8ae002
+extern __typeof (strstr) __strstr_ppc attribute_hidden;
8ae002
+
8ae002
+#include <string/strstr.c>
8ae002
diff --git a/sysdeps/powerpc/powerpc64/multiarch/strstr.c b/sysdeps/powerpc/powerpc64/multiarch/strstr.c
8ae002
new file mode 100644
8ae002
index 0000000..2be7646
8ae002
--- /dev/null
8ae002
+++ b/sysdeps/powerpc/powerpc64/multiarch/strstr.c
8ae002
@@ -0,0 +1,34 @@
8ae002
+/* Multiple versions of strstr. PowerPC64 version.
8ae002
+   Copyright (C) 2015 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 multiple versions only for definition in libc.  */
8ae002
+#if IS_IN (libc)
8ae002
+# include <string.h>
8ae002
+# include <shlib-compat.h>
8ae002
+# include "init-arch.h"
8ae002
+
8ae002
+extern __typeof (strstr) __strstr_ppc attribute_hidden;
8ae002
+extern __typeof (strstr) __strstr_power7 attribute_hidden;
8ae002
+
8ae002
+/* Avoid DWARF definition DIE on ifunc symbol so that GDB can handle
8ae002
+   ifunc symbol properly.  */
8ae002
+libc_ifunc (strstr,
8ae002
+            (hwcap & PPC_FEATURE_HAS_VSX)
8ae002
+            ? __strstr_power7
8ae002
+            : __strstr_ppc);
8ae002
+#endif
8ae002
diff --git a/sysdeps/powerpc/powerpc64/power7/strstr.S b/sysdeps/powerpc/powerpc64/power7/strstr.S
8ae002
new file mode 100644
8ae002
index 0000000..8dca31c
8ae002
--- /dev/null
8ae002
+++ b/sysdeps/powerpc/powerpc64/power7/strstr.S
8ae002
@@ -0,0 +1,509 @@
8ae002
+/* Optimized strstr implementation for PowerPC64/POWER7.
8ae002
+   Copyright (C) 2015 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
+/* Char * [r3] strstr (char *s [r3], char * pat[r4])  */
8ae002
+
8ae002
+/* The performance gain is obtained using aligned memory access, load
8ae002
+ * doubleword and usage of cmpb instruction for quicker comparison.  */
8ae002
+
8ae002
+#ifndef STRLEN
8ae002
+/* For builds with no IFUNC support, local calls should be made to internal
8ae002
+   GLIBC symbol (created by libc_hidden_builtin_def).  */
8ae002
+# ifdef SHARED
8ae002
+#  define STRLEN   __GI_strlen
8ae002
+# else
8ae002
+#  define STRLEN   strlen
8ae002
+# endif
8ae002
+#endif
8ae002
+
8ae002
+#ifndef STRNLEN
8ae002
+/* For builds with no IFUNC support, local calls should be made to internal
8ae002
+   GLIBC symbol (created by libc_hidden_builtin_def).  */
8ae002
+# ifdef SHARED
8ae002
+#  define STRNLEN   __GI_strnlen
8ae002
+# else
8ae002
+#  define STRNLEN   strnlen
8ae002
+# endif
8ae002
+#endif
8ae002
+
8ae002
+#ifndef STRCHR
8ae002
+# ifdef SHARED
8ae002
+#  define STRCHR   __GI_strchr
8ae002
+# else
8ae002
+#  define STRCHR   strchr
8ae002
+# endif
8ae002
+#endif
8ae002
+
8ae002
+#define	FRAMESIZE	(FRAME_MIN_SIZE+32)
8ae002
+	.machine  power7
8ae002
+EALIGN (strstr, 4, 0)
8ae002
+	CALL_MCOUNT 2
8ae002
+	mflr	r0			/* Load link register LR to r0.  */
8ae002
+	std	r31, -8(r1)		/* Save callers register r31.  */
8ae002
+	cfi_offset(r31, -8)
8ae002
+	std	r30, -16(r1)		/* Save callers register r30.  */
8ae002
+	cfi_offset(r30, -16)
8ae002
+	std	r29, -24(r1)		/* Save callers register r29.  */
8ae002
+	cfi_offset(r29, -24)
8ae002
+	std	r0, 16(r1)		/* Store the link register.  */
8ae002
+	cfi_offset(lr, 16)
8ae002
+	stdu	r1, -FRAMESIZE(r1)	/* Create the stack frame.  */
8ae002
+	cfi_adjust_cfa_offset(FRAMESIZE)
8ae002
+
8ae002
+	dcbt	0, r3
8ae002
+	dcbt	0, r4
8ae002
+
8ae002
+	cmpdi	cr7, r3, 0
8ae002
+	beq	cr7, L(retnull)
8ae002
+	cmpdi	cr7, r4, 0
8ae002
+	beq	cr7, L(retnull)
8ae002
+
8ae002
+	mr	r29, r3
8ae002
+	mr	r30, r4
8ae002
+	mr	r3, r4
8ae002
+	bl	STRLEN
8ae002
+	nop
8ae002
+
8ae002
+	cmpdi	cr7, r3, 0	/* If search str is null.  */
8ae002
+	beq	cr7, L(ret_r3)
8ae002
+
8ae002
+	/* Call __strstr_ppc if needle len > 2048 */
8ae002
+	cmpdi	cr7, r3, 2048
8ae002
+	bgt	cr7, L(default)
8ae002
+
8ae002
+	mr	r31, r3
8ae002
+	mr	r4, r3
8ae002
+	mr	r3, r29
8ae002
+	bl	STRNLEN
8ae002
+	nop
8ae002
+
8ae002
+	cmpd	cr7, r3, r31 	/* If len(r3) < len(r4).  */
8ae002
+	blt	cr7, L(retnull)
8ae002
+	mr	r3, r29
8ae002
+	lbz	r4, 0(r30)
8ae002
+	bl	STRCHR
8ae002
+	nop
8ae002
+
8ae002
+	mr	r11, r3
8ae002
+	/* If first char of search str is not present.  */
8ae002
+	cmpdi	cr7, r3, 0
8ae002
+	ble	cr7, L(end)
8ae002
+
8ae002
+	rldicl	r8, r3, 0, 52	/* Page cross check.  */
8ae002
+	cmpldi	cr7, r8, 4096-16
8ae002
+	bgt	cr7, L(bytebybyte)
8ae002
+
8ae002
+	rldicl	r8, r30, 0, 52
8ae002
+	cmpldi	cr7, r8, 4096-16
8ae002
+	bgt	cr7, L(bytebybyte)
8ae002
+
8ae002
+	/* If len(r4) < 8 handle in a different way.  */
8ae002
+	/* Shift position based on null and use cmpb.  */
8ae002
+	cmpdi	cr7, r31, 8
8ae002
+	blt	cr7, L(lessthan8)
8ae002
+
8ae002
+	/* Len(r4) >= 8 reaches here.  */
8ae002
+	mr	r8, r3		/* Save r3 for future use.  */
8ae002
+	mr	r4, r30		/* Restore r4.  */
8ae002
+	li	r0, 0
8ae002
+	rlwinm	r10, r30, 3, 26, 28	/* Calculate padding in bits.  */
8ae002
+	clrrdi	r4, r4, 3	/* Make r4 aligned to 8.  */
8ae002
+	ld	r6, 0(r4)
8ae002
+	addi	r4, r4, 8
8ae002
+	cmpdi	cr7, r10, 0	/* Check if its already aligned?  */
8ae002
+	beq	cr7, L(begin1)
8ae002
+#ifdef __LITTLE_ENDIAN__
8ae002
+	srd	r6, r6, r10	/* Discard unwanted bits.  */
8ae002
+#else
8ae002
+	sld	r6, r6, r10
8ae002
+#endif
8ae002
+	ld	r9, 0(r4)
8ae002
+	subfic	r10, r10, 64
8ae002
+#ifdef __LITTLE_ENDIAN__
8ae002
+	sld	r9, r9, r10	/* Discard unwanted bits.  */
8ae002
+#else
8ae002
+	srd	r9, r9, r10
8ae002
+#endif
8ae002
+	or	r6, r6, r9	/* Form complete search str.  */
8ae002
+L(begin1):
8ae002
+	mr	r29, r6
8ae002
+	rlwinm	r10, r3, 3, 26, 28
8ae002
+	clrrdi	r3, r3, 3
8ae002
+	ld	r5, 0(r3)
8ae002
+	cmpb	r9, r0, r6	/* Check if input has null.  */
8ae002
+	cmpdi	cr7, r9, 0
8ae002
+	bne	cr7, L(return3)
8ae002
+	cmpb	r9, r0, r5	/* Check if input has null.  */
8ae002
+#ifdef __LITTLE_ENDIAN__
8ae002
+	srd	r9, r9, r10
8ae002
+#else
8ae002
+	sld	r9, r9, r10
8ae002
+#endif
8ae002
+	cmpdi	cr7, r9, 0
8ae002
+	bne	cr7, L(retnull)
8ae002
+
8ae002
+	li	r12, -8		/* Shift values.  */
8ae002
+	li	r11, 72		/* Shift values.  */
8ae002
+	cmpdi	cr7, r10, 0
8ae002
+	beq	cr7, L(nextbyte1)
8ae002
+	mr	r12, r10
8ae002
+	addi	r12, r12, -8
8ae002
+	subfic	r11, r12, 64
8ae002
+
8ae002
+L(nextbyte1):
8ae002
+	ldu	r7, 8(r3) 	/* Load next dw.  */
8ae002
+	addi	r12, r12, 8	/* Shift one byte and compare.  */
8ae002
+	addi	r11, r11, -8
8ae002
+#ifdef __LITTLE_ENDIAN__
8ae002
+	srd	r9, r5, r12	/* Rotate based on mask.  */
8ae002
+	sld	r10, r7, r11
8ae002
+#else
8ae002
+	sld	r9, r5, r12
8ae002
+	srd	r10, r7, r11
8ae002
+#endif
8ae002
+	/* Form single dw from few bytes on first load and second load.  */
8ae002
+	or	r10, r9, r10
8ae002
+	/* Check for null in the formed dw.  */
8ae002
+	cmpb	r9, r0, r10
8ae002
+	cmpdi	cr7, r9, 0
8ae002
+	bne	cr7, L(retnull)
8ae002
+	/* Cmpb search str and input str.  */
8ae002
+	cmpb	r9, r10, r6
8ae002
+	cmpdi	cr7, r9, -1
8ae002
+	beq	cr7, L(match)
8ae002
+	addi	r8, r8, 1
8ae002
+	b	L(begin)
8ae002
+
8ae002
+	.align	4
8ae002
+L(match):
8ae002
+	/* There is a match of 8 bytes, check next bytes.  */
8ae002
+	cmpdi	cr7, r31, 8
8ae002
+	beq	cr7, L(return)
8ae002
+	/* Update next starting point r8.  */
8ae002
+	srdi	r9, r11, 3
8ae002
+	subf	r9, r9, r3
8ae002
+	mr	r8, r9
8ae002
+
8ae002
+L(secondmatch):
8ae002
+	mr	r5, r7
8ae002
+	rlwinm	r10, r30, 3, 26, 28	/* Calculate padding in bits.  */
8ae002
+	ld	r6, 0(r4)
8ae002
+	addi	r4, r4, 8
8ae002
+	cmpdi	cr7, r10, 0	/* Check if its already aligned?  */
8ae002
+	beq	cr7, L(proceed3)
8ae002
+#ifdef __LITTLE_ENDIAN__
8ae002
+	srd	r6, r6, r10	/* Discard unwanted bits.  */
8ae002
+	cmpb	r9, r0, r6
8ae002
+	sld	r9, r9, r10
8ae002
+#else
8ae002
+	sld	r6, r6, r10
8ae002
+	cmpb	r9, r0, r6
8ae002
+	srd	r9, r9, r10
8ae002
+#endif
8ae002
+	cmpdi	cr7, r9, 0
8ae002
+	bne	cr7, L(proceed3)
8ae002
+	ld	r9, 0(r4)
8ae002
+	subfic	r10, r10, 64
8ae002
+#ifdef __LITTLE_ENDIAN__
8ae002
+	sld	r9, r9, r10	/* Discard unwanted bits.  */
8ae002
+#else
8ae002
+	srd	r9, r9, r10
8ae002
+#endif
8ae002
+	or	r6, r6, r9	/* Form complete search str.  */
8ae002
+
8ae002
+L(proceed3):
8ae002
+	li	r7, 0
8ae002
+	addi	r3, r3, 8
8ae002
+	cmpb	r9, r0, r5
8ae002
+	cmpdi	cr7, r9, 0
8ae002
+	bne	cr7, L(proceed4)
8ae002
+	ld	r7, 0(r3)
8ae002
+L(proceed4):
8ae002
+#ifdef __LITTLE_ENDIAN__
8ae002
+	srd	r9, r5, r12
8ae002
+	sld	r10, r7, r11
8ae002
+#else
8ae002
+	sld	r9, r5, r12
8ae002
+	srd	r10, r7, r11
8ae002
+#endif
8ae002
+	/* Form single dw with few bytes from first and second load.  */
8ae002
+	or	r10, r9, r10
8ae002
+	cmpb	r9, r0, r6
8ae002
+	cmpdi	cr7, r9, 0
8ae002
+	bne	cr7, L(return4)
8ae002
+	/* Check for null in the formed dw.  */
8ae002
+	cmpb	r9, r0, r10
8ae002
+	cmpdi	cr7, r9, 0
8ae002
+	bne	cr7, L(retnull)
8ae002
+	/* If the next 8 bytes dont match, start search again.  */
8ae002
+	cmpb	r9, r10, r6
8ae002
+	cmpdi	cr7, r9, -1
8ae002
+	bne	cr7, L(reset)
8ae002
+	/* If the next 8 bytes match, load and compare next 8.  */
8ae002
+	b	L(secondmatch)
8ae002
+
8ae002
+	.align	4
8ae002
+L(reset):
8ae002
+	/* Start the search again.  */
8ae002
+	addi	r8, r8, 1
8ae002
+	b	L(begin)
8ae002
+
8ae002
+	.align	4
8ae002
+L(return3):
8ae002
+	/* Count leading zeros and compare partial dw.  */
8ae002
+#ifdef __LITTLE_ENDIAN__
8ae002
+	addi	r7, r9, -1
8ae002
+	andc	r7, r7, r9
8ae002
+	popcntd	r7, r7
8ae002
+	subfic	r7, r7, 64
8ae002
+	sld	r10, r5, r7
8ae002
+	sld	r6, r6, r7
8ae002
+#else
8ae002
+	cntlzd	r7, r9
8ae002
+	subfic	r7, r7, 64
8ae002
+	srd	r10, r5, r7
8ae002
+	srd	r6, r6, r7
8ae002
+#endif
8ae002
+	cmpb	r9, r10, r6
8ae002
+	cmpdi	cr7, r9, -1
8ae002
+	addi	r8, r8, 1
8ae002
+	/* Start search again if there is no match.  */
8ae002
+	bne	cr7, L(begin)
8ae002
+	/* If the words match, update return values.  */
8ae002
+	subfic	r7, r7, 64
8ae002
+	srdi	r7, r7, 3
8ae002
+	add	r3, r3, r7
8ae002
+	subf	r3, r31, r3
8ae002
+	b	L(end)
8ae002
+
8ae002
+	.align	4
8ae002
+L(return4):
8ae002
+	/* Count leading zeros and compare partial dw.  */
8ae002
+#ifdef __LITTLE_ENDIAN__
8ae002
+	addi	r7, r9, -1
8ae002
+	andc	r7, r7, r9
8ae002
+	popcntd	r7, r7
8ae002
+	subfic	r7, r7, 64
8ae002
+	sld	r10, r10, r7
8ae002
+	sld	r6, r6, r7
8ae002
+#else
8ae002
+	cntlzd	r7, r9
8ae002
+	subfic	r7, r7, 64
8ae002
+	srd	r10, r10, r7
8ae002
+	srd	r6, r6, r7
8ae002
+#endif
8ae002
+	cmpb	r9, r10, r6
8ae002
+	cmpdi	cr7, r9, -1
8ae002
+	addi	r8, r8, 1
8ae002
+	bne	cr7, L(begin)
8ae002
+	subfic	r7, r7, 64
8ae002
+	srdi	r11, r11, 3
8ae002
+	subf	r3, r11, r3
8ae002
+	srdi	r7, r7, 3
8ae002
+	add	r3, r3, r7
8ae002
+	subf	r3, r31, r3
8ae002
+	b	L(end)
8ae002
+
8ae002
+	.align	4
8ae002
+L(begin):
8ae002
+	mr	r3, r8
8ae002
+	lbz	r4, 0(r30)
8ae002
+	bl	STRCHR
8ae002
+	nop
8ae002
+	/* If first char of search str is not present.  */
8ae002
+	cmpdi	cr7, r3, 0
8ae002
+	ble	cr7, L(end)
8ae002
+	mr	r8, r3
8ae002
+	mr	r4, r30		/* Restore r4.  */
8ae002
+	li	r0, 0
8ae002
+	mr	r6, r29
8ae002
+	clrrdi	r4, r4, 3
8ae002
+	addi	r4, r4, 8
8ae002
+	b	L(begin1)
8ae002
+
8ae002
+	/* Handle less than 8 search string.  */
8ae002
+	.align	4
8ae002
+L(lessthan8):
8ae002
+	mr	r4, r3
8ae002
+	mr	r9, r30
8ae002
+	li	r0, 0
8ae002
+
8ae002
+	rlwinm	r10, r9, 3, 26, 28	/* Calculate padding in bits.  */
8ae002
+	srdi	r8, r10, 3	/* Padding in bytes.  */
8ae002
+	clrrdi	r9, r9, 3	/* Make r4 aligned to 8.  */
8ae002
+	ld	r6, 0(r9)
8ae002
+	cmpdi	cr7, r10, 0	/* Check if its already aligned?  */
8ae002
+	beq	cr7, L(proceed2)
8ae002
+#ifdef __LITTLE_ENDIAN__
8ae002
+	srd	r6, r6, r10	/* Discard unwanted bits.  */
8ae002
+#else
8ae002
+	sld	r6, r6, r10
8ae002
+#endif
8ae002
+	subfic	r8, r8, 8
8ae002
+	cmpd	cr7, r8, r31	/* Next load needed?  */
8ae002
+	bge	cr7, L(proceed2)
8ae002
+	ld	r7, 8(r9)
8ae002
+	subfic	r10, r10, 64
8ae002
+#ifdef __LITTLE_ENDIAN__
8ae002
+	sld	r7, r7, r10	/* Discard unwanted bits.  */
8ae002
+#else
8ae002
+	srd	r7, r7, r10
8ae002
+#endif
8ae002
+	or	r6, r6, r7	/* Form complete search str.  */
8ae002
+L(proceed2):
8ae002
+	mr	r29, r6
8ae002
+	rlwinm	r10, r3, 3, 26, 28
8ae002
+	clrrdi	r7, r3, 3	/* Make r3 aligned.  */
8ae002
+	ld	r5, 0(r7)
8ae002
+	sldi	r8, r31, 3
8ae002
+	subfic	r8, r8, 64
8ae002
+#ifdef __LITTLE_ENDIAN__
8ae002
+	sld	r6, r6, r8
8ae002
+	cmpb	r9, r0, r5
8ae002
+	srd	r9, r9, r10
8ae002
+#else
8ae002
+	srd	r6, r6, r8
8ae002
+	cmpb	r9, r0, r5
8ae002
+	sld	r9, r9, r10
8ae002
+#endif
8ae002
+	cmpdi	cr7, r9, 0
8ae002
+	bne	cr7, L(noload)
8ae002
+	cmpdi	cr7, r10, 0
8ae002
+	beq	cr7, L(continue)
8ae002
+	ld	r7, 8(r7)
8ae002
+L(continue1):
8ae002
+	mr	r12, r10
8ae002
+	addi	r12, r12, -8
8ae002
+	subfic	r11, r12, 64
8ae002
+	b	L(nextbyte)
8ae002
+
8ae002
+	.align	4
8ae002
+L(continue):
8ae002
+	ld	r7, 8(r7)
8ae002
+	li	r12, -8		/* Shift values.  */
8ae002
+	li	r11, 72		/* Shift values.  */
8ae002
+L(nextbyte):
8ae002
+	addi	r12, r12, 8	/* Mask for rotation.  */
8ae002
+	addi	r11, r11, -8
8ae002
+#ifdef __LITTLE_ENDIAN__
8ae002
+	srd	r9, r5, r12
8ae002
+	sld	r10, r7, r11
8ae002
+	or	r10, r9, r10
8ae002
+	sld	r10, r10, r8
8ae002
+	cmpb	r9, r0, r10
8ae002
+	srd	r9, r9, r8
8ae002
+#else
8ae002
+	sld	r9, r5, r12
8ae002
+	srd	r10, r7, r11
8ae002
+	or	r10, r9, r10
8ae002
+	srd	r10, r10, r8
8ae002
+	cmpb	r9, r0, r10
8ae002
+	sld	r9, r9, r8
8ae002
+#endif
8ae002
+	cmpdi	cr7, r9, 0
8ae002
+	bne	cr7, L(retnull)
8ae002
+	cmpb	r9, r10, r6
8ae002
+	cmpdi	cr7, r9, -1
8ae002
+	beq	cr7, L(end)
8ae002
+	addi	r3, r4, 1
8ae002
+	lbz	r4, 0(r30)
8ae002
+	bl	STRCHR
8ae002
+	nop
8ae002
+	/* If first char of search str is not present.  */
8ae002
+	cmpdi	cr7, r3, 0
8ae002
+	ble	cr7, L(end)
8ae002
+	mr	r4, r3
8ae002
+	mr	r6, r29
8ae002
+	li	r0, 0
8ae002
+	b	L(proceed2)
8ae002
+
8ae002
+	.align	4
8ae002
+L(noload):
8ae002
+	/* Reached null in r3, so skip next load.  */
8ae002
+	li 	r7, 0
8ae002
+	b	L(continue1)
8ae002
+
8ae002
+	.align	4
8ae002
+L(return):
8ae002
+	/* Update return values.  */
8ae002
+	srdi	r9, r11, 3
8ae002
+	subf	r3, r9, r3
8ae002
+	b	L(end)
8ae002
+
8ae002
+	/* Handling byte by byte.  */
8ae002
+	.align	4
8ae002
+L(bytebybyte):
8ae002
+	mr	r8, r3
8ae002
+	addi	r8, r8, -1
8ae002
+L(loop1):
8ae002
+	addi	r8, r8, 1
8ae002
+	mr	r3, r8
8ae002
+	mr	r4, r30
8ae002
+	lbz	r6, 0(r4)
8ae002
+	cmpdi	cr7, r6, 0
8ae002
+	beq	cr7, L(updater3)
8ae002
+L(loop):
8ae002
+	lbz	r5, 0(r3)
8ae002
+	cmpdi	cr7, r5, 0
8ae002
+	beq	cr7, L(retnull)
8ae002
+	cmpld	cr7, r6, r5
8ae002
+	bne	cr7, L(loop1)
8ae002
+	addi	r3, r3, 1
8ae002
+	addi	r4, r4, 1
8ae002
+	lbz	r6, 0(r4)
8ae002
+	cmpdi	cr7, r6, 0
8ae002
+	beq	cr7, L(updater3)
8ae002
+	b	L(loop)
8ae002
+
8ae002
+	/* Handling return values.  */
8ae002
+	.align	4
8ae002
+L(updater3):
8ae002
+	subf	r3, r31, r3	/* Reduce len of r4 from r3.  */
8ae002
+	b	L(end)
8ae002
+
8ae002
+	.align	4
8ae002
+L(ret_r3):
8ae002
+	mr	r3, r29		/* Return r3.  */
8ae002
+	b	L(end)
8ae002
+
8ae002
+	.align	4
8ae002
+L(retnull):
8ae002
+	li	r3, 0		/* Return NULL.  */
8ae002
+	b	L(end)
8ae002
+
8ae002
+	.align	4
8ae002
+L(default):
8ae002
+	mr	r3, r29
8ae002
+	mr	r4, r30
8ae002
+	bl	__strstr_ppc
8ae002
+	nop
8ae002
+
8ae002
+	.align	4
8ae002
+L(end):
8ae002
+	addi	r1, r1, FRAMESIZE	/* Restore stack pointer.  */
8ae002
+	cfi_adjust_cfa_offset(-FRAMESIZE)
8ae002
+	ld	r0, 16(r1)	/* Restore the saved link register.  */
8ae002
+	ld	r29, -24(r1)	/* Restore callers save register r29.  */
8ae002
+	ld	r30, -16(r1)	/* Restore callers save register r30.  */
8ae002
+	ld	r31, -8(r1)	/* Restore callers save register r31.  */
8ae002
+	mtlr	r0		/* Branch to link register.  */
8ae002
+	blr
8ae002
+END (strstr)
8ae002
+libc_hidden_builtin_def (strstr)
8ae002
-- 
8ae002
2.1.0
8ae002