This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH] Do not transform strchr into rawmemchr
- From: Zack Weinberg <zackw at panix dot com>
- To: Wilco Dijkstra <Wilco dot Dijkstra at arm dot com>
- Cc: "libc-alpha at sourceware dot org" <libc-alpha at sourceware dot org>, nd <nd at arm dot com>
- Date: Wed, 16 Nov 2016 14:02:15 -0500
- Subject: Re: [PATCH] Do not transform strchr into rawmemchr
- Authentication-results: sourceware.org; auth=none
- References: <AM5PR0802MB26102CD0C9B41C82C3CF58A483BE0@AM5PR0802MB2610.eurprd08.prod.outlook.com> <AM5PR0802MB26101582FEA5EBF10B7CE8F583BE0@AM5PR0802MB2610.eurprd08.prod.outlook.com>
On Wed, Nov 16, 2016 at 1:59 PM, Wilco Dijkstra <Wilco.Dijkstra@arm.com> wrote:
> 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.
I endorse the removal of the non-optimization, but ...
> #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
... wouldn't it be just as effective to remove this block entirely?
That is, don't #define strchr at all.
zw