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

Add float conversion tests #81

Merged
merged 3 commits into from
Sep 23, 2015
Merged

Conversation

AugustusHuang
Copy link
Contributor

No description provided.

@jfbastien
Copy link
Member

Confirming that Xuxing Huang is a member of the W3C CG. Thanks!

@rossberg
Copy link
Member

lgtm

@AugustusHuang
Copy link
Contributor Author

Picked +/-0, +/- INT_MAX, +/-1 to test Int2Float, 0, 1, +/- MOST-POSITIVE-DOUBLE(SINGLE)-FLOAT, +/- LEAST-POSITIVE-DOUBLE(SINGLE)-FLOAT to test reinterpretFloat2Int, some of the results of reinterpretInt2Float will generate NaN so I didn't add them. All tests have one or more random cases :)

(assert_eq (invoke "$f32_convert_u_i32" (i32.const 0)) (f32.const 0.0))
(assert_eq (invoke "$f32_convert_u_i32" (i32.const 2147483647)) (f32.const 2147483647))
(assert_eq (invoke "$f32_convert_u_i32" (i32.const -2147483648)) (f32.const 2147483648))
(assert_eq (invoke "$f32_convert_u_i32" (i32.const 305419896)) (f32.const 305419896)) ;; 0x12345678
Copy link
Member

Choose a reason for hiding this comment

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

The wasm parser does recognize hexadecimal constants now, so you can write the constant directly now instead of writing it in decimal and having a comment :-).

@sunfishcode
Copy link
Member

This looks good!

One thing to watch out for: Constants such as 2147483647, 9223372036854775807, and 1234567890 are not exactly representable as f32 values; the wasm parser is silently rounding them. This is obviously not ideal. Eventually we should implement hexadecimal float literal parsing, and then we'll probably convert most of these tests to use it, but if you want to be tidy in the mean time, it'd be nice to avoid values that need rounding.

If you're interested in writing more conversion tests, here are some further ideas :-) :

  • Conversions with unsigned inputs will need to be tested with the maximum unsigned value of the type. For example, we'll need to test f32.convert_u/i32 against 0xffffffff and so on.
  • Conversions involving floating point will need to be tested for correct rounding. For example, the trunc conversions are defined to round toward zero, so we should make sure that a positive number rounds down even when the nearest integer is up, and a negative number rounds up even when the nearest integer is down, and so on. For conversions that round to nearest, we should test that a positive number is rounded down to nearest, a negative number is rounded up to nearest, and a number halfway between two integers is rounded to the even integer.
  • trunc conversions will need to test that values just outside the i32 range can be rounded into a valid i32 value.

We'll also eventually need to add -0, NaN, Infinity, and trapping cases, though as you noticed these aren't all convenient to do right now. I have some possible ideas for this in this branch, though there's discussion ongoing about them in #70.

sunfishcode added a commit that referenced this pull request Sep 23, 2015
@sunfishcode sunfishcode merged commit 8cb562c into WebAssembly:master Sep 23, 2015
littledan pushed a commit to littledan/spec that referenced this pull request Mar 4, 2018
littledan pushed a commit to littledan/spec that referenced this pull request Mar 4, 2018
Revert "Update docs to allow import/export mut globals (WebAssembly#81)"

This reverts commit 5d2ad6e.

Revert "Support import/export mut globals in interpreter (WebAssembly#80)"

This reverts commit 07a6fb2.
eqrion pushed a commit to eqrion/wasm-spec that referenced this pull request Jul 18, 2019
dhil pushed a commit to dhil/webassembly-spec that referenced this pull request Mar 2, 2023
dhil added a commit to dhil/webassembly-spec that referenced this pull request Aug 30, 2024
This patch redefines the `switch` instruction such that it only takes a single immediate type (in addition to the tag).

Resolves WebAssembly#76.
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.

4 participants