[v2] Do not transform strchr into rawmemchr

Message ID AM5PR0802MB26104A3FF89354B0E9A7555B83450@AM5PR0802MB2610.eurprd08.prod.outlook.com
State Committed
Headers

Commit Message

Wilco Dijkstra Feb. 9, 2017, 3:28 p.m. UTC
  ping



From: Wilco Dijkstra
Sent: 23 November 2016 17:19
To: libc-alpha@sourceware.org
Cc: nd
Subject: [PATCH v2] Do not transform strchr into rawmemchr
    
Version 2 of the patch removes the strchr define completely as
suggested:

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.  As GCC recognizes strchr as a builtin,
defining strchr as the builtin is not useful.

Regress passes, OK for commit?

ChangeLog:
2015-11-23  Wilco Dijkstra  <wdijkstr@arm.com>

        * string/bits/string2.h (strchr): Remove define.
--
  

Comments

Adhemerval Zanella Netto Feb. 10, 2017, 1:33 p.m. UTC | #1
LGTM.

On 09/02/2017 13:28, Wilco Dijkstra wrote:
> ping
> 
> 
> 
> From: Wilco Dijkstra
> Sent: 23 November 2016 17:19
> To: libc-alpha@sourceware.org
> Cc: nd
> Subject: [PATCH v2] Do not transform strchr into rawmemchr
>     
> Version 2 of the patch removes the strchr define completely as
> suggested:
> 
> 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.  As GCC recognizes strchr as a builtin,
> defining strchr as the builtin is not useful.
> 
> Regress passes, OK for commit?
> 
> ChangeLog:
> 2015-11-23  Wilco Dijkstra  <wdijkstr@arm.com>
> 
>         * string/bits/string2.h (strchr): Remove define.
> --
> diff --git a/string/bits/string2.h b/string/bits/string2.h
> index e39d4f1a85c25a4f47418e6a5613b27177ca6cbb..de426b47cae09933b2dc53e0956d63b4c93aebc0 100644
> --- a/string/bits/string2.h
> +++ b/string/bits/string2.h
> @@ -58,16 +58,6 @@
>  #endif
>  
>  
> -#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)))
> -#endif
> -
> -
>  /* Copy SRC to DEST, returning pointer to final NUL byte.  */
>  #ifdef __USE_GNU
>  # ifndef _HAVE_STRING_ARCH_stpcpy
> 
> 
>     
>
  

Patch

diff --git a/string/bits/string2.h b/string/bits/string2.h
index e39d4f1a85c25a4f47418e6a5613b27177ca6cbb..de426b47cae09933b2dc53e0956d63b4c93aebc0 100644
--- a/string/bits/string2.h
+++ b/string/bits/string2.h
@@ -58,16 +58,6 @@ 
 #endif
 
 
-#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)))
-#endif
-
-
 /* Copy SRC to DEST, returning pointer to final NUL byte.  */
 #ifdef __USE_GNU
 # ifndef _HAVE_STRING_ARCH_stpcpy