This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[PATCH] Do not transform strchr into rawmemchr
- From: Wilco Dijkstra <Wilco dot Dijkstra at arm dot com>
- To: "libc-alpha at sourceware dot org" <libc-alpha at sourceware dot org>
- Cc: nd <nd at arm dot com>
- Date: Wed, 16 Nov 2016 18:59:36 +0000
- Subject: [PATCH] Do not transform strchr into rawmemchr
- Authentication-results: sourceware.org; auth=none
- Authentication-results: spf=none (sender IP is ) smtp.mailfrom=Wilco dot Dijkstra at arm dot com;
- Nodisclaimer: True
- References: <AM5PR0802MB26102CD0C9B41C82C3CF58A483BE0@AM5PR0802MB2610.eurprd08.prod.outlook.com>
- Spamdiagnosticmetadata: NSPM
- Spamdiagnosticoutput: 1:99
GLIBC uses strchr (s, '\0') as an idiom to find the end of a string.
This is transformed into rawmemchr by the bits/string2.h header.
However this is generally slower than strlen on most targets, even when
an optimized rawmemchr implementation exists. Since GCC7 optimizes
strchr (s, '\0') to strlen (s) + s, the GLIBC headers should not
transform this to rawmemchr.
GLIBC tests pass, OK for commit?
ChangeLog:
2015-11-16 Wilco Dijkstra <wdijkstr@arm.com>
* string/bits/string2.h (strchr): Use __builtin_strchr.
--
diff --git a/string/bits/string2.h b/string/bits/string2.h
index 80987602f34ded483854bcea86dabd5b81e42a18..f0e2ce9cd87033698236e7878c63a2e5f9bb1887 100644
--- a/string/bits/string2.h
+++ b/string/bits/string2.h
@@ -59,12 +59,7 @@
#ifndef _HAVE_STRING_ARCH_strchr
-extern void *__rawmemchr (const void *__s, int __c);
-# define strchr(s, c) \
- (__extension__ (__builtin_constant_p (c) && !__builtin_constant_p (s) \
- && (c) == '\0' \
- ? (char *) __rawmemchr (s, c) \
- : __builtin_strchr (s, c)))
+# define strchr(s, c) __builtin_strchr (s, c)
#endif