Skip to content

Optional SIMD memrchr #598

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 14, 2025
Merged

Optional SIMD memrchr #598

merged 1 commit into from
Aug 14, 2025

Conversation

ncruces
Copy link
Contributor

@ncruces ncruces commented Jul 18, 2025

Continuing #580. memrchr is mostly used to implement strrchr, so that's what I test.

It has the advantage that we know the length and can access the entire buffer, so no undefined behavior for this one. I does do unaligned reads, however, so wasm_v128_load is used to dereference the pointer. It uses SIMD while there are 16 or more bytes to read, then fallback to scalar.

The only other notable feature is using clz rather than ctz.

Copy link
Collaborator

@abrown abrown left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I've been fuzzing this, comparing output of the scalar and SIMD versions, and things seem to check out. I'll also note that just enabling __wasm_simd128__ (without this logic) seemed to do some amount of vectorization — something to compare against later.

@abrown abrown merged commit c1b54ea into WebAssembly:main Aug 14, 2025
17 checks passed
@ncruces ncruces deleted the simd branch August 17, 2025 21:32
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