Skip to content

Add a bitwise-or form of NaN propagation.#713

Closed
sunfishcode wants to merge 1 commit intomasterfrom
bitwise-or-nan-propagation
Closed

Add a bitwise-or form of NaN propagation.#713
sunfishcode wants to merge 1 commit intomasterfrom
bitwise-or-nan-propagation

Conversation

@sunfishcode
Copy link
Member

I recently read about a CPU which has NaN propagation behavior that is not supported by WebAssembly.

This PR proposes to augment WebAssembly's NaN rules to say that when there are multiple NaN inputs, the return can be computed by bitwise-or'ing them together. This change:

  • requires no changes in existing implementations
  • is basically compatible with the NaN-boxing-on-wasm scheme the current NaN rules aim to support
  • keeps nondeterminism quite limited while still supporting current and anticipated hardware designs

That said, the NaN rules are already fairly complex, and this would make them even more so, and it does slightly increase nondeterminism. Dropping the goal of supporting NaN boxing on top of wasm, and/or accepting greater nondeterminism in NaN bits, could simplify the spec in this area.

@sunfishcode sunfishcode added this to the MVP milestone Jun 27, 2016
@kripken
Copy link
Member

kripken commented Jun 27, 2016

What's the cpu?

@sunfishcode
Copy link
Member Author

It's an obscure CPU; I think the argument in favor is primarily one of theoretical portability combined with the relatively low impact on everyone else. If an actual CPU does this, others in the future might too.

@gahaas
Copy link
Contributor

gahaas commented Jun 28, 2016

I think we should stick to the IEEE-754 standard which says that "the result shall be a quiet NaN which should be one of the input NaNs". It seems to me that this obscure CPU and all future CPUs which behave similar do not satisfy the IEEE-754 standard.

@sunfishcode
Copy link
Member Author

Note the "should" in that sentence; returning a quiet NaN is required, but returning one of the input NaNs is not. RISC-V, and ARM in "default NaN" mode, are examples of CPUs that don't implement the "should" part. Since IEEE itself doesn't require it, and there exists hardware that found some practucal motivation to omit it, future CPUs might omit it too, so it's risky for WebAssembly to require it.

And in practice, the utility of forwarding NaN payloads through arithmetic for diagnostic information purposes, IEEE's stated motivation for this recommendation, is limited, given that WebAssembly can't practically define any actual diagnostics.

WebAssenbly was changed to allow "default NaN behavior" here. This PR currently proposes to further allow bitwise-or behavior too.

@kripken
Copy link
Member

kripken commented Jun 28, 2016

Sounds good to me.

@titzer
Copy link

titzer commented Jun 29, 2016

@sunfishcode According to the above logic, then this obscure CPU is also IEEE-compliant? If that's the case, then why don't we just adopt the IEEE 754 language? FWIW this NaN behavior doesn't really preclude NaN-boxing as far as I can tell, it just means that implementations need to be able to get the original source inputs rather than relying on the output being a copy of one of the inputs.

@sunfishcode
Copy link
Member Author

@titzer The IEEE 754 language doesn't support the basic NaN boxing use case efficiently, as it would requiring extra canonicalization after arithmetic operations.

Because I recognize this PR adds complexity, I've now also created #716 which proposes an alternative solution, following the "accepting greater nondeterminism in NaN bits" approach suggested above. At most one of these two PRs should be merged.

@sunfishcode sunfishcode modified the milestone: MVP Jul 8, 2016
@flagxor
Copy link
Member

flagxor commented Jul 27, 2016

Let's do #716 instead.
Closing.

@flagxor flagxor closed this Jul 27, 2016
@sunfishcode sunfishcode deleted the bitwise-or-nan-propagation branch August 9, 2016 19:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants