This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH]: Use RAX_LP/RDX_LP on SAVE_PTR in sysdeps/x86_64/strtok.S


Hi,

This patch uses RAX_LP/RDX_LP on SAVE_PTR in sysdeps/x86_64/strtok.S to
access pointers.  Also there is no need to update rax twice in:

        movq %rdx, %rax
        movq %rdx, %r9          /* Save value - see def. of SAVE_PTR.  */
        movq (%rax), %rax

We can just do

        movq %rdx, %r9          /* Save value - see def. of SAVE_PTR.  */
        movq (%r9), %rax

I need to use -O1 on tst-strtok_r.c.  Otherwise, it won't fail with
broken strtok.S.  Tested on Linux/x32 and Linux/x86-64. OK to install?

Thanks.

H.J.
---
	[BZ #14229]
	* string/Makefile (tests): Add tst-strtok_r.
	* string/tst-strtok_r.c: New file.
	* sysdeps/x86_64/strtok.S: Use RAX_LP/RDX_LP on SAVE_PTR.

diff --git a/string/Makefile b/string/Makefile
index 80923a2..5942978 100644
--- a/string/Makefile
+++ b/string/Makefile
@@ -56,7 +56,7 @@ tests		:= tester inl-tester noinl-tester testcopy test-ffs	\
 		   tst-strtok tst-strxfrm bug-strcoll1 tst-strfry	\
 		   bug-strtok1 $(addprefix test-,$(strop-tests))	\
 		   bug-envz1 tst-strxfrm2 tst-endian tst-svc2		\
-		   bug-strstr1 bug-strchr1
+		   bug-strstr1 bug-strchr1 tst-strtok_r
 
 
 include ../Rules
@@ -74,6 +74,7 @@ CFLAGS-stratcliff.c = -fno-builtin
 CFLAGS-test-ffs.c = -fno-builtin
 CFLAGS-tst-inlcall.c = -fno-builtin
 CFLAGS-bug-strstr1.c = -fno-builtin
+CFLAGS-tst-strtok_r.c = -O1 -fno-inline -fno-builtin
 
 ifeq ($(cross-compiling),no)
 tests: $(objpfx)tst-svc.out
diff --git a/string/tst-strtok_r.c b/string/tst-strtok_r.c
new file mode 100644
index 0000000..f404f1b
--- /dev/null
+++ b/string/tst-strtok_r.c
@@ -0,0 +1,11 @@
+#include <stdlib.h>
+#include <string.h>
+
+int main()
+{
+  char line[] = "udf 75868 1 - Live 0xffffffffa0bfb000\n";
+  char *saveptr, *tok = strtok_r(line, " \t", &saveptr);
+  if (strcmp (tok, "udf") != 0)
+    abort ();
+  return 0;
+}
diff --git a/sysdeps/x86_64/strtok.S b/sysdeps/x86_64/strtok.S
index 150f4d6..f5f19a7 100644
--- a/sysdeps/x86_64/strtok.S
+++ b/sysdeps/x86_64/strtok.S
@@ -1,6 +1,6 @@
 /* strtok (str, delim) -- Return next DELIM separated token from STR.
    For AMD x86-64.
-   Copyright (C) 1998,2000-2003,2005,2006 Free Software Foundation, Inc.
+   Copyright (C) 1998-2012 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Based on i686 version contributed by Ulrich Drepper
    <drepper@cygnus.com>, 1998.
@@ -79,13 +79,12 @@ ENTRY (BP_SYM (FUNCTION))
 
 #ifdef USE_AS_STRTOK_R
 	/* The value is stored in the third argument.  */
-	movq %rdx, %rax
 	movq %rdx, %r9		/* Save value - see def. of SAVE_PTR.  */
-	movq (%rax), %rax
+	mov (%r9), %RAX_LP
 #else
 	/* The value is in the local variable defined above.  But
 	   we have to take care for PIC code.  */
-	movq SAVE_PTR, %rax
+	mov SAVE_PTR, %RAX_LP
 #endif
 	movq %r8, %rdx		/* Get start of string.  */
 
@@ -194,7 +193,7 @@ L(8):	cmpq %rax, %rdx
 	cmovne %rcx, %rdx
 
 	/* Store the pointer to the next character.  */
-	movq %rdx, SAVE_PTR
+	mov %RDX_LP, SAVE_PTR
 
 L(epilogue):
 	/* Remove the stopset table.  */
@@ -205,7 +204,7 @@ L(epilogue):
 L(returnNULL):
 	xorl %eax, %eax
 	/* Store the pointer to the next character.  */
-	movq %rdx, SAVE_PTR
+	mov %RDX_LP, SAVE_PTR
 	jmp L(epilogue)
 
 END (BP_SYM (FUNCTION))


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]