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

Fuzzer: Add SIMD support to DeNaN #6318

Merged
merged 15 commits into from
Feb 21, 2024
Merged

Conversation

kripken
Copy link
Member

@kripken kripken commented Feb 15, 2024

It already sanitized away NaNs in f32 and f64, but was missing SIMD. This matters
when comparing results between VMs due to nondeterminism, which is tested
more thanks to #6312

@kripken kripken requested a review from tlively February 15, 2024 22:24
uint8_t zero128[16] = {};
// InvalidBinary is passed here as the condition in this case is more
// complex and computed above.
add(deNan128, Type::v128, Literal(zero128), InvalidBinary);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about making the op argument a std::optional? That would take less explaining than passing InvalidBinary here, I think.

}

// Check if a contant v128 may contain f32 or f64 NaNs.
bool maybeNaN(Const* c) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe call this hasNaNLane or hasNaN? I don't think maybe is quite accurate.


;; This is not a NaN. (We do still emit a call for it atm, FIXME)
(drop
(v128.const i32x4 0x00000001 0x00000002 0x00000003 0x00000004)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be useful to write the tests using f32x4 and f64x2 shapes rather than i32x4 so we can better see what values are being passed. You can use the --new-wat-parser and its extensive support for the standard nan formats if you want.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was actually thinking it is nice to see the actual bits because of how they are used in the pass (the explanation about the f32 and f64 bits overlapping etc.)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be more specific, in this test code:

    ;; This is an f64 NaN and also an f32. It will become 0's.
    (drop
      (v128.const i32x4 0xffffffff 0x00000002 0x00000003 0x00000004)
    )
    ;; This is an f32 NaN and not an f64. It will also become 0's.
    (drop
      (v128.const i32x4 0x00000001 0xffffffff 0x00000003 0x00000004)
    )

It is nice to see the bits, because that allows the comments to clarify how the same bits can be both f32 and f64 nans, or not.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would be more convinced by this if readers were likely to know off the top of their heads what bit patterns correspond to NaNs. I know I don't :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heh, I don't know that either, but I mentioned it in the pass (8 vs 11 top non-sign bits).

(func $foo128 (param $x v128) (result v128)
;; The incoming param will be de-naned.

;; This is not a NaN. (We do still emit a call for it atm, FIXME)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does this happen?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No good reason - that's what the code did for f32 and f64 before this PR. I can fix it later.

@kripken
Copy link
Member Author

kripken commented Feb 20, 2024

Adding some changes from feedback, and responses to other feedback.

Copy link
Member

@tlively tlively left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I still think the tests would be more readable/useful if they used NaN syntax, but I understand the benefit of seeing the bits, too, and I don't feel strongly about it.

@kripken kripken merged commit 0ecea77 into WebAssembly:main Feb 21, 2024
14 checks passed
@kripken kripken deleted the fuzz.simd.nan branch February 21, 2024 00:26
radekdoulik pushed a commit to dotnet/binaryen that referenced this pull request Jul 12, 2024
@gkdn gkdn mentioned this pull request Aug 31, 2024
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