PATCH: Add __strend for x86-64
H.J. Lu
hongjiu.lu@intel.com
Thu Jul 2 18:17:00 GMT 2009
Hi,
Here is a patch to add an internal function, __strend, for x86-64.
const char *__strlen(const char *s);
It returns a pointer to the end of S, i.e. to the terminating
null-character. It can be used internally in glibc to implement
other string functions.
H.J.
---
2009-07-02 H.J. Lu <hongjiu.lu@intel.com>
* sysdeps/x86_64/Makefile (sysdep_routines): Add strend for
string.
* sysdeps/x86_64/strlen.S: Don't substract the start of string
if USE_AS_STREND is defined.
* sysdeps/x86_64/strend.S: New.
diff --git a/sysdeps/x86_64/Makefile b/sysdeps/x86_64/Makefile
index da82093..7fb6046 100644
--- a/sysdeps/x86_64/Makefile
+++ b/sysdeps/x86_64/Makefile
@@ -11,7 +11,7 @@ sysdep_routines += _mcount
endif
ifeq ($(subdir),string)
-sysdep_routines += cacheinfo
+sysdep_routines += cacheinfo strend
endif
ifeq ($(subdir),elf)
diff --git a/sysdeps/x86_64/strend.S b/sysdeps/x86_64/strend.S
new file mode 100644
index 0000000..bd9e3a8
--- /dev/null
+++ b/sysdeps/x86_64/strend.S
@@ -0,0 +1,3 @@
+#define strlen __strend
+#define USE_AS_STREND
+#include "strlen.S"
diff --git a/sysdeps/x86_64/strlen.S b/sysdeps/x86_64/strlen.S
index 93aee6b..031dd0e 100644
--- a/sysdeps/x86_64/strlen.S
+++ b/sysdeps/x86_64/strlen.S
@@ -25,7 +25,9 @@
ENTRY(strlen)
pxor %xmm2, %xmm2
movq %rdi, %rcx
+#ifndef USE_AS_STREND
movq %rdi, %r8
+#endif
andq $~15, %rdi
movdqa %xmm2, %xmm1
pcmpeqb (%rdi), %xmm2
@@ -43,9 +45,14 @@ ENTRY(strlen)
testl %edx, %edx
jz 2b
-1: subq %r8, %rdi
+1:
+#ifndef USE_AS_STREND
+ subq %r8, %rdi
+#endif
bsfl %edx, %eax
addq %rdi, %rax
ret
END(strlen)
+#ifndef USE_AS_STREND
libc_hidden_builtin_def (strlen)
+#endif
More information about the Libc-alpha
mailing list