summary refs log tree commit diff
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2009-06-16 10:23:31 -0700
committerPetr Baudis <pasky@suse.cz>2009-06-18 00:27:59 +0200
commitd0f6ed789f460357fca11f8ffcffcb968d8d7434 (patch)
tree330532a8d20e02cdb31c029eea4677fce16c6970
parent626b1576643ecb869c1a685a7dc59e5df09bbf1d (diff)
downloadglibc-d0f6ed789f460357fca11f8ffcffcb968d8d7434.tar.gz
glibc-d0f6ed789f460357fca11f8ffcffcb968d8d7434.tar.xz
glibc-d0f6ed789f460357fca11f8ffcffcb968d8d7434.zip
Fix x86-64 memchr for large lengths.
(cherry picked from commit fab8238de69de67637d21923b3ec1c26e4ce8450)
-rw-r--r--ChangeLog7
-rw-r--r--string/test-memchr.c9
-rw-r--r--sysdeps/x86_64/memchr.S6
3 files changed, 17 insertions, 5 deletions
diff --git a/ChangeLog b/ChangeLog
index 7b39200b02..b3808c50b1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2009-06-16  Jakub Jelinek  <jakub@redhat.com>
+
+	* sysdeps/x86_64/memchr.S (memchr): Use unsigned instead of signed
+	comparisons.
+	* string/test-memchr.c (do_random_tests): Test very large lengths
+	as well.
+
 2009-04-22  Ryan S. Arnold  <rsa@us.ibm.com>
 
 	[BZ #10107]
diff --git a/string/test-memchr.c b/string/test-memchr.c
index c233ead5dd..cd9a01e3da 100644
--- a/string/test-memchr.c
+++ b/string/test-memchr.c
@@ -1,5 +1,5 @@
 /* Test and measure memchr functions.
-   Copyright (C) 1999, 2002, 2003, 2005 Free Software Foundation, Inc.
+   Copyright (C) 1999, 2002, 2003, 2005, 2009 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Written by Jakub Jelinek <jakub@redhat.com>, 1999.
 
@@ -144,7 +144,12 @@ do_random_tests (void)
 	}
 
       if (pos < len)
-	result = (char *) (p + pos + align);
+	{
+	  size_t r = random ();
+	  if ((r & 31) == 0)
+	    len = ~(uintptr_t) (p + align) - ((r >> 5) & 31);
+	  result = (char *) (p + pos + align);
+	}
       else
 	result = NULL;
 
diff --git a/sysdeps/x86_64/memchr.S b/sysdeps/x86_64/memchr.S
index 54b7af534c..6082aa7f76 100644
--- a/sysdeps/x86_64/memchr.S
+++ b/sysdeps/x86_64/memchr.S
@@ -41,7 +41,7 @@ ENTRY (memchr)
 	movl	$16, %esi
 	jnz	1f
 	cmpq	%rsi, %rdx
-	jle	3f
+	jbe	3f
 
 2:	movdqa	(%rdi,%rsi), %xmm0
 	leaq	16(%rsi), %rsi
@@ -50,7 +50,7 @@ ENTRY (memchr)
 	testl	%ecx, %ecx
 	jnz	1f
 	cmpq	%rsi, %rdx
-	jg	2b
+	ja	2b
 
 3:	xorl	%eax, %eax
 	ret
@@ -60,7 +60,7 @@ ENTRY (memchr)
 	addq	%rcx, %rax
 	leaq	-16(%rsi,%rcx), %rsi
 	cmpq	%rsi, %rdx
-	jle	3b
+	jbe	3b
 	ret
 END (memchr)