diff options
| author | Dan Gohman <sunfish@mozilla.com> | 2015-06-15 16:14:30 -0700 |
|---|---|---|
| committer | Dan Gohman <sunfish@mozilla.com> | 2015-06-15 16:14:30 -0700 |
| commit | cfed15608dc2e09d9f24b930b504007491e73ee3 (patch) | |
| tree | ce1262b5716d62c9670c77281e593646ee768804 | |
| parent | cf781d468394304794e29625d8bd9ca53578c353 (diff) | |
| parent | 9ff302ec30e71d756942ef906c243349bd6ee000 (diff) | |
| download | nanowasm-design-cfed15608dc2e09d9f24b930b504007491e73ee3.tar.gz | |
Merge pull request #175 from WebAssembly/memoryaccess
refine memory loads/stores
| -rw-r--r-- | AstSemantics.md | 72 |
1 files changed, 34 insertions, 38 deletions
diff --git a/AstSemantics.md b/AstSemantics.md index 1c04006..534e58d 100644 --- a/AstSemantics.md +++ b/AstSemantics.md @@ -35,14 +35,10 @@ variables, local variables, and parameters. The heap itself is not typed, but all accesses to the heap are annotated with a type. The legal types for global variables and heap accesses are called *Memory types*. - * sint8 - signed 8-bit integer - * sint16 - signed 16-bit integer - * sint32 - signed 32-bit integer - * sint64 - signed 64-bit integer - * uint8 - unsigned 8-bit integer - * uint16 - unsigned 16-bit integer - * uint32 - unsigned 32-bit integer - * uint64 - unsigned 64-bit integer + * int8 - 8-bit integer + * int16 - 16-bit integer + * int32 - 32-bit integer + * int64 - 64-bit integer * float32 - 32-bit floating point * float64 - 64-bit floating point @@ -54,41 +50,41 @@ are a subset of the Memory types: * float32 - 32-bit floating point * float64 - 64-bit floating point -All IR operations except loads and stores deal with local types. Loads implicitly -convert Memory types to Local types according to the follow rules: - - * load[sint8] - sign-extend to int32 - * load[sint16] - sign-extend to int32 - * load[sint32] - (no conversion) - * load[sint64] - (no conversion) - * load[uint8] - zero-extend to int32 - * load[uint16] - zero-extend to int32 - * load[uint32] - reinterpret as int32 - * load[uint64] - reinterpret as int64 - * load[float32] - (no conversion) - * load[float64] - (no conversion) +All IR operations except loads and stores deal with local types. Loads convert +Memory types to Local types according to the following rules: + + * int32.load_sx[int8] - sign-extend to int32 + * int32.load_sx[int16] - sign-extend to int32 + * int32.load_zx[int8] - zero-extend to int32 + * int32.load_zx[int16] - zero-extend to int32 + * int32.load[int32] - (no conversion) + * int64.load_sx[int8] - sign-extend to int64 + * int64.load_sx[int16] - sign-extend to int64 + * int64.load_sx[int32] - sign-extend to int64 + * int64.load_zx[int8] - zero-extend to int64 + * int64.load_zx[int16] - zero-extend to int64 + * int64.load_zx[int32] - zero-extend to int64 + * int64.load[int64] - (no conversion) + * float32.load[float32] - (no conversion) + * float64.load[float64] - (no conversion) Note that the local types int32 and int64 don't technically have a sign; the sign bit is interpreted differently by the operations below. -Note: [issue #139](https://github.com/WebAssembly/design/issues/139) discussed -extending loads and truncating stores in more details. - -Similar to loads, stores implicitly truncate Local types to Memory types -according to the following rules: +Similar to loads, stores convert Local types to Memory types according to the +following rules: - * store[sint8] - truncate int32 to sint8 - * store[sint16] - truncate int32 to sint16 - * store[sint32] - (no truncation) - * store[sint64] - (no truncation) - * store[uint8] - truncate int32 to uint8 - * store[uint16] - truncate int32 to uint16 - * store[uint32] - reinterpret int32 as uint32 - * store[uint64] - reinterpret int64 as uint64 - * store[float32] - (no truncation) - * store[float64] - (no truncation) + * int32.store[int8] - wrap int32 to int8 + * int32.store[int16] - wrap int32 to int16 + * int32.store[int32] - (no conversion) + * int64.store[int8] - wrap int64 to int8 + * int64.store[int16] - wrap int64 to int16 + * int64.store[int32] - wrap int64 to int32 + * int64.store[int64] - (no conversion) + * float32.store[float32] - (no conversion) + * float64.store[float64] - (no conversion) -Truncation of integers simply discards any upper bits; i.e. truncation does not +Wrapping of integers simply discards any upper bits; i.e. wrapping does not perform saturation, trap on overflow, etc. ## Addressing local variables @@ -148,7 +144,7 @@ which leads to the following advantages: Each heap access is annotated with a *Memory type* and the presumed alignment of the incoming pointer. As discussed previously, loads may -include implicit zero- or sign-extension and stores may include implicit truncation. +include explicit zero- or sign-extension and stores may include implicit wrapping. Indexes into the heap are always byte indexes. |
