about summary refs log tree commit diff
path: root/sysdeps/powerpc/powerpc32/power7/memchr.S
diff options
context:
space:
mode:
Diffstat (limited to 'sysdeps/powerpc/powerpc32/power7/memchr.S')
-rw-r--r--sysdeps/powerpc/powerpc32/power7/memchr.S11
1 files changed, 10 insertions, 1 deletions
diff --git a/sysdeps/powerpc/powerpc32/power7/memchr.S b/sysdeps/powerpc/powerpc32/power7/memchr.S
index 318168b4cf..5ce2bb0bad 100644
--- a/sysdeps/powerpc/powerpc32/power7/memchr.S
+++ b/sysdeps/powerpc/powerpc32/power7/memchr.S
@@ -26,7 +26,16 @@ ENTRY (__memchr)
 	dcbt	0,r3
 	clrrwi  r8,r3,2
 	insrwi	r4,r4,8,16    /* Replicate byte to word.  */
-	add	r7,r3,r5      /* Calculate the last acceptable address.  */
+
+	/* Calculate the last acceptable address and check for possible
+	   addition overflow by using satured math:
+	   r7 = r3 + r5
+	   r7 |= -(r7 < x)  */
+	add     r7,r3,r5
+	subfc   r6,r3,r7
+	subfe   r9,r9,r9
+	or      r7,r7,r9
+
 	insrwi	r4,r4,16,0
 	cmplwi	r5,16
 	li	r9, -1