summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libc/string/generic/strchr.c23
-rw-r--r--libc/string/generic/strchrnul.c23
2 files changed, 20 insertions, 26 deletions
diff --git a/libc/string/generic/strchr.c b/libc/string/generic/strchr.c
index 321d2b8c3..b34884d67 100644
--- a/libc/string/generic/strchr.c
+++ b/libc/string/generic/strchr.c
@@ -60,22 +60,19 @@ char *strchr (const char *s, int c_in)
The 1-bits make sure that carries propagate to the next 0-bit.
The 0-bits provide holes for carries to fall into. */
- switch (sizeof (longword))
- {
- case 4: magic_bits = 0x7efefeffL; break;
- case 8: magic_bits = ((0x7efefefeL << 16) << 16) | 0xfefefeffL; break;
- default:
- abort ();
- }
-
/* Set up a longword, each of whose bytes is C. */
+#if __WORDSIZE == 32
+ magic_bits = 0x7efefeffL;
charmask = c | (c << 8);
charmask |= charmask << 16;
- if (sizeof (longword) > 4)
- /* Do the shift in two steps to avoid a warning if long has 32 bits. */
- charmask |= (charmask << 16) << 16;
- if (sizeof (longword) > 8)
- abort ();
+#elif __WORDSIZE == 64
+ magic_bits = ((0x7efefefeL << 16) << 16) | 0xfefefeffL;
+ charmask = c | (c << 8);
+ charmask |= charmask << 16;
+ charmask |= (charmask << 16) << 16;
+#else
+ #error unexpected integer size strchr()
+#endif
/* Instead of the traditional loop which tests each character,
we will test a longword at a time. The tricky part is testing
diff --git a/libc/string/generic/strchrnul.c b/libc/string/generic/strchrnul.c
index d11d9e00d..d9fadc776 100644
--- a/libc/string/generic/strchrnul.c
+++ b/libc/string/generic/strchrnul.c
@@ -59,22 +59,19 @@ char *strchrnul (const char *s, int c_in)
The 1-bits make sure that carries propagate to the next 0-bit.
The 0-bits provide holes for carries to fall into. */
- switch (sizeof (longword))
- {
- case 4: magic_bits = 0x7efefeffL; break;
- case 8: magic_bits = ((0x7efefefeL << 16) << 16) | 0xfefefeffL; break;
- default:
- abort ();
- }
- /* Set up a longword, each of whose bytes is C. */
+#if __WORDSIZE == 32
+ magic_bits = 0x7efefeffL;
charmask = c | (c << 8);
charmask |= charmask << 16;
- if (sizeof (longword) > 4)
- /* Do the shift in two steps to avoid a warning if long has 32 bits. */
- charmask |= (charmask << 16) << 16;
- if (sizeof (longword) > 8)
- abort ();
+#elif __WORDSIZE == 64
+ magic_bits = ((0x7efefefeL << 16) << 16) | 0xfefefeffL;
+ charmask = c | (c << 8);
+ charmask |= charmask << 16;
+ charmask |= (charmask << 16) << 16;
+#else
+ #error unexpected integer size strchr()
+#endif
/* Instead of the traditional loop which tests each character,
we will test a longword at a time. The tricky part is testing