Skip to content
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

WASM: Intrinsify numberOfLeadingZeros, numberOfTrailingZeros, and bitCount #978

Merged
merged 4 commits into from
Dec 3, 2024

Conversation

lax1dude
Copy link
Contributor

I implemented intrinsic functions for numberOfLeadingZeros, numberOfTrailingZeros, and bitCount using the clz, ctz, and popcnt instructions in the WASM and WASM GC backends.

The classlib unit tests pass and my app still works, I make use of the leading and trailing zero functions in my direct buffer malloc/free implementation so I actually do have a reason to optimize them.

@konsoletyper
Copy link
Owner

I doubt it will work with optimizations enabled. Optimizer may inline method bodies, written in Java, which makes impossible to apply these intrinsics. So additionally Wasm GC BE should provide class transformers which turns intrinsic target methods into native and removes their body.

@lax1dude
Copy link
Contributor Author

lax1dude commented Dec 2, 2024

@konsoletyper I see what you mean, I'll fix it tomorrow

@konsoletyper
Copy link
Owner

Yes, and although I won't ask you to write unit tests, please, at least disassemble your app and make sure that relevant WebAssembly instructions are used instead of falling back to "software" implementations.

@lax1dude
Copy link
Contributor Author

lax1dude commented Dec 3, 2024

@konsoletyper Okay I added the class transformers. I also added unit tests for the 64-bit numberOfLeadingZeros and numberOfTrailingZeros because I noticed they didn't exist. I also copied the code from the unit tests and compiled it myself and disassembled the binary and all the intrinsics are compiling correctly (on the AGGRESSIVE optimization level).

@konsoletyper konsoletyper merged commit 61e8c85 into konsoletyper:master Dec 3, 2024
6 checks passed
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