winch: respect the enable_nan_canonicalization setting#12939
winch: respect the enable_nan_canonicalization setting#12939r-near wants to merge 2 commits intobytecodealliance:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR ensures Winch respects the existing enable_nan_canonicalization shared setting by adding a canonicalize_nan hook to the MacroAssembler trait and invoking it after scalar floating-point operations so NaN results are normalized to the canonical quiet-NaN bit pattern.
Changes:
- Add
MacroAssembler::canonicalize_nanand implement it for x64 and aarch64. - Invoke NaN canonicalization after scalar float arithmetic/conversion ops (and after rounding paths in the visitor).
- Add a scalar WAST test to validate canonical NaN bit patterns.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
winch/codegen/src/visitor.rs |
Inserts canonicalize_nan after scalar float ops and adds helper for rounding results. |
winch/codegen/src/masm.rs |
Extends the MacroAssembler trait with canonicalize_nan. |
winch/codegen/src/isa/x64/masm.rs |
Implements NaN detection + replacement with canonical NaN on x64. |
winch/codegen/src/isa/aarch64/masm.rs |
Implements NaN detection + replacement with canonical NaN on aarch64; stores shared flags in the masm. |
tests/misc_testsuite/canonicalize-nan-scalar.wast |
Adds scalar coverage for canonical NaN bit patterns and propagation. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
fc5efb7 to
97d89bb
Compare
97d89bb to
0c5e168
Compare
Subscribe to Label ActionDetailsThis issue or pull request has been labeled: "winch"Thus the following users have been cc'd because of the following labels:
To subscribe or unsubscribe from this label, edit the |
|
@r-near we usually either stick with the assignment bot's suggestions (the reason I reviewed your last PR) or, in cases such as this one, tag a sub-area reviewer who knows part of the code best -- in this case @saulecabrera might be best to review Winch-specific work? |
|
I'll review. |
The
enable_nan_canonicalizationflag already flows through to Winch via the sharedFlags, but Winch was ignoring it. This adds acanonicalize_nanmethod to theMasmtrait that, when the flag is set, emits a compare-with-self + conditional branch to replace NaN results with the canonical quiet NaN after each float arithmetic op.Covered operations: add, sub, mul, div, min, max, sqrt, ceil, floor, trunc, nearest, demote, and promote. Implemented for x64 and aarch64. Includes a scalar wast test (counterpart to
simd/canonicalize-nan.wast).