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

Implement accurate float32 semantics #29

Merged
merged 3 commits into from
Aug 27, 2015
Merged

Implement accurate float32 semantics #29

merged 3 commits into from
Aug 27, 2015

Conversation

rossberg
Copy link
Member

@lukewagner, @kg, doing it asm.js-style.

)

(asserteq
(invoke "eq_float32" (const.f32 1.123456789012345) (const.f32 1.123456789))
Copy link
Member

Choose a reason for hiding this comment

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

For the AST syntax, it's desirable to issue an error when the literal value can't be exactly represented its type, rather than implicitly rounding it, as this test is testing, since rounding is an interesting operation from the perspective of a language spec.

There is also a variety of opinions about whether we even want a decimal syntax for floating point values, though I think it's fine for now for exactly representable values.

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 agree, it would be good to have the front-end issue errors whenever there is rounding. But it seems like that would require implementing our own string-to-float conversion. I'm no real expert on that.

At least I changed the tests so that the don't rely on rounding for literals.

Copy link
Member

Choose a reason for hiding this comment

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

The proposed floating formats just represent the bits of the IEEE754
float32/float64 directly, so all you need at the end is an
Int64.float_of_bits.

On Wed, Aug 26, 2015 at 1:01 PM, rossberg-chromium <[email protected]

wrote:

In ml-proto/test/float32.wasm
#29 (comment):

  • (func $div_float32 (param $x f32) (param $y f32) (result f32)
  • (div.f32 (getlocal $x) (getlocal $y))
  • )
  • (func $div_float64 (param $x f64) (param $y f64) (result f64)
  • (div.f64 (getlocal $x) (getlocal $y))
  • )
  • (export "eq_float32" $eq_float32)
  • (export "eq_float64" $eq_float64)
  • (export "div_float32" $div_float32)
  • (export "div_float64" $div_float64)
    +)

+(asserteq

  • (invoke "eq_float32" (const.f32 1.123456789012345) (const.f32 1.123456789))

I agree, it would be good to have the front-end issue errors whenever
there is rounding. But it seems like that would require implementing our
own string-to-float conversion. I'm no real expert on that.

At least I changed the tests so that the don't rely on rounding for
literals.


Reply to this email directly or view it on GitHub
https://github.com/WebAssembly/spec/pull/29/files#r38013736.

Copy link
Member

Choose a reason for hiding this comment

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

A simple thing we could do for the parser for now would be to just test if string_of_float on the float value gives us a string equal to the string passed to float_of_string, and issue an error if it's not. That won't be everything we'll ever want, but it'll work for many simple purposes.

Copy link
Member Author

Choose a reason for hiding this comment

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

Unfortunately, string representations for floats aren't unique. So that would prevent you from ever writing e.g. 1e10, which would be rather bad in terms of usability.

But I agree that we should add hex float literals. I would still want to keep the ability to write human readable constants in the text format, though.

Copy link
Member

Choose a reason for hiding this comment

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

Hex float is perfectly readable / writable by humans :-)
More seriously, I think it's pretty important that text parsers reject numbers which aren't precisely representable. It also important that all parsers know exactly how to do this so that they all accept the same inputs! Hex float is the easiest way to get this, but I'm open to supporting more.

I'd like to make sure that we discuss any other representation in WebAssembly/design#292, and that we write down the outcome so it's easy to search in the future. These PR discussions aren't searchable!

@lukewagner
Copy link
Member

This will get us much closer but, unfortunately, there are some ops for which the

  x,y : float32
  x f32.op y = float32( float64(x) f64.op float64(y) )

identity doesn't hold (e.g. modulus). The only ops that I know are proven are +, -, *, /, and sqrt.

@sunfishcode
Copy link
Member

Fortunately, wasm doesn't have a floating point modulus operator :-). I think this technique covers all of the operators in wasm.

@lukewagner
Copy link
Member

Also, scanning for float in asm.js, ceil, floor, the comparisons. Eliminating the transcendental functions eliminated a lot of the non-commutative ops. I was about to ask about whether we could remove float mod (b/c it's in ml-proto), but then Dan just commented :)

@rossberg
Copy link
Member Author

Ah, good point. Removed float mod.

On 26 August 2015 at 16:12, Luke Wagner [email protected] wrote:

Also, scanning for float in asm.js
http://asmjs.org/spec/latest/#standard-library, ceil, floor, the
comparisons. Eliminating the transcendental functions eliminated a lot of
the non-commutative ops. I was about to ask about whether we could remove
float mod (b/c it's in ml-proto), but then Dan just commented :)


Reply to this email directly or view it on GitHub
#29 (comment).

@lukewagner
Copy link
Member

lgtm. I also felt the pain of the imprecise decimal representation in #24; perhaps we could open a new issue/PR to use one of the schemes from design/#292 as @sunfishcode suggested?

@jfbastien
Copy link
Member

@lukewagner's cross-repo link should have been WebAssembly/design#292 :-)

I strongly support this proposal!

rossberg added a commit that referenced this pull request Aug 27, 2015
Implement accurate float32 semantics
@rossberg rossberg merged commit 9e3a789 into unsigned Aug 27, 2015
@jfbastien jfbastien deleted the float32 branch August 27, 2015 16:12
@rossberg rossberg restored the float32 branch August 28, 2015 02:59
@rossberg rossberg deleted the float32 branch August 28, 2015 03:06
littledan pushed a commit to littledan/spec that referenced this pull request Mar 4, 2018
eqrion pushed a commit to eqrion/wasm-spec that referenced this pull request Jul 18, 2019
…able.copy`. (WebAssembly#29)

This would make it simpler to extend those instructions to support multiple memories/tables, and copying between different memories/tables.

The current encoding has a single placeholder zero byte for those instructions, which allows extension to multiple memories/tables, but would require a more complicated encoding to add two immediate indices.
dhil added a commit to dhil/webassembly-spec that referenced this pull request Apr 11, 2023
* Add type annotations to continuation instructions

This patch annotates the following continuation instructions with a continuation type:

* `cont.bind $src $dst`: The annotation `$src` specifies the type of the source continuation, and `$dst` specifices the type of the target continuation (i.e. the continuation type after the partial continuation application). The latter type annotation was already present.
* `resume $kt`: The annotation `$kt` specifices the type of the continuation argument to `resume`.
* `resume $kt $tagt`: The annotation `$kt` specifies the type of the continuation argument to `resume_throw`, whilst `$tagt` specifices the type of the tag argument. The latter type annotation was already present.

This patch also drops the verbose `(type $t)` syntax on continuation instructions in favour of simply `$t`.

* Update interpreter/valid/valid.ml

Co-authored-by: Andreas Rossberg <[email protected]>

* Update interpreter/valid/valid.ml

Co-authored-by: Andreas Rossberg <[email protected]>

* Address Andreas' comments.

* Update interpreter/valid/valid.ml

Co-authored-by: Andreas Rossberg <[email protected]>

* Update interpreter/valid/valid.ml

Co-authored-by: Andreas Rossberg <[email protected]>

* Address Andreas' feedback 2

---------

Co-authored-by: Andreas Rossberg <[email protected]>
backes pushed a commit to backes/spec that referenced this pull request Jul 12, 2023
Switch order of load/store immediates in binary format
dhil added a commit to dhil/webassembly-spec that referenced this pull request Apr 12, 2024
rossberg pushed a commit that referenced this pull request Sep 4, 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.

4 participants