arrfab / rpms / glibc

Forked from rpms/glibc 4 years ago
Clone

Blame SOURCES/glibc-rh1385004-4.patch

147e83
From 561857f53a543684862c2b6d2308bc13affa2a18 Mon Sep 17 00:00:00 2001
147e83
From: Rajalakshmi Srinivasaraghavan <raji@linux.vnet.ibm.com>
147e83
Date: Tue, 18 Aug 2015 22:40:56 +0530
147e83
Subject: [PATCH] powerpc: Handle worstcase behavior in strstr() for POWER7
147e83
147e83
Instead of checking needle length, constant 'n' number of comparisons
147e83
is checked to fall back to default implementation.  This patch is tested
147e83
on powerpc64 and powerpc64le.
147e83
147e83
2015-08-25  Rajalakshmi Srinivasaraghavan  <raji@linux.vnet.ibm.com>
147e83
147e83
	* sysdeps/powerpc/powerpc64/power7/strstr.S: Handle worst case.
147e83
147e83
(cherry picked from commit fe7faec3e56a8dd64f78023a2f4a74fc8d42e79f)
147e83
---
147e83
 ChangeLog                                 |  4 ++++
147e83
 sysdeps/powerpc/powerpc64/power7/strstr.S | 22 +++++++++++++++-------
147e83
 2 files changed, 19 insertions(+), 7 deletions(-)
147e83
147e83
diff --git a/ChangeLog b/ChangeLog
147e83
index cf95a84..5cbd6d6 100644
147e83
diff --git a/sysdeps/powerpc/powerpc64/power7/strstr.S b/sysdeps/powerpc/powerpc64/power7/strstr.S
147e83
index bfb0c49..fb3c810 100644
147e83
--- a/sysdeps/powerpc/powerpc64/power7/strstr.S
147e83
+++ b/sysdeps/powerpc/powerpc64/power7/strstr.S
147e83
@@ -23,6 +23,8 @@
147e83
 /* The performance gain is obtained using aligned memory access, load
147e83
  * doubleword and usage of cmpb instruction for quicker comparison.  */
147e83
 
147e83
+#define ITERATIONS	64
147e83
+
147e83
 #ifndef STRLEN
147e83
 /* For builds with no IFUNC support, local calls should be made to internal
147e83
    GLIBC symbol (created by libc_hidden_builtin_def).  */
147e83
@@ -62,6 +64,8 @@ EALIGN (strstr, 4, 0)
147e83
 	cfi_offset(r30, -16)
147e83
 	std	r29, -24(r1)		/* Save callers register r29.  */
147e83
 	cfi_offset(r29, -24)
147e83
+	std	r28, -32(r1)		/* Save callers register r28.  */
147e83
+	cfi_offset(r28, -32)
147e83
 	std	r0, 16(r1)		/* Store the link register.  */
147e83
 	cfi_offset(lr, 16)
147e83
 	stdu	r1, -FRAMESIZE(r1)	/* Create the stack frame.  */
147e83
@@ -69,7 +73,6 @@ EALIGN (strstr, 4, 0)
147e83
 
147e83
 	dcbt	0, r3
147e83
 	dcbt	0, r4
147e83
-
147e83
 	cmpdi	cr7, r3, 0
147e83
 	beq	cr7, L(retnull)
147e83
 	cmpdi	cr7, r4, 0
147e83
@@ -84,10 +87,6 @@ EALIGN (strstr, 4, 0)
147e83
 	cmpdi	cr7, r3, 0	/* If search str is null.  */
147e83
 	beq	cr7, L(ret_r3)
147e83
 
147e83
-	/* Call __strstr_ppc if needle len > 2048 */
147e83
-	cmpdi	cr7, r3, 2048
147e83
-	bgt	cr7, L(default)
147e83
-
147e83
 	mr	r31, r3
147e83
 	mr	r4, r3
147e83
 	mr	r3, r29
147e83
@@ -105,7 +104,8 @@ EALIGN (strstr, 4, 0)
147e83
 	/* If first char of search str is not present.  */
147e83
 	cmpdi	cr7, r3, 0
147e83
 	ble	cr7, L(end)
147e83
-
147e83
+	/* Reg r28 is used to count the number of iterations. */
147e83
+	li	r28, 0
147e83
 	rldicl	r8, r3, 0, 52	/* Page cross check.  */
147e83
 	cmpldi	cr7, r8, 4096-16
147e83
 	bgt	cr7, L(bytebybyte)
147e83
@@ -324,6 +324,10 @@ L(return4):
147e83
 	.align	4
147e83
 L(begin):
147e83
 	mr	r3, r8
147e83
+	/* When our iterations exceed ITERATIONS,fall back to default. */
147e83
+	addi	r28, r28, 1
147e83
+	cmpdi	cr7, r28, ITERATIONS
147e83
+	beq	cr7, L(default)
147e83
 	lbz	r4, 0(r30)
147e83
 	bl	STRCHR
147e83
 	nop
147e83
@@ -423,6 +427,10 @@ L(nextbyte):
147e83
 	cmpdi	cr7, r9, -1
147e83
 	beq	cr7, L(end)
147e83
 	addi	r3, r4, 1
147e83
+	/* When our iterations exceed ITERATIONS,fall back to default. */
147e83
+	addi	r28, r28, 1
147e83
+	cmpdi	cr7, r28, ITERATIONS
147e83
+	beq	cr7, L(default)
147e83
 	lbz	r4, 0(r30)
147e83
 	bl	STRCHR
147e83
 	nop
147e83
@@ -490,7 +498,6 @@ L(retnull):
147e83
 
147e83
 	.align	4
147e83
 L(default):
147e83
-	mr	r3, r29
147e83
 	mr	r4, r30
147e83
 	bl	__strstr_ppc
147e83
 	nop
147e83
@@ -500,6 +507,7 @@ 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	r28, -32(r1)	/* Restore callers save register r28.  */
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
-- 
147e83
2.1.0
147e83