Skip to content

Convert operator and type names to lowercase with underscores. #122

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 15, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
246 changes: 123 additions & 123 deletions AstSemantics.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,48 +35,48 @@ 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*.

* Int8 - signed 8-bit integer
* Int16 - signed 16-bit integer
* Int32 - signed 32-bit integer
* Uint8 - unsigned 8-bit integer
* Uint16 - unsigned 16-bit integer
* Uint32 - unsigned 32-bit integer
* Float32 - 32-bit floating point
* Float64 - 64-bit floating point
* sint8 - signed 8-bit integer
* sint16 - signed 16-bit integer
* sint32 - signed 32-bit integer
* uint8 - unsigned 8-bit integer
* uint16 - unsigned 16-bit integer
* uint32 - unsigned 32-bit integer
* float32 - 32-bit floating point
* float64 - 64-bit floating point

The legal types for parameters and local variables, called *Local types*
are a subset of the Memory types:

* Int32 - 32-bit integer
* Float32 - 32-bit floating point
* Float64 - 64-bit floating point
* int32 - 32-bit integer
* 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[Int8] - sign-extend to Int32
* Load[Int16] - sign-extend to Int32
* Load[Int32] - (no conversion)
* Load[Uint8] - zero-extend to Int32
* Load[Uint16] - zero-extend to Int32
* Load[Uint32] - reinterpret as Int32
* Load[Float32] - (no conversion)
* Load[Float64] - (no conversion)
* load[sint8] - sign-extend to int32
* load[sint16] - sign-extend to int32
* load[sint32] - (no conversion)
* load[uint8] - zero-extend to int32
* load[uint16] - zero-extend to int32
* load[uint32] - reinterpret as int32
* load[float32] - (no conversion)
* load[float64] - (no conversion)

Note that the local type Int32 does not technically have a sign; the sign bit
Note that the local type int32 does not technically have a sign; the sign bit
is interpreted differently by the operations below.

Similar to loads, stores implicitly truncate Local types to Memory types according to the
following rules:

* Store[Int8] - truncate Int32 to Int8
* Store[Int16] - truncate Int32 to Int16
* Store[Int32] - (no truncation)
* Store[Uint8] - truncate Int32 to Uint8
* Store[Uint16] - truncate Int32 to Uint16
* Store[Uint32] - reinterpret Int32 as Uint32
* Store[Float32] - (no truncation)
* Store[Float64] - (no truncation)
* store[sint8] - truncate int32 to sint8
* store[sint16] - truncate int32 to sint16
* store[sint32] - (no truncation)
* store[uint8] - truncate int32 to uint8
* store[uint16] - truncate int32 to uint16
* store[uint32] - reinterpret int32 as uint32
* store[float32] - (no truncation)
* store[float64] - (no truncation)

Truncation of integers simply discards any upper bits; i.e. truncation does not perform saturation,
trap on overflow, etc.
Expand All @@ -92,8 +92,8 @@ Local variables have *Local types* and are initialized to the appropriate zero v
their type at the beginning of the function, except parameters which are
initialized to the values of the arguments passed to the function.

* GetLocal - read the current value of a local variable
* SetLocal - set the current value of a local variable
* get_local - read the current value of a local variable
* set_local - set the current value of a local variable

The details of index space for local variables and their types needs clarification,
e.g. whether locals with type int32 must be contiguous and separate from others,
Expand All @@ -104,16 +104,16 @@ etc.
WebAssembly offers basic structured control flow. All control flow structures
are statements.

* **Block**: a fixed-length sequence of statements
* **If**: if statement
* **Do-While**: do while statement, basically a loop with a conditional branch
* **block**: a fixed-length sequence of statements
* **if**: if statement
* **do_while**: do while statement, basically a loop with a conditional branch
(back to the top of the loop)
* **Forever**: infinite loop statement (like `while (1)`), basically an
* **forever**: infinite loop statement (like `while (1)`), basically an
unconditional branch (back to the top of the loop)
* **Continue**: continue to start of nested loop
* **Break**: break to end from nested loop or block
* **Return**: return zero or more values from this function
* **Switch**: switch statement with fallthrough
* **continue**: continue to start of nested loop
* **break**: break to end from nested loop or block
* **return**: return zero or more values from this function
* **switch**: switch statement with fallthrough

