Skip to content

Comments

Optional SIMD strchrnul#594

Merged
abrown merged 2 commits intoWebAssembly:mainfrom
ncruces:simd
Jul 17, 2025
Merged

Optional SIMD strchrnul#594
abrown merged 2 commits intoWebAssembly:mainfrom
ncruces:simd

Conversation

@ncruces
Copy link
Contributor

@ncruces ncruces commented Jul 11, 2025

Continuing #580. strchrnul is used by strchr, strcspn and many other places in libc. The implementation is a matchup between strlen and memchr.

@ncruces
Copy link
Contributor Author

ncruces commented Jul 15, 2025

The test for memchr needed a fix: the unsigned to signed pos < length + 2 comparison meant that, depending on compile flags, the inner loop might not run.

@ncruces ncruces mentioned this pull request Jul 17, 2025
@abrown abrown merged commit 4525255 into WebAssembly:main Jul 17, 2025
17 checks passed
abrown pushed a commit that referenced this pull request Dec 11, 2025
Continuing #580, implements `strspn` and `strcspn`.

This one follows the same general structure as #586, #592 and #594, but
uses a somewhat more complicated algorithm, described
[here](http://0x80.pl/notesen/2018-10-18-simd-byte-lookup.html).

I used the Geoff Langdale alternative implementation (the tweet as since
disappeared) which is correctly described there but has a subtle bug in
the implementation:
WojciechMula/simd-byte-lookup#2

Since the complexity needed for `__wasm_v128_bitmap256_t` is shared for
both `strspn` and `strcspn`, I moved the implementation to a common
file, when SIMD is used.

The tests follow a similar structure as the previous ones, and cover the
bug, which I was found through fuzzing.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants