diff options
author | Alexey Lapshin <alexey.lapshin@espressif.com> | 2025-02-10 13:01:45 +0000 |
---|---|---|
committer | Corinna Vinschen <corinna@vinschen.de> | 2025-02-10 15:20:47 +0100 |
commit | c9b74e32892966c8f66280c752181292bc95f690 (patch) | |
tree | c5e4e6cc1a40ce394b2ec22d3028cfdb7a8c4f97 /newlib/libc/string/strchr.c | |
parent | 0d113da2350a4bdae5227c5cc88585d5b20d6065 (diff) | |
download | newlib-c9b74e32892966c8f66280c752181292bc95f690.zip newlib-c9b74e32892966c8f66280c752181292bc95f690.tar.gz newlib-c9b74e32892966c8f66280c752181292bc95f690.tar.bz2 |
newlib: string: refactor str/mem-family functions
Move common macros to local.h header
Diffstat (limited to 'newlib/libc/string/strchr.c')
-rw-r--r-- | newlib/libc/string/strchr.c | 32 |
1 files changed, 6 insertions, 26 deletions
diff --git a/newlib/libc/string/strchr.c b/newlib/libc/string/strchr.c index 96f30be..cfbff9b 100644 --- a/newlib/libc/string/strchr.c +++ b/newlib/libc/string/strchr.c @@ -29,27 +29,7 @@ QUICKREF #include <string.h> #include <limits.h> - -/* Nonzero if X is not aligned on a "long" boundary. */ -#define UNALIGNED(X) ((long)X & (sizeof (long) - 1)) - -/* How many bytes are loaded each iteration of the word copy loop. */ -#define LBLOCKSIZE (sizeof (long)) - -#if LONG_MAX == 2147483647L -#define DETECTNULL(X) (((X) - 0x01010101) & ~(X) & 0x80808080) -#else -#if LONG_MAX == 9223372036854775807L -/* Nonzero if X (a long int) contains a NULL byte. */ -#define DETECTNULL(X) (((X) - 0x0101010101010101) & ~(X) & 0x8080808080808080) -#else -#error long int is not a 32bit or 64bit type. -#endif -#endif - -/* DETECTCHAR returns nonzero if (long)X contains the byte used - to fill (long)MASK. */ -#define DETECTCHAR(X,MASK) (DETECTNULL(X ^ MASK)) +#include "local.h" char * strchr (const char *s1, @@ -65,7 +45,7 @@ strchr (const char *s1, /* Special case for finding 0. */ if (!c) { - while (UNALIGNED (s)) + while (UNALIGNED_X(s)) { if (!*s) return (char *) s; @@ -73,7 +53,7 @@ strchr (const char *s1, } /* Operate a word at a time. */ aligned_addr = (unsigned long *) s; - while (!DETECTNULL (*aligned_addr)) + while (!DETECT_NULL(*aligned_addr)) aligned_addr++; /* Found the end of string. */ s = (const unsigned char *) aligned_addr; @@ -83,7 +63,7 @@ strchr (const char *s1, } /* All other bytes. Align the pointer, then search a long at a time. */ - while (UNALIGNED (s)) + while (UNALIGNED_X(s)) { if (!*s) return NULL; @@ -93,11 +73,11 @@ strchr (const char *s1, } mask = c; - for (j = 8; j < LBLOCKSIZE * 8; j <<= 1) + for (j = 8; j < sizeof(mask) * 8; j <<= 1) mask = (mask << j) | mask; aligned_addr = (unsigned long *) s; - while (!DETECTNULL (*aligned_addr) && !DETECTCHAR (*aligned_addr, mask)) + while (!DETECT_NULL(*aligned_addr) && !DETECT_CHAR(*aligned_addr, mask)) aligned_addr++; /* The block of bytes currently pointed to by aligned_addr |