-
Notifications
You must be signed in to change notification settings - Fork 5.3k
[Wasm Ryujit] codegen for NOT and NEG #122376
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
Conversation
Wasm has a few wrinkles here to sort through. There is no NOT or NEG for integer types in Wasm. Also, support returning TYP_LONG directly.
|
@dotgnet/jit PTAL |
|
Might want to remove |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds WASM support for NOT and NEG operations in the RyuJIT compiler. Since WASM lacks native NOT and NEG instructions for integer types, the implementation transforms integer NEG operations into SUB(0, x) during lowering, handles NOT using XOR with -1 during code generation, and preserves native f32.neg/f64.neg for floating-point types. Additionally, the PR enables direct TYP_LONG return values for WASM (which has native 64-bit support).
Key Changes
- Added LowerNeg in lowerwasm.cpp to transform integer NEG operations to SUB(0, x)
- Added genCodeForNegNot in codegenwasm.cpp to handle NOT (via XOR with -1) and floating-point NEG
- Modified ContainCheckRet to allow WASM to return TYP_LONG directly without containing GT_LONG nodes
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/coreclr/jit/lowerwasm.cpp | Implements LowerNeg to transform integer NEG operations to SUB(0, x) since WASM lacks native integer NEG |
| src/coreclr/jit/lower.h | Declares LowerNeg function under TARGET_WASM guard |
| src/coreclr/jit/lower.cpp | Integrates LowerNeg into LowerNode for GT_NEG case and allows WASM to return TYP_LONG directly |
| src/coreclr/jit/codegenwasm.cpp | Implements genCodeForNegNot to generate WASM instructions: XOR with -1 for NOT, native f32.neg/f64.neg for floating-point NEG |
Co-authored-by: Copilot <[email protected]>
SingleAccretion
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with minor comments.
|
Tagging subscribers to 'arch-wasm': @lewing, @pavelsavara |
Wasm has a few wrinkles here to sort through. There is no NOT or NEG for integer types in Wasm.
Also, support returning TYP_LONG directly.