[Wasm RyuJit] codegen for some intrinsics#124575
Conversation
Handle some math intrinsics that map to Wasm operations.
|
@dotnet/jit-contrib PTAL |
There was a problem hiding this comment.
Pull request overview
Adds initial WebAssembly (Wasm) RyuJIT support for lowering selected System.Math intrinsics directly to Wasm numeric instructions, enabling more operations to be emitted without helper calls.
Changes:
- Teach the importer which
System.Mathintrinsics are target-supported onTARGET_WASM. - Add Wasm codegen handling for
GT_INTRINSICand emit the corresponding Wasm instructions for supported intrinsics.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/coreclr/jit/importercalls.cpp |
Adds a TARGET_WASM arm to Compiler::IsTargetIntrinsic for a set of System.Math intrinsics. |
src/coreclr/jit/codegenwasm.cpp |
Handles GT_INTRINSIC in Wasm codegen and introduces CodeGen::genIntrinsic to emit Wasm ops for supported intrinsics. |
|
Tagging subscribers to 'arch-wasm': @lewing, @pavelsavara |
Co-authored-by: Copilot <[email protected]>
|
I think you'd want @tannergooding's review. These intrinsics are tricky around IEEE754. E.g. it seems f32.max in WASM corresponds to IEEE 754-2019's maximum. Is it the same for Math.Max? Same concerns for min, round |
|
The Wasm spec says:
If we must explicitly check for and propagate NaN inputs this may tip the scale in favor of always using a helper call (especially for binops). |
|
Notably, the NaN propagation issue affects all FP operations, not just intrinsics. What are our actual semantic requirements for it (required for all ops, required only for min/max, required for all |
|
I will note that from glancing at the interpreter code, it uses native floating point operations in C++ and doesn't take any steps to preserve NaNs. I ran a snippet of the interpreter through godbolt and it doesn't look like clang generated any special wasm to preserve NaNs for those operations either (I looked at add and mul). So for consistency with the interpreter as it currently exists, we'd want to use the native opcodes in most cases, I think. |
|
@tannergooding this is the issue I pinged you about offline... |
|
Left some comments above that talked about things both ways. The TL;DR is that we want to propagate if possible for consistency, but there is no strict requirement to do so and it is still compliant if a runtime canonicalizes their NaN results (most just don't because its faster to not). WASM recommends that implementations do propagate matching the IEEE 754 spec and anything that isn't will have the same issue for |
|
/ba-g android timeouts |
Handle some math intrinsics that map to Wasm operations.