This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Gcc builtin review: memchr, memrchr, rawmemchr
- From: OndÅej BÃlka <neleai at seznam dot cz>
- To: libc-alpha at sourceware dot org
- Cc: Andrew Pinski <pinskia at gmail dot com>
- Date: Mon, 25 May 2015 12:55:40 +0200
- Subject: Gcc builtin review: memchr, memrchr, rawmemchr
- Authentication-results: sourceware.org; auth=none
- References: <20150525101505 dot GA11233 at domone> <20150525103839 dot GB11233 at domone>
Gcc doesn't do any optimizations with these but misses several.
I already submitted that rawmemchr (s, 0) is silly, you should use
s + strlen (s) as strlen is better optimized (AFAIR around 50% faster
than rawmemchr)
Then gcc also doesn't optimize memchr with n small constant which is
possible but bit obscure. I could get similar performance improvement as
strcmp question is if its worth mainatainence. But fell free to add gcc
optimization for that.
Another use case is how wordexp abuses strchr/memchr to test membership
in set. For example it checked whitespace with
if (strchr (" \t\r\n", c))
While this would be relatively easy to implement with header and would
be candidate for ufunc calculating table in gcc would be really ugly
hack.