| 1 |
#if !defined(__wasm_simd128__) || !defined(__wasilibc_simd_string) || \ |
| 2 |
__clang_major__ == 19 || __clang_major__ == 20 |
| 3 |
// The SIMD implementation is in strspn_simd.c |
| 4 |
|
| 5 |
#include <string.h> |
| 6 |
|
| 7 |
#define BITOP(a,b,op) \ |
| 8 |
((a)[(size_t)(b)/(8*sizeof *(a))] op (size_t)1<<((size_t)(b)%(8*sizeof *(a)))) |
| 9 |
|
| 10 |
size_t strcspn(const char *s, const char *c) |
| 11 |
{ |
| 12 |
const char *a = s; |
| 13 |
size_t byteset[32/sizeof(size_t)]; |
| 14 |
|
| 15 |
if (!c[0] || !c[1]) return __strchrnul(s, *c)-a; |
| 16 |
|
| 17 |
memset(byteset, 0, sizeof byteset); |
| 18 |
for (; *c && BITOP(byteset, *(unsigned char *)c, |=); c++); |
| 19 |
for (; *s && !BITOP(byteset, *(unsigned char *)s, &); s++); |
| 20 |
return s-a; |
| 21 |
} |
| 22 |
|
| 23 |
#endif |