This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH 4/4] Micro-optimize critical path of strstr, strcase andmemmem.


On 5/30/2012 5:13 AM, Maxim Kuvyrkov wrote:
> [PATCH 4/4] Micro-optimize critical path of strstr, strcase and memmem.

You need a NEWS entry for this patch set. Please pat yourself on the back.

> --
> Maxim Kuvyrkov
> CodeSourcery / Mentor Graphics
> 
> 
> 	* string/str-two-way.h (AVAILABLE1_USES_J): New macro, define default.
> 	(two_way_short_needle): Use it.
> 	* string/{strstr.c, strcasestr.c} (AVAILABLE1_USES_J): Define.
> ---
>  string/str-two-way.h |   11 ++++++++++-
>  string/strcasestr.c  |    1 +
>  string/strstr.c      |    1 +
>  3 files changed, 12 insertions(+), 1 deletions(-)
> 
> diff --git a/string/str-two-way.h b/string/str-two-way.h
> index b6e17e4..f1eb7d1 100644
> --- a/string/str-two-way.h
> +++ b/string/str-two-way.h
> @@ -87,6 +87,9 @@
>  #ifndef RET0_IF_0
>  # define RET0_IF_0(a) /* nothing */
>  #endif
> +#ifndef AVAILABLE1_USES_J
> +# define AVAILABLE1_USES_J (1)
> +#endif
>  
>  /* Perform a critical factorization of NEEDLE, of length NEEDLE_LEN.
>     Return the index of the first byte in the right half, and set
> @@ -298,12 +301,17 @@ two_way_short_needle (const unsigned char *haystack, size_t haystack_len,
>  	      != (a = CANON_ELEMENT (*phaystack++)))
>  	    {
>  	      RET0_IF_0 (a);
> +#if AVAILABLE1_USES_J
>  	      ++j;
> +#endif
>  	      continue;
>  	    }
>  
> -	  /* Calculate J.  */
> +#if !AVAILABLE1_USES_J
> +	  /* Calculate J if it wasn't kept up-to-date in the first-character
> +	     loop.  */
>  	  j = phaystack - &haystack[suffix] - 1;
> +#endif
>  
>  	  /* Scan for matches in right half.  */
>  	  i = suffix + 1;
> @@ -500,6 +508,7 @@ two_way_long_needle (const unsigned char *haystack, size_t haystack_len,
>  #undef AVAILABLE
>  #undef AVAILABLE1
>  #undef AVAILABLE2
> +#undef AVAILABLE1_USES_J
>  #undef CANON_ELEMENT
>  #undef CMP_FUNC
>  #undef RET0_IF_0
> diff --git a/string/strcasestr.c b/string/strcasestr.c
> index b6458ae..9467b7a 100644
> --- a/string/strcasestr.c
> +++ b/string/strcasestr.c
> @@ -46,6 +46,7 @@
>  #define AVAILABLE1(h, h_l, j, n_l) (true)
>  #define AVAILABLE2(h, h_l, j, n_l) AVAILABLE (h, h_l, j, n_l)
>  #define RET0_IF_0(a) if (!a) goto ret0
> +#define AVAILABLE1_USES_J (0)
>  #define CANON_ELEMENT(c) TOLOWER (c)
>  #define CMP_FUNC(p1, p2, l)				\
>    __strncasecmp ((const char *) (p1), (const char *) (p2), l)
> diff --git a/string/strstr.c b/string/strstr.c
> index ec2a1e9..cfed771 100644
> --- a/string/strstr.c
> +++ b/string/strstr.c
> @@ -38,6 +38,7 @@
>  #define AVAILABLE1(h, h_l, j, n_l) (true)
>  #define AVAILABLE2(h, h_l, j, n_l) AVAILABLE (h, h_l, j, n_l)
>  #define RET0_IF_0(a) if (!a) goto ret0
> +#define AVAILABLE1_USES_J (0)
>  #include "str-two-way.h"
>  
>  #undef strstr
> 

OK as is.

Cheers,
Carlos.
-- 
Carlos O'Donell
Mentor Graphics / CodeSourcery
carlos_odonell@mentor.com
carlos@codesourcery.com
+1 (613) 963 1026


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]