From 93e84b7bf7de63aa278bf885f8d4279300ea9bf2 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Mon, 6 Jul 2015 05:19:16 -0800 Subject: [PATCH 1/2] Define a `subnormal_mode` AST node. --- AstSemantics.md | 19 +++++++++++++++++-- Nondeterminism.md | 12 +++++++----- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/AstSemantics.md b/AstSemantics.md index 548eb9d5..2da02dec 100644 --- a/AstSemantics.md +++ b/AstSemantics.md @@ -270,6 +270,21 @@ nested. This guarantees that all resulting control flow graphs are well-structur feature would allow efficient compilation of arbitrary irreducible control flow. +## Floating Point Subnormal Handling + + * `subnormal_mode`: Like [`block`](AstSemantics.md#control-flow-structures), + but with a mode attribute specifying special semantics for the handling of + subnormal values in all lexically contained [floating point operations][] + except `neg`, `abs`, and `copysign`, and [conversions][], except those in + contained `subnormal_mode` blocks. The mode may be one of: + * `standard`: standard semantics are followed + * `dont_care`: Subnormal values may or may not be interpreted as zero of the + same sign. Subnormal result values may or may not be replaced by any + subnormal value of the same sign, or zero of the same sign. + + [floating point operations]: AstSemantics.md#floating-point-operations + [conversions]: AstSemantics.md#datatype-conversions-truncations-reinterpretations-promotions-and-demotions + ## Calls Direct calls to a function specify the callee by index into a function table. @@ -400,8 +415,8 @@ Floating point arithmetic follows the IEEE-754 standard, except that: - WebAssembly uses the round-to-nearest ties-to-even rounding attribute, except where otherwise specified. Non-default directed rounding attributes are not supported. - - The strategy for gradual underflow (subnormals) is - [under discussion](https://github.com/WebAssembly/design/issues/148). + - Inside the lexical extent of a `subnormal_mode` block, operators may follow + [alternate semantics](AstSemantics.md#floating-point-subnormal-handling). In the future, these limitations may be lifted, enabling [full IEEE-754 support](FutureFeatures.md#full-ieee-754-conformance). diff --git a/Nondeterminism.md b/Nondeterminism.md index afec0883..3eddf66b 100644 --- a/Nondeterminism.md +++ b/Nondeterminism.md @@ -32,11 +32,13 @@ currently admits nondeterminism: * Out of bounds heap accesses *may* want [some flexibility](AstSemantics.md#out-of-bounds) * [NaN bit patterns](AstSemantics.md#floating-point-operations) - * [Fixed-width SIMD may want some flexibility](PostMVP.md#fixed-width-simd) - - In SIMD.js, floating point values may or may not have subnormals flushed to - zero. - - In SIMD.js, operations ending in "Approximation" return approximations that - may vary between platforms. + * Within the lexical extent of a + `dont_care` [`subnormal_mode`](AstSemantics.md#floating-point-subnormal-handling) + block, the interpretation and production of subnormal values is + nondeterministically relaxed. + * [Fixed-width SIMD](PostMVP.md#fixed-width-simd) may define operations with + names ending in "approximation" which return approximations that may vary + nondeterministically. * Environment-dependent resource limits may be exhausted. A few examples: - Memory allocation may fail. - Program stack may get exhausted. From 28d049d2d0332604e47ce9c210d8d61a17753fd6 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Mon, 6 Jul 2015 05:19:23 -0800 Subject: [PATCH 2/2] Conversions have nondeterministic NaN bits too. --- AstSemantics.md | 3 +-- Nondeterminism.md | 4 +++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/AstSemantics.md b/AstSemantics.md index 2da02dec..edd2f93f 100644 --- a/AstSemantics.md +++ b/AstSemantics.md @@ -500,8 +500,7 @@ Promotion and demotion of floating point values always succeed. Demotion of floating point values uses round-to-nearest ties-to-even rounding, and may overflow to infinity or negative infinity as specified by IEEE-754. If the operand of promotion or demotion is NaN, the sign bit and significand -of the result are computed from an unspecified function of the implementation, -the opcode, and the operand. +of the result are not specified. Reinterpretations always succeed. diff --git a/Nondeterminism.md b/Nondeterminism.md index 3eddf66b..73294767 100644 --- a/Nondeterminism.md +++ b/Nondeterminism.md @@ -31,7 +31,9 @@ currently admits nondeterminism: nondeterministic. * Out of bounds heap accesses *may* want [some flexibility](AstSemantics.md#out-of-bounds) - * [NaN bit patterns](AstSemantics.md#floating-point-operations) + * NaN bit patterns in floating point + [operations](AstSemantics.md#floating-point-operations) and + [conversions](AstSemantics.md#datatype-conversions-truncations-reinterpretations-promotions-and-demotions) * Within the lexical extent of a `dont_care` [`subnormal_mode`](AstSemantics.md#floating-point-subnormal-handling) block, the interpretation and production of subnormal values is