-
Notifications
You must be signed in to change notification settings - Fork 83
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
Perform NaN randomization as part of the interpretation of float bits #279
Perform NaN randomization as part of the interpretation of float bits #279
Conversation
Good catch on the missing |
This removes the `THE_HOST_WANTS_TO` option, which appeared to give hosts permission to interpret NaN bits how they "want to". The change here is to say that all core-wasm NaN bitpatterns are interpreted as the same component-model NaN value. It's my understanding that the `random_nan_bits` function isn't meant to be the precise algorithm that nondeterministic-profile implementations must use, so this doesn't require hosts to do any new randomization work. This change also fixes what appears to be a bug: `lift_flat_variant`/`lower_flat_variant` were calling `reinterpret_i32_as_float`/`reinterpret_float_as_i32` without performing NaN scrambling. By making NaN scrambling be part of interpretation, we ensure that it's performed anywhere interpretation is performed.
6a34d7b
to
af62ee5
Compare
I've now changed the PR to canonicalize on lifting, and scramble on lowering. This better illustrates how "all core-wasm NaN bitpatterns are interpreted as the same component-model NaN value".
It's my understanding that your goal here is to avoid confusion among hosts about "do I need to randomize?" My goal here is to avoid the confusion among hosts about "is it ok for me to interpret the bits, if I «want to»?" If they do that, they break virtualization in a subtle way. Also, if we can say there's only one component-model NaN value, that would make it clear why wave doesn't need nan payload syntax. I've also now added comments to this PR to call out how hosts can avoid skip canonicalization and randomization overhead entirely in practice. |
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.
I really like this idea of saying that there is only one "semantic" NaN value -- it's just that lowering scrambles and oh hey, it's technically valid not to canonicalize if you don't want to. Nice and thanks for the consideration!
Just stylistic nits:
And reword to better fit it in with the rest of the prose.
Co-authored-by: Luke Wagner <[email protected]>
Thanks again for thinking through this! |
With WebAssembly/component-model#279, component-model floating-point types have a single NaN value. Canonicalization isn't required, and may be omitted as an optimization, but users shouldn't depend on NaN bitpatterns being preserved. To help users avoid depending on NaN bitpatterns being preserved as they propagate through component-model values, canonicalize NaN values in Wave.
This removes the
THE_HOST_WANTS_TO
option, which appeared to give hosts permission to interpret NaN bits how they "want to". The change here is to say that all core-wasm NaN bitpatterns are interpreted as the same component-model NaN value.It's my understanding that the
random_nan_bits
function isn't meant to be the precise algorithm that nondeterministic-profile implementations must use, so this doesn't require hosts to do any new randomization work.This change also fixes what appears to be a bug:
lift_flat_variant
/lower_flat_variant
were callingreinterpret_i32_as_float
/reinterpret_float_as_i32
without performing NaN scrambling. By making NaN scrambling be part of interpretation, we ensure that it's performed anywhere interpretation is performed.