Skip to content

Comments

Optional SIMD memrchr#598

Merged
abrown merged 1 commit intoWebAssembly:mainfrom
ncruces:simd
Aug 14, 2025
Merged

Optional SIMD memrchr#598
abrown merged 1 commit intoWebAssembly:mainfrom
ncruces:simd

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