Break and continue statements can only target blocks or loops in which they are
nested. This guarantees that all resulting control flow graphs are reducible,
Expand Down Expand Up @@ -142,14 +142,14 @@ include implicit zero- or sign-extension and stores may include implicit truncat

Indexes into the heap are always byte indexes.

* LoadHeap - load a value from the heap at a given index with given alignment
* StoreHeap - store a given value to the heap at a given index with given alignment
* load_heap - load a value from the heap at a given index with given alignment
* store_heap - store a given value to the heap at a given index with given alignment

To enable more aggressive hoisting of bounds checks, heap accesses may also include
an offset:

* LoadHeapWithOffset - load a value from the heap at a given index plus a given immediate offset
* StoreHeapWithOffset - store a given value to the heap at a given index plus a given immediate offset
* load_heap_with_offset - load a value from the heap at a given index plus a given immediate offset
* store_heap_with_offset - store a given value to the heap at a given index plus a given immediate offset

The addition of the offset and index is specified to use infinite precision
such that an out-of-bounds access never wraps around to an in-bounds access.
Expand All @@ -164,7 +164,7 @@ accept 64-bit unsigned integers.

In the MVP, heaps are not shared between threads. When
[threads](PostMVP.md#threads) are added as a feature, the basic
`LoadHeap`/`StoreHeap` nodes will have the most relaxed semantics specified in
`load_heap`/`store_heap` nodes will have the most relaxed semantics specified in
the memory model and new heap-access nodes will be added with atomic and
ordering guarantees.

Expand Down Expand Up @@ -218,8 +218,8 @@ opportunities provided by each.
Global accesses always specify a single global variable with a constant index.
Every global has exactly one type. Global variables are not aliased to the heap.

* LoadGlobal - load the value of a given global variable
* StoreGlobal - store a given value to a given global variable
* load_global - load the value of a given global variable
* store_global - store a given value to a given global variable

The specification will add atomicity annotations in the future. Currently
all global accesses can be considered "non-atomic".
Expand All @@ -228,21 +228,21 @@ all global accesses can be considered "non-atomic".

Direct calls to a function specify the callee by index into a function table.

* CallDirect - call function directly
* call_direct - call function directly

Each function has a signature in terms of local types, and calls must match the
function signature exactly. [Imported functions](MVP.md#code-loading-and-imports)
also have signatures and are added to the same function table and are thus also
callable via `CallDirect`.
callable via `call_direct`.

Indirect calls may be made to a value of function-pointer type. A function-
pointer value may be obtained for a given function as specified by its index
in the function table.

* CallIndirect - call function indirectly
* AddressOf - obtain a function pointer value for a given function
* call_indirect - call function indirectly
* addressof - obtain a function pointer value for a given function

Function-pointer values are comparable for equality and the `AddressOf` operator
Function-pointer values are comparable for equality and the `addressof` operator
is monomorphic. Function-pointer values can be explicitly coerced to and from
integers (which, in particular, is necessary when loading/storing to the heap
since the heap only provides integer types). For security and safety reasons,
Expand All @@ -266,16 +266,16 @@ All basic data types allow literal values of that data type. See the
## Expressions with control flow

Expression trees offer significant size reduction by avoiding the need for
`SetLocal`/`GetLocal` pairs in the common case of an expression with only one,
`set_local`/`get_local` pairs in the common case of an expression with only one,
immediate use. The following primitives provide AST nodes that express
control flow and thus allow more opportunities to build bigger expression trees
and further reduce `SetLocal`/`GetLocal` usage (which constitute 30-40% of total
and further reduce `set_local`/`get_local` usage (which constitute 30-40% of total
bytes in the [polyfill prototype](https://github.com/WebAssembly/polyfill-prototype-1)).
Additionally, these primitives are useful building blocks for
WebAssembly-generators (including the JavaScript polyfill).

* Comma - evaluate and ignore the result of the first operand, evaluate and return the second operand
* Conditional - basically ternary ?: operator
* comma - evaluate and ignore the result of the first operand, evaluate and return the second operand
* conditional - basically ternary ?: operator

New operands should be considered which allow measurably greater expression-tree-building
opportunities.
Expand All @@ -288,35 +288,35 @@ that overflows conforms to the standard wrap-around semantics.
All comparison operations yield 32-bit integer results with 1 representing true
and 0 representing false.

* Int32Add - signed-less addition
* Int32Sub - signed-less subtraction
* Int32Mul - signed-less multiplication (lower 32-bits)
* Int32SDiv - signed division
* Int32UDiv - unsigned division
* Int32SRem - signed remainder
* Int32URem - unsigned remainder
* Int32And - signed-less logical and
* Int32Ior - signed-less inclusive or
* Int32Xor - signed-less exclusive or
* Int32Shl - signed-less shift left
* Int32Shr - unsigned shift right
* Int32Sar - signed arithmetic shift right
* Int32Eq - signed-less compare equal
* Int32Slt - signed less than
* Int32Sle - signed less than or equal
* Int32Ult - unsigned less than
* Int32Ule - unsigned less than or equal
* Int32Clz - count leading zeroes (defined for all values, including 0)
* Int32Ctz - count trailing zeroes (defined for all values, including 0)
* Int32Popcnt - count number of ones
* int32.add - signed-less addition
* int32.sub - signed-less subtraction
* int32.mul - signed-less multiplication (lower 32-bits)
* int32.sdiv - signed division
* int32.udiv - unsigned division
* int32.srem - signed remainder
* int32.urem - unsigned remainder
* int32.and - signed-less logical and
* int32.ior - signed-less inclusive or
* int32.xor - signed-less exclusive or
* int32.shl - signed-less shift left
* int32.shr - unsigned shift right
* int32.sar - signed arithmetic shift right
* int32.eq - signed-less compare equal
* int32.slt - signed less than
* int32.sle - signed less than or equal
* int32.ult - unsigned less than
* int32.ule - unsigned less than or equal
* int32.clz - count leading zeroes (defined for all values, including 0)
* int32.ctz - count trailing zeroes (defined for all values, including 0)
* int32.popcnt - count number of ones

Division or remainder by zero traps.
Signed division overflow (`INT32_MIN / -1`) traps. Signed remainder with a
non-zero denominator always returns the correct value, even when the
corresponding division would trap.

Shifts interpret their shift count operand as an unsigned value. When the
shift count is at least the bitwidth of the shift, Shl and Shr return 0,
shift count is at least the bitwidth of the shift, shl and shr return 0,
and Sar returns 0 if the value being shifted is non-negative, and -1 otherwise.

Note that greater-than and greater-than-or-equal operations are not required,
Expand Down Expand Up @@ -347,58 +347,58 @@ Floating point arithmetic follows the IEEE-754 standard, except that:
WebAssembly includes enough functionality to support reasonable library
implementations of the remaining required operations.

* Float32Add - addition
* Float32Sub - subtraction
* Float32Mul - multiplication
* Float32Div - division
* Float32Abs - absolute value
* Float32Neg - negation
* Float32Copysign - copysign
* Float32Ceil - ceiling operation
* Float32Floor - floor operation
* Float32Trunc - round to nearest integer towards zero
* Float32NearestInt - round to nearest integer, ties to even
* Float32Eq - compare equal
* Float32Lt - less than
* Float32Le - less than or equal
* Float32Sqrt - square root
* Float32Min - minimum (binary operator); if either operand is NaN, returns NaN
* Float32Max - maximum (binary operator); if either operand is NaN, returns NaN

* Float64Add - addition
* Float64Sub - subtraction
* Float64Mul - multiplication
* Float64Div - division
* Float64Abs - absolute value
* Float64Neg - negation
* Float64Copysign - copysign
* Float64Ceil - ceiling operation
* Float64Floor - floor operation
* Float64Trunc - round to nearest integer towards zero
* Float64NearestInt - round to nearest integer, ties to even
* Float64Eq - compare equal
* Float64Lt - less than
* Float64Le - less than or equal
* Float64Sqrt - square root
* Float64Min - minimum (binary operator); if either operand is NaN, returns NaN
* Float64Max - maximum (binary operator); if either operand is NaN, returns NaN
* float32.add - addition
* float32.sub - subtraction
* float32.mul - multiplication
* float32.div - division
* float32.abs - absolute value
* float32.neg - negation
* float32.copysign - copysign
* float32.ceil - ceiling operation
* float32.floor - floor operation
* float32.trunc - round to nearest integer towards zero
* float32.nearestint - round to nearest integer, ties to even
* float32.eq - compare equal
* float32.lt - less than
* float32.le - less than or equal
* float32.sqrt - square root
* float32.min - minimum (binary operator); if either operand is NaN, returns NaN
* float32.max - maximum (binary operator); if either operand is NaN, returns NaN

* float64.add - addition
* float64.sub - subtraction
* float64.mul - multiplication
* float64.div - division
* float64.abs - absolute value
* float64.neg - negation
* float64.copysign - copysign
* float64.ceil - ceiling operation
* float64.floor - floor operation
* float64.trunc - round to nearest integer towards zero
* float64.nearestint - round to nearest integer, ties to even
* float64.eq - compare equal
* float64.lt - less than
* float64.le - less than or equal
* float64.sqrt - square root
* float64.min - minimum (binary operator); if either operand is NaN, returns NaN
* float64.max - maximum (binary operator); if either operand is NaN, returns NaN

Min and Max operations treat -0 as being effectively less than 0.

## Datatype conversions, truncations, reinterpretations, promotions, and demotions

* Int32FromFloat64 - truncate a 64-bit float to a signed integer
* Int32FromFloat32 - truncate a 32-bit float to a signed integer
* Uint32FromFloat64 - truncate a 64-bit float to an unsigned integer
* Uint32FromFloat32 - truncate a 32-bit float to an unsigned integer
* Int32FromFloat32Bits - reinterpret the bits of a 32-bit float as a 32-bit integer
* Float64FromFloat32 - promote a 32-bit float to a 64-bit float
* Float64FromInt32 - convert a signed integer to a 64-bit float
* Float64FromUInt32 - convert an unsigned integer to a 64-bit float
* Float32FromFloat64 - demote a 64-bit float to a 32-bit float
* Float32FromInt32 - convert a signed integer to a 32-bit float
* Float32FromUInt32 - convert an unsigned integer to a 32-bit float
* Float32FromInt32Bits - reinterpret the bits of a 32-bit integer as a 32-bit float
* sint32_from_float64 - truncate a 64-bit float to a signed integer
* sint32_from_float32 - truncate a 32-bit float to a signed integer
* uint32_from_float64 - truncate a 64-bit float to an unsigned integer
* uint32_from_float32 - truncate a 32-bit float to an unsigned integer
* int32_from_float32_bits - reinterpret the bits of a 32-bit float as a 32-bit integer
* float64_from_float32 - promote a 32-bit float to a 64-bit float
* float64_from_sint32 - convert a signed integer to a 64-bit float
* float64_from_uint32 - convert an unsigned integer to a 64-bit float
* float32_from_float64 - demote a 64-bit float to a 32-bit float
* float32_from_sint32 - convert a signed integer to a 32-bit float
* float32_from_uint32 - convert an unsigned integer to a 32-bit float
* float32_from_int32_bits - reinterpret the bits of a 32-bit integer as a 32-bit float

Promotion and demotion of floating point values always succeeds.
Demotion of floating point values uses round-to-nearest ties-to-even rounding,
Expand Down
Loading