Skip to content
This repository has been archived by the owner on Jan 26, 2022. It is now read-only.

Semantics of minNum and maxNum don't match IEEE 754-2008 for signaling NaNs #341

Open
stoklund opened this issue Apr 18, 2016 · 10 comments
Open

Comments

@stoklund
Copy link

The IEEE 754-2008 operations minNum and maxNum suppress quiet NaNs, but they still propagate signaling NaNs, canonicalising them to qNaNs:

minNum(1.0, qNaN) -> 1.0
minNum(1.0, sNaN) -> qNaN

The ARMv8 vminnm and vmaxnm instructions have the same semantics (my emphasis):

It handles NaNs in consistence with the IEEE754-2008 specification. It returns the numerical operand when one operand is numerical and the other is a quiet NaN, but otherwise the result is identical to floating-point VMAX.

The minNum and maxNum operations currently in our specification don't distinguish between sNaNs and qNaNs. Given our approach to NaNs, it seems difficult to add the distinction.

I would suggest that we either:

  1. Rename minNum and maxNum to avoid confusion with the IEEE operations of the same name, or
  2. Remove the two functions from the specification.
@ljharb
Copy link
Member

ljharb commented Apr 18, 2016

The API needs to be consistent with JS developer expectations as well as SIMD developer expectations - and as such, differentiable NaNs aren't anything I'd think anybody would expect. What's the hazard you see from leaving it as-is?

@jfbastien
Copy link

The intent of minNum and maxNum is to follow IEEE754-2008 semantics precisely.

@ljharb
Copy link
Member

ljharb commented Apr 18, 2016

Right, but JS doesn't have qNaN or sNaN, just NaN.

@jfbastien
Copy link

Right, JS adds non-determinism on top because the NaN values aren't guaranteed, but one of the goals of the SIMD spec is (IIUC?) to be shareable with WebAssembly where the NaN values are observable. WebAssembly has its own NaN observability specification which provides more guarantees. From that POV, I think minNum and maxNum should therefore follow IEEE754-2008 closely, and then the SIMD spec has a generic "here's what happens to NaNs" on top of everything.

@sunfishcode
Copy link
Member

This issue exists independently of the shared spec idea or WebAssembly. It comes down to this:

When we added minNum and maxNum to SIMD.js, we thought we were specifying semantics compatible with the relevant subset of IEEE 754-2008, which is why we used IEEE 754-2008's names. Now it turns out we were mistaken; they aren't actually compatible in the way we thought.

Making these functions aware of signaling NaN would be one way to address this issue, however that would have significant implications for the rest of the SIMD.js spec and probably for JS as well, as it would require us to add semantics to many other places, so that developers could reason about where signaling NaNs might appear.

The suggestion above is that we either just rename these functions, to avoid confusion, since minNum and maxNum are names that IEEE 754-2008 coined, or that we (perhaps temporarily) remove them from SIMD.js. At present, removing them seems like the safest option to me; we can always reintroduce them in the future.

@ljharb
Copy link
Member

ljharb commented Apr 19, 2016

Without those methods, how can I compare two SIMD values and determine the smaller or larger? The process document specifies that the only changes expected in Stage 3 are "Limited: only those deemed critical based on implementation experience" - this does not fall into that bucket.

I don't care what they're called, but the comparative APIs to Math.min and Math.max imo are crucial to include.

@sunfishcode
Copy link
Member

The comparative APIs to Math.min and Math.max are already in the SIMD spec, under the names min and max, and they have the same semantics as their Math counterparts in JS (and similar functions in Java and other languages).

minNum and maxNum have different semantics, and were added specifically to provide IEEE 754 compatible functionality (and similar functions in C and other languages). It is these functions which are under discussion here.

@ljharb
Copy link
Member

ljharb commented Apr 19, 2016

aha, ok thanks for clarifying (it's a big API 😉).

Given that, I'm withdrawing my opinion from the discussion 😄

@nmostafa
Copy link
Contributor

I am in favor of removing them from SIMD.js, since their semantics doesn't serve any purpose now (neither JS or IEEE compliant). We can add them to WASM after semantics fix.

@stoklund
Copy link
Author

I wrote a blog post about the consequences of having non-associative min / max operations.

arunetm-zz added a commit to arunetm-zz/ChakraCore that referenced this issue May 23, 2016
See tc39/ecmascript_simd#341

MinNum and MaxNum operations are decided to be removed from
Simd.js as they are incompatablie with IEE-754 definitions of
MinNum and MaxNum, which makes use of quiet NaN's and signaling NaN's.
arunetm-zz added a commit to arunetm-zz/ChakraCore that referenced this issue May 23, 2016
See tc39/ecmascript_simd#341

MinNum and MaxNum operations are decided to be removed from
Simd.js as they are incompatablie with IEE-754 definitions of
MinNum and MaxNum, which makes use of quiet NaN's and signaling NaN's.
arunetm-zz added a commit to arunetm-zz/ChakraCore that referenced this issue May 26, 2016
See tc39/ecmascript_simd#341

MinNum and MaxNum operations are decided to be removed from
Simd.js as they are incompatablie with IEE-754 definitions of
MinNum and MaxNum, which makes use of quiet NaN's and signaling NaN's.
chakrabot pushed a commit to chakra-core/ChakraCore that referenced this issue May 26, 2016
Merge pull request #1030 from arunetm:RmF4MinMaxNum
See tc39/ecmascript_simd#341

MinNum and MaxNum operations are decided to be removed from
Simd.js as they are incompatablie with IEE-754 definitions of
MinNum and MaxNum, which makes use of quiet NaN's and signaling NaN's.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants