[PATCH 05/11] Improve generic strrchr

Adhemerval Zanella adhemerval.zanella@linaro.org
Tue Dec 20 21:01:00 GMT 2016



On 20/12/2016 15:20, Richard Henderson wrote:
> On 12/20/2016 04:50 AM, Adhemerval Zanella wrote:
>> /* Find the last occurrence of C in S.  */
>> char *
>> STRRCHR (const char *s, int int_c)
>> {
>>   return __memrchr (s, int_c, strlen (s) + 1);
>> }
> 
> Do we really want to touch the memory twice for such a common function?

It really depends of the pattern strrchr is usually issue with.  If last
occurrence is near end of string it can be potentially faster, however
if it is not the case it can potentially touch memory twice indeed.
Using current benchtest I am seeing exactly this:

  - first two loops where string size way larger than character position
    the simplified implementation is slower (about 60% in some cases);

  - third loop show some gains from size 2 and larger (about 15%)

  - it shows also some gain on 4th loop and forward where is acts 
    basically as strlen (since it searches for 0).



More information about the Libc-alpha mailing list