aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Gohman <sunfish@mozilla.com>2020-02-26 18:30:43 -0800
committerGitHub <noreply@github.com>2020-02-26 18:30:43 -0800
commitccbac15a287fa2af4a3db882d950db442011a7b1 (patch)
tree65a9bf05926713284bc5c6ee313f52b56d76bebc
parentd4e7f960c5e3f3788531147e4ea4ed23eb507c02 (diff)
downloadnanowasm-design-ccbac15a287fa2af4a3db882d950db442011a7b1.tar.gz
Define non-trapping float-to-int conversions. (#1089)
* Define non-trapping float-to-int conversions. This also introduces the concept of prefix bytes, and defines the "numeric" prefix byte, used for encodin the new conversion instructions. * Add feature markers. * Add the feature marker in more places. * Rename "numeric" to "misc". See https://github.com/WebAssembly/nontrapping-float-to-int-conversions/issues/5. * Rename opcodes. See https://github.com/WebAssembly/spec/issues/884#issuecomment-426433329.
-rw-r--r--BinaryEncoding.md28
-rw-r--r--Semantics.md23
2 files changed, 44 insertions, 7 deletions
diff --git a/BinaryEncoding.md b/BinaryEncoding.md
index f0ec70f..6edacc8 100644
--- a/BinaryEncoding.md
+++ b/BinaryEncoding.md
@@ -57,12 +57,20 @@ Note: Currently, the only sizes used are `varint7`, `varint32` and `varint64`.
## Instruction Opcodes
-In the MVP, the opcodes of [instructions](Semantics.md) are all encoded in a
-single byte since there are fewer than 256 opcodes. Future features like
-[SIMD][future simd] and [atomics][future threads]
-will bring the total count above 256 and so an extension scheme will be
-necessary, designating one or more single-byte values as prefixes for multi-byte
-opcodes.
+The opcodes for many common instructions are encoded in a single byte.
+
+The opcodes for some families of instructions are encoded as a *prefix byte*
+followed by an LEB128 value. Prefix byte values are allocated starting at `0xfe`
+and counting downwards.
+
+### Prefix Bytes
+
+| Opcode | Name | Description |
+| ------ | -------- | ----------- |
+| `0xff` | reserved | Reserved for unknown future language evolution :milky_way: |
+| `0xfe` | threads | Expected to be used for [atomics :unicorn:][future threads] |
+| `0xfd` | simd | Expected to be used for [SIMD :unicorn:][future simd] |
+| `0xfc` | misc | Miscellaneous operations :bowling: |
## Language Types
@@ -802,6 +810,14 @@ for [future :unicorn:][future multiple tables] use and must be 0 in the MVP.
| `f64.convert_s/i64` | `0xb9` | | |
| `f64.convert_u/i64` | `0xba` | | |
| `f64.promote/f32` | `0xbb` | | |
+| `i32.trunc_sat_f32_s` | `0xfc` `0x00` | | :bowling: saturating form of `i32.trunc_f32_s` |
+| `i32.trunc_sat_f32_u` | `0xfc` `0x01` | | :bowling: saturating form of `i32.trunc_f32_u` |
+| `i32.trunc_sat_f64_s` | `0xfc` `0x02` | | :bowling: saturating form of `i32.trunc_f64_s` |
+| `i32.trunc_sat_f64_u` | `0xfc` `0x03` | | :bowling: saturating form of `i32.trunc_f64_u` |
+| `i64.trunc_sat_f32_s` | `0xfc` `0x04` | | :bowling: saturating form of `i64.trunc_f32_s` |
+| `i64.trunc_sat_f32_u` | `0xfc` `0x05` | | :bowling: saturating form of `i64.trunc_f32_u` |
+| `i64.trunc_sat_f64_s` | `0xfc` `0x06` | | :bowling: saturating form of `i64.trunc_f64_s` |
+| `i64.trunc_sat_f64_u` | `0xfc` `0x07` | | :bowling: saturating form of `i64.trunc_f64_u` |
## Reinterpretations ([described here](Semantics.md#datatype-conversions-truncations-reinterpretations-promotions-and-demotions))
diff --git a/Semantics.md b/Semantics.md
index aa0ed9f..ae6db70 100644
--- a/Semantics.md
+++ b/Semantics.md
@@ -35,6 +35,14 @@ detailed in this document.
[:unicorn:][future general] = Planned [future][future general] feature
+## Post-MVP Features
+
+Some features were added post-MVP. These are indicated with the following symbols:
+
+| Symbol | Feature |
+| ---------- | ------- |
+| :bowling: | Saturating float to int conversions |
+
## Traps
Some operators may *trap* under some conditions, as noted below. In the MVP,
@@ -640,6 +648,14 @@ is NaN, and *ordered* otherwise.
* `f64.convert_u/i32`: convert an unsigned 32-bit integer to a 64-bit float
* `f64.convert_u/i64`: convert an unsigned 64-bit integer to a 64-bit float
* `f64.reinterpret/i64`: reinterpret the bits of a 64-bit integer as a 64-bit float
+ * `i32.trunc_sat_f32_s`: :bowling: truncate a 32-bit float to a signed 32-bit integer with saturation
+ * `i32.trunc_sat_f64_s`: :bowling: truncate a 64-bit float to a signed 32-bit integer with saturation
+ * `i32.trunc_sat_f32_u`: :bowling: truncate a 32-bit float to an unsigned 32-bit integer with saturation
+ * `i32.trunc_sat_f64_u`: :bowling: truncate a 64-bit float to an unsigned 32-bit integer with saturation
+ * `i64.trunc_sat_f32_s`: :bowling: truncate a 32-bit float to a signed 64-bit integer with saturation
+ * `i64.trunc_sat_f64_s`: :bowling: truncate a 64-bit float to a signed 64-bit integer with saturation
+ * `i64.trunc_sat_f32_u`: :bowling: truncate a 32-bit float to an unsigned 64-bit integer with saturation
+ * `i64.trunc_sat_f64_u`: :bowling: truncate a 64-bit float to an unsigned 64-bit integer with saturation
Wrapping and extension of integer values always succeed.
Promotion and demotion of floating point values always succeed.
@@ -665,7 +681,12 @@ round-to-nearest ties-to-even rounding.
Truncation from floating point to integer where IEEE 754-2008 would specify an
invalid operator exception (e.g. when the floating point value is NaN or
-outside the range which rounds to an integer in range) traps.
+outside the range which rounds to an integer in range) is handled as follows:
+ - For instructions with no exceptional behavior specified, a trap is produced.
+ - :bowling: For instructions containing `_sat`, no trap is produced, and:
+ - If the floating-point value is positive, the maximum integer value is returned.
+ - If the floating-point value is negative, the minimum integer value is returned.
+ - If the floating-point value is NaN, zero is returned.
## Type-parametric operators