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 01/11] Improve generic strlen


LGTM and just a few nit below.

On 17/12/2016 04:57, Richard Henderson wrote:
> Extract haszero and whichzero tests into headers that can be
> tailored for the architecture.
> 
> 	* sysdeps/generic/haszero.h: New file.
> 	* sysdeps/generic/whichzero.h: New file.
> 	* sysdeps/generic/extractbyte.h: New file.
> 	* string/strlen.c: Use them.
> ---
>  string/strlen.c               | 80 +++++++++----------------------------------
>  sysdeps/generic/extractbyte.h | 34 ++++++++++++++++++
>  sysdeps/generic/haszero.h     | 42 +++++++++++++++++++++++
>  sysdeps/generic/whichzero.h   | 67 ++++++++++++++++++++++++++++++++++++
>  4 files changed, 160 insertions(+), 63 deletions(-)
>  create mode 100644 sysdeps/generic/extractbyte.h
>  create mode 100644 sysdeps/generic/haszero.h
>  create mode 100644 sysdeps/generic/whichzero.h
> 
> diff --git a/string/strlen.c b/string/strlen.c
> index 4943ce2..f2a53a6 100644
> --- a/string/strlen.c
> +++ b/string/strlen.c
> @@ -20,6 +20,9 @@
>  
>  #include <string.h>
>  #include <stdlib.h>
> +#include <stdint.h>
> +#include <haszero.h>
> +#include <whichzero.h>
>  
>  #undef strlen
>  
> @@ -32,78 +35,29 @@
>  size_t
>  STRLEN (const char *str)
>  {
> -  const char *char_ptr;
> +  const char *char_ptr = str;
>    const unsigned long int *longword_ptr;
> -  unsigned long int longword, himagic, lomagic;
> +  unsigned long int longword;
> +  uintptr_t i, align;
>  
>    /* Handle the first few characters by reading one character at a time.
>       Do this until CHAR_PTR is aligned on a longword boundary.  */
> -  for (char_ptr = str; ((unsigned long int) char_ptr
> -			& (sizeof (longword) - 1)) != 0;
> -       ++char_ptr)
> +  align = -(uintptr_t)char_ptr % sizeof(longword);
> +  for (i = 0; i < align; ++i, ++char_ptr)
>      if (*char_ptr == '\0')
> -      return char_ptr - str;
> +      goto found;

Why not just return 'char_ptr - str' and get rid of label?


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