Instructions¶
WebAssembly computation is performed by executing individual instructions.
Numeric Instructions¶
Numeric instructions are defined in terms of the generic numeric operators. The mapping of numeric instructions to their underlying operators is expressed by the following definition:
And for conversion operators:
Where the underlying operators are partial, the corresponding instruction will trap when the result is not defined. Where the underlying operators are non-deterministic, because they may return one of multiple possible NaN values, so are the corresponding instructions.
Note
For example, the result of instruction \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{add}}\) applied to operands \(i_1, i_2\) invokes \(\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{add}}_{\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}}(i_1, i_2)\), which maps to the generic \(\href{../exec/numerics.html#op-iadd}{\mathrm{iadd}}_{32}(i_1, i_2)\) via the above definition. Similarly, \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i64}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{trunc}}\mathsf{\_}\href{../syntax/types.html#syntax-valtype}{\mathsf{f32}}\mathsf{\_s}\) applied to \(z\) invokes \(\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{trunc}}^{\mathsf{s}}_{\href{../syntax/types.html#syntax-valtype}{\mathsf{f32}},\href{../syntax/types.html#syntax-valtype}{\mathsf{i64}}}(z)\), which maps to the generic \(\href{../exec/numerics.html#op-trunc-s}{\mathrm{trunc}^{\mathsf{s}}}_{32,64}(z)\).
\(t\mathsf{.}\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~c\)¶
Push the value \(t.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~c\) to the stack.
Note
No formal reduction rule is required for this instruction, since \(\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}\) instructions already are values.
\(t\mathsf{.}\href{../syntax/instructions.html#syntax-unop}{\mathit{unop}}\)¶
Assert: due to validation, a value of value type \(t\) is on the top of the stack.
Pop the value \(t.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~c_1\) from the stack.
If \(\href{../exec/instructions.html#exec-instr-numeric}{\mathit{unop}}_t(c_1)\) is defined, then:
Let \(c\) be a possible result of computing \(\href{../exec/instructions.html#exec-instr-numeric}{\mathit{unop}}_t(c_1)\).
Push the value \(t.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~c\) to the stack.
Else:
Trap.
\(t\mathsf{.}\href{../syntax/instructions.html#syntax-binop}{\mathit{binop}}\)¶
Assert: due to validation, two values of value type \(t\) are on the top of the stack.
Pop the value \(t.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~c_2\) from the stack.
Pop the value \(t.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~c_1\) from the stack.
If \(\href{../exec/instructions.html#exec-instr-numeric}{\mathit{binop}}_t(c_1, c_2)\) is defined, then:
Let \(c\) be a possible result of computing \(\href{../exec/instructions.html#exec-instr-numeric}{\mathit{binop}}_t(c_1, c_2)\).
Push the value \(t.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~c\) to the stack.
Else:
Trap.
\(t\mathsf{.}\href{../syntax/instructions.html#syntax-testop}{\mathit{testop}}\)¶
Assert: due to validation, a value of value type \(t\) is on the top of the stack.
Pop the value \(t.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~c_1\) from the stack.
Let \(c\) be the result of computing \(\href{../exec/instructions.html#exec-instr-numeric}{\mathit{testop}}_t(c_1)\).
Push the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~c\) to the stack.
\(t\mathsf{.}\href{../syntax/instructions.html#syntax-relop}{\mathit{relop}}\)¶
Assert: due to validation, two values of value type \(t\) are on the top of the stack.
Pop the value \(t.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~c_2\) from the stack.
Pop the value \(t.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~c_1\) from the stack.
Let \(c\) be the result of computing \(\href{../exec/instructions.html#exec-instr-numeric}{\mathit{relop}}_t(c_1, c_2)\).
Push the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~c\) to the stack.
\(t_2\mathsf{.}\href{../syntax/instructions.html#syntax-cvtop}{\mathit{cvtop}}\mathsf{\_}t_1\mathsf{\_}\href{../syntax/instructions.html#syntax-sx}{\mathit{sx}}^?\)¶
Assert: due to validation, a value of value type \(t_1\) is on the top of the stack.
Pop the value \(t_1.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~c_1\) from the stack.
If \(\href{../syntax/instructions.html#syntax-cvtop}{\mathit{cvtop}}^{\href{../syntax/instructions.html#syntax-sx}{\mathit{sx}}^?}_{t_1,t_2}(c_1)\) is defined:
Let \(c_2\) be a possible result of computing \(\href{../syntax/instructions.html#syntax-cvtop}{\mathit{cvtop}}^{\href{../syntax/instructions.html#syntax-sx}{\mathit{sx}}^?}_{t_1,t_2}(c_1)\).
Push the value \(t_2.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~c_2\) to the stack.
Else:
Trap.
Reference Instructions¶
\(\href{../syntax/instructions.html#syntax-instr-ref}{\mathsf{ref.null}}~x\)¶
Assert: due to validation, the defined type \(F.\href{../exec/runtime.html#syntax-frame}{\mathsf{module}}.\href{../exec/runtime.html#syntax-moduleinst}{\mathsf{types}}[x]\) exists.
Let \(\href{../valid/conventions.html#syntax-deftype}{\mathit{deftype}}\) be the defined type \(F.\href{../exec/runtime.html#syntax-frame}{\mathsf{module}}.\href{../exec/runtime.html#syntax-moduleinst}{\mathsf{types}}[x]\).
Push the value \(\href{../syntax/instructions.html#syntax-instr-ref}{\mathsf{ref.null}}~\href{../valid/conventions.html#syntax-deftype}{\mathit{deftype}}\) to the stack.
Note
No formal reduction rule is required for the case \(\href{../syntax/instructions.html#syntax-instr-ref}{\mathsf{ref.null}}\) \(\href{../syntax/types.html#syntax-absheaptype}{\mathit{absheaptype}}\), since the instruction form is already a value.
\(\href{../syntax/instructions.html#syntax-instr-ref}{\mathsf{ref.func}}~x\)¶
Assert: due to validation, \(F.\href{../exec/runtime.html#syntax-frame}{\mathsf{module}}.\href{../exec/runtime.html#syntax-moduleinst}{\mathsf{funcaddrs}}[x]\) exists.
Let \(a\) be the function address \(F.\href{../exec/runtime.html#syntax-frame}{\mathsf{module}}.\href{../exec/runtime.html#syntax-moduleinst}{\mathsf{funcaddrs}}[x]\).
Push the value \(\href{../exec/runtime.html#syntax-ref}{\mathsf{ref{.}func}}~a\) to the stack.
\(\href{../syntax/instructions.html#syntax-instr-ref}{\mathsf{ref.is\_null}}\)¶
Assert: due to validation, a reference value is on the top of the stack.
Pop the value \(\href{../exec/runtime.html#syntax-ref}{\mathit{ref}}\) from the stack.
If \(\href{../exec/runtime.html#syntax-ref}{\mathit{ref}}\) is \(\href{../syntax/instructions.html#syntax-instr-ref}{\mathsf{ref.null}}~\mathit{ht}\), then:
Push the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~1\) to the stack.
Else:
Push the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~0\) to the stack.
\(\href{../syntax/instructions.html#syntax-instr-ref}{\mathsf{ref.as\_non\_null}}\)¶
Assert: due to validation, a reference value is on the top of the stack.
Pop the value \(\href{../exec/runtime.html#syntax-ref}{\mathit{ref}}\) from the stack.
If \(\href{../exec/runtime.html#syntax-ref}{\mathit{ref}}\) is \(\href{../syntax/instructions.html#syntax-instr-ref}{\mathsf{ref.null}}~\mathit{ht}\), then:
Trap.
Push the value \(\href{../exec/runtime.html#syntax-ref}{\mathit{ref}}\) back to the stack.
\(\href{../syntax/instructions.html#syntax-instr-ref}{\mathsf{ref.eq}}\)¶
Assert: due to validation, two reference values are on the top of the stack.
Pop the value \(\href{../exec/runtime.html#syntax-ref}{\mathit{ref}}_2\) from the stack.
Pop the value \(\href{../exec/runtime.html#syntax-ref}{\mathit{ref}}_1\) from the stack.
If \(\href{../exec/runtime.html#syntax-ref}{\mathit{ref}}_1\) is the same as \(\href{../exec/runtime.html#syntax-ref}{\mathit{ref}}_2\), then:
Push the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~1\) to the stack.
Else:
Push the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~0\) to the stack.
\(\href{../syntax/instructions.html#syntax-instr-ref}{\mathsf{ref.test}}~\mathit{rt}\)¶
Let \(\mathit{rt}_1\) be the reference type \(\href{../exec/types.html#type-inst}{\mathrm{clos}}_{F.\href{../exec/runtime.html#syntax-frame}{\mathsf{module}}}(\mathit{rt})\).
Assert: due to validation, \(\mathit{rt}_1\) is closed.
Assert: due to validation, a reference value is on the top of the stack.
Pop the value \(\href{../exec/runtime.html#syntax-ref}{\mathit{ref}}\) from the stack.
Assert: due to validation, the reference value is valid with some reference type.
Let \(\mathit{rt}_2\) be the reference type of \(\href{../exec/runtime.html#syntax-ref}{\mathit{ref}}\).
If the reference type \(\mathit{rt}_2\) matches \(\mathit{rt}_1\), then:
Push the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~1\) to the stack.
Else:
Push the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~0\) to the stack.
\(\href{../syntax/instructions.html#syntax-instr-ref}{\mathsf{ref.cast}}~\mathit{rt}\)¶
Let \(\mathit{rt}_1\) be the reference type \(\href{../exec/types.html#type-inst}{\mathrm{clos}}_{F.\href{../exec/runtime.html#syntax-frame}{\mathsf{module}}}(\mathit{rt})\).
Assert: due to validation, \(\mathit{rt}_1\) is closed.
Assert: due to validation, a reference value is on the top of the stack.
Pop the value \(\href{../exec/runtime.html#syntax-ref}{\mathit{ref}}\) from the stack.
Assert: due to validation, the reference value is valid with some reference type.
Let \(\mathit{rt}_2\) be the reference type of \(\href{../exec/runtime.html#syntax-ref}{\mathit{ref}}\).
If the reference type \(\mathit{rt}_2\) matches \(\mathit{rt}_1\), then:
Push the value \(\href{../exec/runtime.html#syntax-ref}{\mathit{ref}}\) back to the stack.
Else:
Trap.
\(\href{../syntax/instructions.html#syntax-instr-i31}{\mathsf{ref.i31}}\)¶
Assert: due to validation, a value of type \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}\) is on the top of the stack.
Pop the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~i\) from the stack.
Let \(j\) be the result of computing \(\href{../exec/numerics.html#op-wrap}{\mathrm{wrap}}_{32,31}(i)\).
Push the reference value \((\href{../exec/runtime.html#syntax-ref}{\mathsf{ref{.}i31}}~j)\) to the stack.
\(\href{../syntax/instructions.html#syntax-instr-i31}{\mathsf{i31.get}}\mathsf{\_}\href{../syntax/instructions.html#syntax-sx}{\mathit{sx}}\)¶
Assert: due to validation, a value of type \((\href{../syntax/types.html#syntax-reftype}{\mathsf{ref}}~\href{../syntax/types.html#syntax-reftype}{\mathsf{null}}~\href{../syntax/types.html#syntax-heaptype}{\mathsf{i31}})\) is on the top of the stack.
Pop the value \(\href{../exec/runtime.html#syntax-ref}{\mathit{ref}}\) from the stack.
If \(\href{../exec/runtime.html#syntax-ref}{\mathit{ref}}\) is \(\href{../syntax/instructions.html#syntax-instr-ref}{\mathsf{ref.null}}~t\), then:
Trap.
Assert: due to validation, a \(\href{../exec/runtime.html#syntax-ref}{\mathit{ref}}\) is a scalar reference.
Let \(\href{../exec/runtime.html#syntax-ref}{\mathsf{ref{.}i31}}~i\) be the reference value \(\href{../exec/runtime.html#syntax-ref}{\mathit{ref}}\).
Let \(j\) be the result of computing \(\href{../exec/numerics.html#op-extend-u}{\mathrm{extend}}^{\href{../syntax/instructions.html#syntax-sx}{\mathit{sx}}}_{31,32}(i)\).
Push the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~j\) to the stack.
\(\href{../syntax/instructions.html#syntax-instr-struct}{\mathsf{struct.new}}~x\)¶
Assert: due to validation, the defined type \(F.\href{../exec/runtime.html#syntax-frame}{\mathsf{module}}.\href{../exec/runtime.html#syntax-moduleinst}{\mathsf{types}}[x]\) exists.
Let \(\href{../valid/conventions.html#syntax-deftype}{\mathit{deftype}}\) be the defined type \(F.\href{../exec/runtime.html#syntax-frame}{\mathsf{module}}.\href{../exec/runtime.html#syntax-moduleinst}{\mathsf{types}}[x]\).
Assert: due to validation, the expansion of \(\href{../valid/conventions.html#syntax-deftype}{\mathit{deftype}}\) is a structure type.
Let \(\href{../syntax/types.html#syntax-comptype}{\mathsf{struct}}~\mathit{ft}^\ast\) be the expanded structure type of \(\href{../valid/conventions.html#syntax-deftype}{\mathit{deftype}}\).
Let \(n\) be the length of the field type sequence \(\mathit{ft}^\ast\).
Assert: due to validation, \(n\) values are on the top of the stack.
Pop the \(n\) values \(\href{../exec/runtime.html#syntax-val}{\mathit{val}}^\ast\) from the stack.
For every value \(\href{../exec/runtime.html#syntax-val}{\mathit{val}}_i\) in \(\href{../exec/runtime.html#syntax-val}{\mathit{val}}^\ast\) and corresponding field type \(\mathit{ft}_i\) in \(\mathit{ft}^\ast\):
Let \(\href{../exec/runtime.html#syntax-fieldval}{\mathit{fieldval}}_i\) be the result of computing \(\href{../exec/runtime.html#aux-packval}{\mathrm{pack}}_{\mathit{ft}_i}(\href{../exec/runtime.html#syntax-val}{\mathit{val}}_i))\).
Let \(\href{../exec/runtime.html#syntax-fieldval}{\mathit{fieldval}}^\ast\) the concatenation of all field values \(\href{../exec/runtime.html#syntax-fieldval}{\mathit{fieldval}}_i\).
Let \(\mathit{si}\) be the structure instance \(\{\href{../exec/runtime.html#syntax-structinst}{\mathsf{type}}~\href{../valid/conventions.html#syntax-deftype}{\mathit{deftype}}, \href{../exec/runtime.html#syntax-structinst}{\mathsf{fields}}~\href{../exec/runtime.html#syntax-fieldval}{\mathit{fieldval}}^\ast\}\).
Let \(a\) be the length of \(S.\href{../exec/runtime.html#syntax-store}{\mathsf{structs}}\).
Append \(\mathit{si}\) to \(S.\href{../exec/runtime.html#syntax-store}{\mathsf{structs}}\).
Push the structure reference \(\href{../exec/runtime.html#syntax-ref}{\mathsf{ref{.}struct}}~a\) to the stack.
\(\href{../syntax/instructions.html#syntax-instr-struct}{\mathsf{struct.new\_default}}~x\)¶
Assert: due to validation, the defined type \(F.\href{../exec/runtime.html#syntax-frame}{\mathsf{module}}.\href{../exec/runtime.html#syntax-moduleinst}{\mathsf{types}}[x]\) exists.
Let \(\href{../valid/conventions.html#syntax-deftype}{\mathit{deftype}}\) be the defined type \(F.\href{../exec/runtime.html#syntax-frame}{\mathsf{module}}.\href{../exec/runtime.html#syntax-moduleinst}{\mathsf{types}}[x]\).
Assert: due to validation, the expansion of \(\href{../valid/conventions.html#syntax-deftype}{\mathit{deftype}}\) is a structure type.
Let \(\href{../syntax/types.html#syntax-comptype}{\mathsf{struct}}~\mathit{ft}^\ast\) be the expanded structure type of \(\href{../valid/conventions.html#syntax-deftype}{\mathit{deftype}}\).
Let \(n\) be the length of the field type sequence \(\mathit{ft}^\ast\).
For every field type \(\mathit{ft}_i\) in \(\mathit{ft}^\ast\):
Let \(t_i\) be the value type \(\href{../syntax/types.html#aux-unpacktype}{\mathrm{unpack}}(\mathit{ft}_i)\).
Assert: due to validation, \(\href{../exec/runtime.html#default-val}{\mathrm{default}}_{t_i}\) is defined.
Push the value \(\href{../exec/runtime.html#default-val}{\mathrm{default}}_{t_i}\) to the stack.
Execute the instruction \((\href{../syntax/instructions.html#syntax-instr-struct}{\mathsf{struct.new}}~x)\).
\(\href{../syntax/instructions.html#syntax-instr-struct}{\mathsf{struct.get}}\mathsf{\_}\href{../syntax/instructions.html#syntax-sx}{\mathit{sx}}^?~x~y\)¶
Assert: due to validation, the defined type \(F.\href{../exec/runtime.html#syntax-frame}{\mathsf{module}}.\href{../exec/runtime.html#syntax-moduleinst}{\mathsf{types}}[x]\) exists.
Let \(\href{../valid/conventions.html#syntax-deftype}{\mathit{deftype}}\) be the defined type \(F.\href{../exec/runtime.html#syntax-frame}{\mathsf{module}}.\href{../exec/runtime.html#syntax-moduleinst}{\mathsf{types}}[x]\).
Assert: due to validation, the expansion of \(\href{../valid/conventions.html#syntax-deftype}{\mathit{deftype}}\) is a structure type with at least \(y + 1\) fields.
Let \(\href{../syntax/types.html#syntax-comptype}{\mathsf{struct}}~\mathit{ft}^\ast\) be the expanded structure type of \(\href{../valid/conventions.html#syntax-deftype}{\mathit{deftype}}\).
Let \(\mathit{ft}_y\) be the \(y\)-th field type of \(\mathit{ft}^\ast\).
Assert: due to validation, a value of type \((\href{../syntax/types.html#syntax-reftype}{\mathsf{ref}}~\href{../syntax/types.html#syntax-reftype}{\mathsf{null}}~x)\) is on the top of the stack.
Pop the value \(\href{../exec/runtime.html#syntax-ref}{\mathit{ref}}\) from the stack.
If \(\href{../exec/runtime.html#syntax-ref}{\mathit{ref}}\) is \(\href{../syntax/instructions.html#syntax-instr-ref}{\mathsf{ref.null}}~t\), then:
Trap.
Assert: due to validation, a \(\href{../exec/runtime.html#syntax-ref}{\mathit{ref}}\) is a structure reference.
Let \(\href{../exec/runtime.html#syntax-ref}{\mathsf{ref{.}struct}}~a\) be the reference value \(\href{../exec/runtime.html#syntax-ref}{\mathit{ref}}\).
Assert: due to validation, the structure instance \(S.\href{../exec/runtime.html#syntax-store}{\mathsf{structs}}[a]\) exists and has at least \(y + 1\) fields.
Let \(\href{../exec/runtime.html#syntax-fieldval}{\mathit{fieldval}}\) be the field value \(S.\href{../exec/runtime.html#syntax-store}{\mathsf{structs}}[a].\href{../exec/runtime.html#syntax-structinst}{\mathsf{fields}}[y]\).
Let \(\href{../exec/runtime.html#syntax-val}{\mathit{val}}\) be the result of computing \(\href{../exec/runtime.html#aux-unpackval}{\mathrm{unpack}}^{\href{../syntax/instructions.html#syntax-sx}{\mathit{sx}}^?}_{\mathit{ft}_y}(\href{../exec/runtime.html#syntax-fieldval}{\mathit{fieldval}}))\).
Push the value \(\href{../exec/runtime.html#syntax-val}{\mathit{val}}\) to the stack.
\(\href{../syntax/instructions.html#syntax-instr-struct}{\mathsf{struct.set}}~x~y\)¶
Assert: due to validation, the defined type \(F.\href{../exec/runtime.html#syntax-frame}{\mathsf{module}}.\href{../exec/runtime.html#syntax-moduleinst}{\mathsf{types}}[x]\) exists.
Let \(\href{../valid/conventions.html#syntax-deftype}{\mathit{deftype}}\) be the defined type \(F.\href{../exec/runtime.html#syntax-frame}{\mathsf{module}}.\href{../exec/runtime.html#syntax-moduleinst}{\mathsf{types}}[x]\).
Assert: due to validation, the expansion of \(\href{../valid/conventions.html#syntax-deftype}{\mathit{deftype}}\) is a structure type with at least \(y + 1\) fields.
Let \(\href{../syntax/types.html#syntax-comptype}{\mathsf{struct}}~\mathit{ft}^\ast\) be the expanded structure type of \(\href{../valid/conventions.html#syntax-deftype}{\mathit{deftype}}\).
Let \(\mathit{ft}_y\) be the \(y\)-th field type of \(\mathit{ft}^\ast\).
Assert: due to validation, a value is on the top of the stack.
Pop the value \(\href{../exec/runtime.html#syntax-val}{\mathit{val}}\) from the stack.
Assert: due to validation, a value of type \((\href{../syntax/types.html#syntax-reftype}{\mathsf{ref}}~\href{../syntax/types.html#syntax-reftype}{\mathsf{null}}~x)\) is on the top of the stack.
Pop the value \(\href{../exec/runtime.html#syntax-ref}{\mathit{ref}}\) from the stack.
If \(\href{../exec/runtime.html#syntax-ref}{\mathit{ref}}\) is \(\href{../syntax/instructions.html#syntax-instr-ref}{\mathsf{ref.null}}~t\), then:
Trap.
Assert: due to validation, a \(\href{../exec/runtime.html#syntax-ref}{\mathit{ref}}\) is a structure reference.
Let \(\href{../exec/runtime.html#syntax-ref}{\mathsf{ref{.}struct}}~a\) be the reference value \(\href{../exec/runtime.html#syntax-ref}{\mathit{ref}}\).
Assert: due to validation, the structure instance \(S.\href{../exec/runtime.html#syntax-store}{\mathsf{structs}}[a]\) exists and has at least \(y + 1\) fields.
Let \(\href{../exec/runtime.html#syntax-fieldval}{\mathit{fieldval}}\) be the result of computing \(\href{../exec/runtime.html#aux-packval}{\mathrm{pack}}_{\mathit{ft}_y}(\href{../exec/runtime.html#syntax-val}{\mathit{val}}))\).
Replace the field value \(S.\href{../exec/runtime.html#syntax-store}{\mathsf{structs}}[a].\href{../exec/runtime.html#syntax-structinst}{\mathsf{fields}}[y]\) with \(\href{../exec/runtime.html#syntax-fieldval}{\mathit{fieldval}}\).
\(\href{../syntax/instructions.html#syntax-instr-array}{\mathsf{array.new}}~x\)¶
Assert: due to validation, a value of type \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}\) is on the top of the stack.
Pop the value \((\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~n)\) from the stack.
Assert: due to validation, a value is on the top of the stack.
Pop the value \(\href{../exec/runtime.html#syntax-val}{\mathit{val}}\) from the stack.
Push the value \(\href{../exec/runtime.html#syntax-val}{\mathit{val}}\) to the stack \(n\) times.
Execute the instruction \((\href{../syntax/instructions.html#syntax-instr-array}{\mathsf{array.new\_fixed}}~x~n)\).
\(\href{../syntax/instructions.html#syntax-instr-array}{\mathsf{array.new\_default}}~x\)¶
Assert: due to validation, the defined type \(F.\href{../exec/runtime.html#syntax-frame}{\mathsf{module}}.\href{../exec/runtime.html#syntax-moduleinst}{\mathsf{types}}[x]\) exists.
Let \(\href{../valid/conventions.html#syntax-deftype}{\mathit{deftype}}\) be the defined type \(F.\href{../exec/runtime.html#syntax-frame}{\mathsf{module}}.\href{../exec/runtime.html#syntax-moduleinst}{\mathsf{types}}[x]\).
Assert: due to validation, the expansion of \(\href{../valid/conventions.html#syntax-deftype}{\mathit{deftype}}\) is an array type.
Let \(\href{../syntax/types.html#syntax-comptype}{\mathsf{array}}~\mathit{ft}\) be the expanded array type of \(\href{../valid/conventions.html#syntax-deftype}{\mathit{deftype}}\).
Assert: due to validation, a value of type \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}\) is on the top of the stack.
Pop the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~n\) from the stack.
Let \(t\) be the value type \(\href{../syntax/types.html#aux-unpacktype}{\mathrm{unpack}}(\mathit{ft})\).
Assert: due to validation, \(\href{../exec/runtime.html#default-val}{\mathrm{default}}_t\) is defined.
Push the value \(\href{../exec/runtime.html#default-val}{\mathrm{default}}_t\) to the stack \(n\) times.
Execute the instruction \((\href{../syntax/instructions.html#syntax-instr-array}{\mathsf{array.new\_fixed}}~x~n)\).
\(\href{../syntax/instructions.html#syntax-instr-array}{\mathsf{array.new\_fixed}}~x~n\)¶
Assert: due to validation, the defined type \(F.\href{../exec/runtime.html#syntax-frame}{\mathsf{module}}.\href{../exec/runtime.html#syntax-moduleinst}{\mathsf{types}}[x]\) exists.
Let \(\href{../valid/conventions.html#syntax-deftype}{\mathit{deftype}}\) be the defined type \(F.\href{../exec/runtime.html#syntax-frame}{\mathsf{module}}.\href{../exec/runtime.html#syntax-moduleinst}{\mathsf{types}}[x]\).
Assert: due to validation, the expansion of \(\href{../valid/conventions.html#syntax-deftype}{\mathit{deftype}}\) is a array type.
Let \(\href{../syntax/types.html#syntax-comptype}{\mathsf{array}}~\mathit{ft}\) be the expanded array type of \(\href{../valid/conventions.html#syntax-deftype}{\mathit{deftype}}\).
Assert: due to validation, \(n\) values are on the top of the stack.
Pop the \(n\) values \(\href{../exec/runtime.html#syntax-val}{\mathit{val}}^\ast\) from the stack.
For every value \(\href{../exec/runtime.html#syntax-val}{\mathit{val}}_i\) in \(\href{../exec/runtime.html#syntax-val}{\mathit{val}}^\ast\):
Let \(\href{../exec/runtime.html#syntax-fieldval}{\mathit{fieldval}}_i\) be the result of computing \(\href{../exec/runtime.html#aux-packval}{\mathrm{pack}}_{\mathit{ft}}(\href{../exec/runtime.html#syntax-val}{\mathit{val}}_i))\).
Let \(\href{../exec/runtime.html#syntax-fieldval}{\mathit{fieldval}}^\ast\) be the concatenation of all field values \(\href{../exec/runtime.html#syntax-fieldval}{\mathit{fieldval}}_i\).
Let \(\mathit{ai}\) be the array instance \(\{\href{../exec/runtime.html#syntax-arrayinst}{\mathsf{type}}~\href{../valid/conventions.html#syntax-deftype}{\mathit{deftype}}, \href{../exec/runtime.html#syntax-arrayinst}{\mathsf{fields}}~\href{../exec/runtime.html#syntax-fieldval}{\mathit{fieldval}}^\ast\}\).
Let \(a\) be the length of \(S.\href{../exec/runtime.html#syntax-store}{\mathsf{arrays}}\).
Append \(\mathit{ai}\) to \(S.\href{../exec/runtime.html#syntax-store}{\mathsf{arrays}}\).
Push the array reference \(\href{../exec/runtime.html#syntax-ref}{\mathsf{ref{.}array}}~a\) to the stack.
\(\href{../syntax/instructions.html#syntax-instr-array}{\mathsf{array.new\_data}}~x~y\)¶
Assert: due to validation, the defined type \(F.\href{../exec/runtime.html#syntax-frame}{\mathsf{module}}.\href{../exec/runtime.html#syntax-moduleinst}{\mathsf{types}}[x]\) exists.
Let \(\href{../valid/conventions.html#syntax-deftype}{\mathit{deftype}}\) be the defined type \(F.\href{../exec/runtime.html#syntax-frame}{\mathsf{module}}.\href{../exec/runtime.html#syntax-moduleinst}{\mathsf{types}}[x]\).
Assert: due to validation, the expansion of \(\href{../valid/conventions.html#syntax-deftype}{\mathit{deftype}}\) is an array type.
Let \(\href{../syntax/types.html#syntax-comptype}{\mathsf{array}}~\mathit{ft}\) be the expanded array type of \(\href{../valid/conventions.html#syntax-deftype}{\mathit{deftype}}\).
Assert: due to validation, the data address \(F.\href{../exec/runtime.html#syntax-frame}{\mathsf{module}}.\href{../exec/runtime.html#syntax-moduleinst}{\mathsf{dataaddrs}}[y]\) exists.
Let \(\mathit{da}\) be the data address \(F.\href{../exec/runtime.html#syntax-frame}{\mathsf{module}}.\href{../exec/runtime.html#syntax-moduleinst}{\mathsf{dataaddrs}}[y]\).
Assert: due to validation, the data instance \(S.\href{../exec/runtime.html#syntax-store}{\mathsf{datas}}[\mathit{da}]\) exists.
Let \(\href{../exec/runtime.html#syntax-datainst}{\mathit{datainst}}\) be the data instance \(S.\href{../exec/runtime.html#syntax-store}{\mathsf{datas}}[\mathit{da}]\).
Assert: due to validation, two values of type \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}\) are on the top of the stack.
Pop the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~n\) from the stack.
Pop the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~s\) from the stack.
Assert: due to validation, the field type \(\mathit{ft}\) has a defined bit width.
Let \(z\) be the bit width of field type \(\mathit{ft}\) divided by eight.
If the sum of \(s\) and \(n\) times \(z\) is larger than the length of \(\href{../exec/runtime.html#syntax-datainst}{\mathit{datainst}}.\href{../exec/runtime.html#syntax-datainst}{\mathsf{data}}\), then:
Trap.
Let \(b^\ast\) be the byte sequence \(\href{../exec/runtime.html#syntax-datainst}{\mathit{datainst}}.\href{../exec/runtime.html#syntax-datainst}{\mathsf{data}}[s \href{../syntax/conventions.html#notation-slice}{\mathrel{\mathbf{:}}} n \cdot z]\).
Let \(t\) be the value type \(\href{../syntax/types.html#aux-unpacktype}{\mathrm{unpack}}(\mathit{ft})\).
For each of the \(n\) consecutive subsequences \({b'}^z\) of \(b^\ast\):
Assert: due to validation, \(\href{../exec/numerics.html#aux-bytes}{\mathrm{bytes}}_{\mathit{ft}}\) is defined.
Let \(c_i\) be the constant for which \(\href{../exec/numerics.html#aux-bytes}{\mathrm{bytes}}_{\mathit{ft}}(c_i)\) is \({b'}^z\).
Push the value \(t.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~c_i\) to the stack.
Execute the instruction \((\href{../syntax/instructions.html#syntax-instr-array}{\mathsf{array.new\_fixed}}~x~n)\).
\(\href{../syntax/instructions.html#syntax-instr-array}{\mathsf{array.new\_elem}}~x~y\)¶
Assert: due to validation, the element address \(F.\href{../exec/runtime.html#syntax-frame}{\mathsf{module}}.\href{../exec/runtime.html#syntax-moduleinst}{\mathsf{elemaddrs}}[y]\) exists.
Let \(\mathit{ea}\) be the element address \(F.\href{../exec/runtime.html#syntax-frame}{\mathsf{module}}.\href{../exec/runtime.html#syntax-moduleinst}{\mathsf{elemaddrs}}[y]\).
Assert: due to validation, the element instance \(S.\href{../exec/runtime.html#syntax-store}{\mathsf{elems}}[\mathit{ea}]\) exists.
Let \(\href{../exec/runtime.html#syntax-eleminst}{\mathit{eleminst}}\) be the element instance \(S.\href{../exec/runtime.html#syntax-store}{\mathsf{elems}}[\mathit{ea}]\).
Assert: due to validation, two values of type \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}\) are on the top of the stack.
Pop the value \((\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~n)\) from the stack.
Pop the value \((\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~s)\) from the stack.
If the sum of \(s\) and \(n\) is larger than the length of \(\href{../exec/runtime.html#syntax-eleminst}{\mathit{eleminst}}.\href{../exec/runtime.html#syntax-eleminst}{\mathsf{elem}}\), then:
Trap.
Let \(\href{../exec/runtime.html#syntax-ref}{\mathit{ref}}^\ast\) be the reference sequence \(\href{../exec/runtime.html#syntax-eleminst}{\mathit{eleminst}}.\href{../exec/runtime.html#syntax-eleminst}{\mathsf{elem}}[s \href{../syntax/conventions.html#notation-slice}{\mathrel{\mathbf{:}}} n]\).
Push the references \(\href{../exec/runtime.html#syntax-ref}{\mathit{ref}}^\ast\) to the stack.
Execute the instruction \((\href{../syntax/instructions.html#syntax-instr-array}{\mathsf{array.new\_fixed}}~x~n)\).
\(\href{../syntax/instructions.html#syntax-instr-array}{\mathsf{array.get}}\mathsf{\_}\href{../syntax/instructions.html#syntax-sx}{\mathit{sx}}^?~x\)¶
Assert: due to validation, the defined type \(F.\href{../exec/runtime.html#syntax-frame}{\mathsf{module}}.\href{../exec/runtime.html#syntax-moduleinst}{\mathsf{types}}[x]\) exists.
Let \(\href{../valid/conventions.html#syntax-deftype}{\mathit{deftype}}\) be the defined type \(F.\href{../exec/runtime.html#syntax-frame}{\mathsf{module}}.\href{../exec/runtime.html#syntax-moduleinst}{\mathsf{types}}[x]\).
Assert: due to validation, the expansion of \(\href{../valid/conventions.html#syntax-deftype}{\mathit{deftype}}\) is an array type.
Let \(\href{../syntax/types.html#syntax-comptype}{\mathsf{array}}~\mathit{ft}\) be the expanded array type of \(\href{../valid/conventions.html#syntax-deftype}{\mathit{deftype}}\).
Assert: due to validation, a value of type \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}\) is on the top of the stack.
Pop the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~i\) from the stack.
Assert: due to validation, a value of type \((\href{../syntax/types.html#syntax-reftype}{\mathsf{ref}}~\href{../syntax/types.html#syntax-reftype}{\mathsf{null}}~x)\) is on the top of the stack.
Pop the value \(\href{../exec/runtime.html#syntax-ref}{\mathit{ref}}\) from the stack.
If \(\href{../exec/runtime.html#syntax-ref}{\mathit{ref}}\) is \(\href{../syntax/instructions.html#syntax-instr-ref}{\mathsf{ref.null}}~t\), then:
Trap.
Assert: due to validation, \(\href{../exec/runtime.html#syntax-ref}{\mathit{ref}}\) is an array reference.
Let \(\href{../exec/runtime.html#syntax-ref}{\mathsf{ref{.}array}}~a\) be the reference value \(\href{../exec/runtime.html#syntax-ref}{\mathit{ref}}\).
Assert: due to validation, the array instance \(S.\href{../exec/runtime.html#syntax-store}{\mathsf{arrays}}[a]\) exists.
If \(n\) is larger than or equal to the length of \(S.\href{../exec/runtime.html#syntax-store}{\mathsf{arrays}}[a].\href{../exec/runtime.html#syntax-arrayinst}{\mathsf{fields}}\), then:
Trap.
Let \(\href{../exec/runtime.html#syntax-fieldval}{\mathit{fieldval}}\) be the field value \(S.\href{../exec/runtime.html#syntax-store}{\mathsf{arrays}}[a].\href{../exec/runtime.html#syntax-arrayinst}{\mathsf{fields}}[i]\).
Let \(\href{../exec/runtime.html#syntax-val}{\mathit{val}}\) be the result of computing \(\href{../exec/runtime.html#aux-unpackval}{\mathrm{unpack}}^{\href{../syntax/instructions.html#syntax-sx}{\mathit{sx}}^?}_{\mathit{ft}}(\href{../exec/runtime.html#syntax-fieldval}{\mathit{fieldval}}))\).
Push the value \(\href{../exec/runtime.html#syntax-val}{\mathit{val}}\) to the stack.
\(\href{../syntax/instructions.html#syntax-instr-array}{\mathsf{array.set}}~x\)¶
Assert: due to validation, the defined type \(F.\href{../exec/runtime.html#syntax-frame}{\mathsf{module}}.\href{../exec/runtime.html#syntax-moduleinst}{\mathsf{types}}[x]\) exists.
Let \(\href{../valid/conventions.html#syntax-deftype}{\mathit{deftype}}\) be the defined type \(F.\href{../exec/runtime.html#syntax-frame}{\mathsf{module}}.\href{../exec/runtime.html#syntax-moduleinst}{\mathsf{types}}[x]\).
Assert: due to validation, the expansion of \(\href{../valid/conventions.html#syntax-deftype}{\mathit{deftype}}\) is an array type.
Let \(\href{../syntax/types.html#syntax-comptype}{\mathsf{array}}~\mathit{ft}\) be the expanded array type of \(\href{../valid/conventions.html#syntax-deftype}{\mathit{deftype}}\).
Assert: due to validation, a value is on the top of the stack.
Pop the value \(\href{../exec/runtime.html#syntax-val}{\mathit{val}}\) from the stack.
Assert: due to validation, a value of type \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}\) is on the top of the stack.
Pop the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~i\) from the stack.
Assert: due to validation, a value of type \((\href{../syntax/types.html#syntax-reftype}{\mathsf{ref}}~\href{../syntax/types.html#syntax-reftype}{\mathsf{null}}~x)\) is on the top of the stack.
Pop the value \(\href{../exec/runtime.html#syntax-ref}{\mathit{ref}}\) from the stack.
If \(\href{../exec/runtime.html#syntax-ref}{\mathit{ref}}\) is \(\href{../syntax/instructions.html#syntax-instr-ref}{\mathsf{ref.null}}~t\), then:
Trap.
Assert: due to validation, \(\href{../exec/runtime.html#syntax-ref}{\mathit{ref}}\) is an array reference.
Let \(\href{../exec/runtime.html#syntax-ref}{\mathsf{ref{.}array}}~a\) be the reference value \(\href{../exec/runtime.html#syntax-ref}{\mathit{ref}}\).
Assert: due to validation, the array instance \(S.\href{../exec/runtime.html#syntax-store}{\mathsf{arrays}}[a]\) exists.
If \(n\) is larger than or equal to the length of \(S.\href{../exec/runtime.html#syntax-store}{\mathsf{arrays}}[a].\href{../exec/runtime.html#syntax-arrayinst}{\mathsf{fields}}\), then:
Trap.
Let \(\href{../exec/runtime.html#syntax-fieldval}{\mathit{fieldval}}\) be the result of computing \(\href{../exec/runtime.html#aux-packval}{\mathrm{pack}}_{\mathit{ft}}(\href{../exec/runtime.html#syntax-val}{\mathit{val}}))\).
Replace the field value \(S.\href{../exec/runtime.html#syntax-store}{\mathsf{arrays}}[a].\href{../exec/runtime.html#syntax-arrayinst}{\mathsf{fields}}[i]\) with \(\href{../exec/runtime.html#syntax-fieldval}{\mathit{fieldval}}\).
\(\href{../syntax/instructions.html#syntax-instr-array}{\mathsf{array.len}}\)¶
Assert: due to validation, a value of type \((\href{../syntax/types.html#syntax-reftype}{\mathsf{ref}}~\href{../syntax/types.html#syntax-reftype}{\mathsf{null}}~\href{../syntax/types.html#syntax-heaptype}{\mathsf{array}})\) is on the top of the stack.
Pop the value \(\href{../exec/runtime.html#syntax-ref}{\mathit{ref}}\) from the stack.
If \(\href{../exec/runtime.html#syntax-ref}{\mathit{ref}}\) is \(\href{../syntax/instructions.html#syntax-instr-ref}{\mathsf{ref.null}}~t\), then:
Trap.
Assert: due to validation, \(\href{../exec/runtime.html#syntax-ref}{\mathit{ref}}\) is an array reference.
Let \(\href{../exec/runtime.html#syntax-ref}{\mathsf{ref{.}array}}~a\) be the reference value \(\href{../exec/runtime.html#syntax-ref}{\mathit{ref}}\).
Assert: due to validation, the array instance \(S.\href{../exec/runtime.html#syntax-store}{\mathsf{arrays}}[a]\) exists.
Let \(n\) be the length of \(S.\href{../exec/runtime.html#syntax-store}{\mathsf{arrays}}[a].\href{../exec/runtime.html#syntax-arrayinst}{\mathsf{fields}}\).
Push the value \((\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~n)\) to the stack.
\(\href{../syntax/instructions.html#syntax-instr-array}{\mathsf{array.fill}}~x\)¶
Assert: due to validation, a value of type \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}\) is on the top of the stack.
Pop the value \(n\) from the stack.
Assert: due to validation, a value is on the top of the stack.
Pop the value \(\href{../exec/runtime.html#syntax-val}{\mathit{val}}\) from the stack.
Assert: due to validation, a value of type \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}\) is on the top of the stack.
Pop the value \(d\) from the stack.
Assert: due to validation, a value of type \((\href{../syntax/types.html#syntax-reftype}{\mathsf{ref}}~\href{../syntax/types.html#syntax-reftype}{\mathsf{null}}~x)\) is on the top of the stack.
Pop the value \(\href{../exec/runtime.html#syntax-ref}{\mathit{ref}}\) from the stack.
If \(\href{../exec/runtime.html#syntax-ref}{\mathit{ref}}\) is \(\href{../syntax/instructions.html#syntax-instr-ref}{\mathsf{ref.null}}~t\), then:
Trap.
Assert: due to validation, \(\href{../exec/runtime.html#syntax-ref}{\mathit{ref}}\) is an array reference.
Let \(\href{../exec/runtime.html#syntax-ref}{\mathsf{ref{.}array}}~a\) be the reference value \(\href{../exec/runtime.html#syntax-ref}{\mathit{ref}}\).
Assert: due to validation, the array instance \(S.\href{../exec/runtime.html#syntax-store}{\mathsf{arrays}}[a]\) exists.
If \(d + n\) is larger than the length of \(S.\href{../exec/runtime.html#syntax-store}{\mathsf{arrays}}[a].\href{../exec/runtime.html#syntax-arrayinst}{\mathsf{fields}}\), then:
Trap.
If \(n = 0\), then:
Return.
Push the value \(\href{../exec/runtime.html#syntax-ref}{\mathsf{ref{.}array}}~a\) to the stack.
Push the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~d\) to the stack.
Push the value \(\href{../exec/runtime.html#syntax-val}{\mathit{val}}\) to the stack.
Execute the instruction \(\href{../syntax/instructions.html#syntax-instr-array}{\mathsf{array.set}}~x\).
Push the value \(\href{../exec/runtime.html#syntax-ref}{\mathsf{ref{.}array}}~a\) to the stack.
Assert: due to the earlier check against the array size, \(d+1 < 2^{32}\).
Push the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~(d+1)\) to the stack.
Push the value \(\href{../exec/runtime.html#syntax-val}{\mathit{val}}\) to the stack.
Push the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~(n-1)\) to the stack.
Execute the instruction \(\href{../syntax/instructions.html#syntax-instr-array}{\mathsf{array.fill}}~x\).
\(\href{../syntax/instructions.html#syntax-instr-array}{\mathsf{array.copy}}~x~y\)¶
Assert: due to validation, the defined type \(F.\href{../exec/runtime.html#syntax-frame}{\mathsf{module}}.\href{../exec/runtime.html#syntax-moduleinst}{\mathsf{types}}[y]\) exists.
Let \(\href{../valid/conventions.html#syntax-deftype}{\mathit{deftype}}\) be the defined type \(F.\href{../exec/runtime.html#syntax-frame}{\mathsf{module}}.\href{../exec/runtime.html#syntax-moduleinst}{\mathsf{types}}[y]\).
Assert: due to validation, the expansion of \(\href{../valid/conventions.html#syntax-deftype}{\mathit{deftype}}\) is an array type.
Let \(\href{../syntax/types.html#syntax-comptype}{\mathsf{array}}~\href{../syntax/types.html#syntax-mut}{\mathit{mut}}~\mathit{st}\) be the expanded array type \(\href{../valid/conventions.html#syntax-deftype}{\mathit{deftype}}\).
Assert: due to validation, a value of type \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}\) is on the top of the stack.
Pop the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~n\) from the stack.
Assert: due to validation, a value of type \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}\) is on the top of the stack.
Pop the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~s\) from the stack.
Assert: due to validation, a value of type \((\href{../syntax/types.html#syntax-reftype}{\mathsf{ref}}~\href{../syntax/types.html#syntax-reftype}{\mathsf{null}}~y)\) is on the top of the stack.
Pop the value \(\href{../exec/runtime.html#syntax-ref}{\mathit{ref}}_2\) from the stack.
Assert: due to validation, a value of type \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}\) is on the top of the stack.
Pop the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~d\) from the stack.
Assert: due to validation, a value of type \((\href{../syntax/types.html#syntax-reftype}{\mathsf{ref}}~\href{../syntax/types.html#syntax-reftype}{\mathsf{null}}~x)\) is on the top of the stack.
Pop the value \(\href{../exec/runtime.html#syntax-ref}{\mathit{ref}}_1\) from the stack.
If \(\href{../exec/runtime.html#syntax-ref}{\mathit{ref}}_1\) is \(\href{../syntax/instructions.html#syntax-instr-ref}{\mathsf{ref.null}}~t\), then:
Trap.
Assert: due to validation, \(\href{../exec/runtime.html#syntax-ref}{\mathit{ref}}_1\) is an array reference.
Let \(\href{../exec/runtime.html#syntax-ref}{\mathsf{ref{.}array}}~a_1\) be the reference value \(\href{../exec/runtime.html#syntax-ref}{\mathit{ref}}_1\).
If \(\href{../exec/runtime.html#syntax-ref}{\mathit{ref}}_2\) is \(\href{../syntax/instructions.html#syntax-instr-ref}{\mathsf{ref.null}}~t\), then:
Trap.
Assert: due to validation, \(\href{../exec/runtime.html#syntax-ref}{\mathit{ref}}_2\) is an array reference.
Let \(\href{../exec/runtime.html#syntax-ref}{\mathsf{ref{.}array}}~a_2\) be the reference value \(\href{../exec/runtime.html#syntax-ref}{\mathit{ref}}_2\).
Assert: due to validation, the array instance \(S.\href{../exec/runtime.html#syntax-store}{\mathsf{arrays}}[a_1]\) exists.
Assert: due to validation, the array instance \(S.\href{../exec/runtime.html#syntax-store}{\mathsf{arrays}}[a_2]\) exists.
If \(d + n\) is larger than the length of \(S.\href{../exec/runtime.html#syntax-store}{\mathsf{arrays}}[a_1].\href{../exec/runtime.html#syntax-arrayinst}{\mathsf{fields}}\), then:
Trap.
If \(s + n\) is larger than the length of \(S.\href{../exec/runtime.html#syntax-store}{\mathsf{arrays}}[a_2].\href{../exec/runtime.html#syntax-arrayinst}{\mathsf{fields}}\), then:
Trap.
If \(n = 0\), then:
Return.
If \(d \leq s\), then:
Push the value \(\href{../exec/runtime.html#syntax-ref}{\mathsf{ref{.}array}}~a_1\) to the stack.
Push the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~d\) to the stack.
Push the value \(\href{../exec/runtime.html#syntax-ref}{\mathsf{ref{.}array}}~a_2\) to the stack.
Push the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~s\) to the stack.
Execute \(\href{../exec/instructions.html#aux-getfield}{\mathrm{getfield}}(\mathit{st})\).
Execute the instruction \(\href{../syntax/instructions.html#syntax-instr-array}{\mathsf{array.set}}~x\).
Push the value \(\href{../exec/runtime.html#syntax-ref}{\mathsf{ref{.}array}}~a_1\) to the stack.
Assert: due to the earlier check against the array size, \(d+1 < 2^{32}\).
Push the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~(d+1)\) to the stack.
Push the value \(\href{../exec/runtime.html#syntax-ref}{\mathsf{ref{.}array}}~a_2\) to the stack.
Assert: due to the earlier check against the array size, \(s+1 < 2^{32}\).
Push the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~(s+1)\) to the stack.
Else:
Push the value \(\href{../exec/runtime.html#syntax-ref}{\mathsf{ref{.}array}}~a_1\) to the stack.
Assert: due to the earlier check against the array size, \(d+n-1 < 2^{32}\).
Push the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~(d+n-1)\) to the stack.
Push the value \(\href{../exec/runtime.html#syntax-ref}{\mathsf{ref{.}array}}~a_2\) to the stack.
Assert: due to the earlier check against the array size, \(s+n-1 < 2^{32}\).
Push the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~(s+n-1)\) to the stack.
Execute \(\href{../exec/instructions.html#aux-getfield}{\mathrm{getfield}}(\mathit{st})\).
Execute the instruction \(\href{../syntax/instructions.html#syntax-instr-array}{\mathsf{array.set}}~x\).
Push the value \(\href{../exec/runtime.html#syntax-ref}{\mathsf{ref{.}array}}~a_1\) to the stack.
Push the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~d\) to the stack.
Push the value \(\href{../exec/runtime.html#syntax-ref}{\mathsf{ref{.}array}}~a_2\) to the stack.
Push the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~s\) to the stack.
Push the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~(n-1)\) to the stack.
Execute the instruction \(\href{../syntax/instructions.html#syntax-instr-array}{\mathsf{array.copy}}~x~y\).
Where:
\(\href{../syntax/instructions.html#syntax-instr-array}{\mathsf{array.init\_data}}~x~y\)¶
Assert: due to validation, the defined type \(F.\href{../exec/runtime.html#syntax-frame}{\mathsf{module}}.\href{../exec/runtime.html#syntax-moduleinst}{\mathsf{types}}[x]\) exists.
Let \(\href{../valid/conventions.html#syntax-deftype}{\mathit{deftype}}\) be the defined type \(F.\href{../exec/runtime.html#syntax-frame}{\mathsf{module}}.\href{../exec/runtime.html#syntax-moduleinst}{\mathsf{types}}[x]\).
Assert: due to validation, the expansion of \(\href{../valid/conventions.html#syntax-deftype}{\mathit{deftype}}\) is an array type.
Let \(\href{../syntax/types.html#syntax-comptype}{\mathsf{array}}~\mathit{ft}\) be the expanded array type \(\href{../valid/conventions.html#syntax-deftype}{\mathit{deftype}}\).
Assert: due to validation, the data address \(F.\href{../exec/runtime.html#syntax-frame}{\mathsf{module}}.\href{../exec/runtime.html#syntax-moduleinst}{\mathsf{dataaddrs}}[y]\) exists.
Let \(\mathit{da}\) be the data address \(F.\href{../exec/runtime.html#syntax-frame}{\mathsf{module}}.\href{../exec/runtime.html#syntax-moduleinst}{\mathsf{dataaddrs}}[y]\).
Assert: due to validation, the data instance \(S.\href{../exec/runtime.html#syntax-store}{\mathsf{datas}}[\mathit{da}]\) exists.
Let \(\href{../exec/runtime.html#syntax-datainst}{\mathit{datainst}}\) be the data instance \(S.\href{../exec/runtime.html#syntax-store}{\mathsf{datas}}[\mathit{da}]\).
Assert: due to validation, three values of type \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}\) are on the top of the stack.
Pop the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~n\) from the stack.
Pop the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~s\) from the stack.
Pop the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~d\) from the stack.
Assert: due to validation, a value of type \((\href{../syntax/types.html#syntax-reftype}{\mathsf{ref}}~\href{../syntax/types.html#syntax-reftype}{\mathsf{null}}~x)\) is on the top of the stack.
Pop the value \(\href{../exec/runtime.html#syntax-ref}{\mathit{ref}}\) from the stack.
If \(\href{../exec/runtime.html#syntax-ref}{\mathit{ref}}\) is \(\href{../syntax/instructions.html#syntax-instr-ref}{\mathsf{ref.null}}~t\), then:
Trap.
Assert: due to validation, \(\href{../exec/runtime.html#syntax-ref}{\mathit{ref}}\) is an array reference.
Let \(\href{../exec/runtime.html#syntax-ref}{\mathsf{ref{.}array}}~a\) be the reference value \(\href{../exec/runtime.html#syntax-ref}{\mathit{ref}}\).
Assert: due to validation, the array instance \(S.\href{../exec/runtime.html#syntax-store}{\mathsf{arrays}}[a]\) exists.
Assert: due to validation, the field type \(\mathit{ft}\) has a defined bit width.
Let \(z\) be the bit width of field type \(\mathit{ft}\) divided by eight.
If \(d + n\) is larger than the length of \(S.\href{../exec/runtime.html#syntax-store}{\mathsf{arrays}}[a].\href{../exec/runtime.html#syntax-arrayinst}{\mathsf{fields}}\), or the sum of \(s\) and \(n\) times \(z\) is larger than the length of \(\href{../exec/runtime.html#syntax-datainst}{\mathit{datainst}}.\href{../exec/runtime.html#syntax-datainst}{\mathsf{data}}\), then:
Trap.
If \(n = 0\), then:
Return.
Let \(b^\ast\) be the byte sequence \(\href{../exec/runtime.html#syntax-datainst}{\mathit{datainst}}.\href{../exec/runtime.html#syntax-datainst}{\mathsf{data}}[s \href{../syntax/conventions.html#notation-slice}{\mathrel{\mathbf{:}}} z]\).
Let \(t\) be the value type \(\href{../syntax/types.html#aux-unpacktype}{\mathrm{unpack}}(\mathit{ft})\).
Assert: due to validation, \(\href{../exec/numerics.html#aux-bytes}{\mathrm{bytes}}_{\mathit{ft}}\) is defined.
Let \(c\) be the constant for which \(\href{../exec/numerics.html#aux-bytes}{\mathrm{bytes}}_{\mathit{ft}}(c)\) is \(b^\ast\).
Push the value \(\href{../exec/runtime.html#syntax-ref}{\mathsf{ref{.}array}}~a\) to the stack.
Push the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~d\) to the stack.
Push the value \(t.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~c\) to the stack.
Execute the instruction \(\href{../syntax/instructions.html#syntax-instr-array}{\mathsf{array.set}}~x\).
Push the value \(\href{../exec/runtime.html#syntax-ref}{\mathsf{ref{.}array}}~a\) to the stack.
Push the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~(d+1)\) to the stack.
Push the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~(s+z)\) to the stack.
Push the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~(n-1)\) to the stack.
Execute the instruction \(\href{../syntax/instructions.html#syntax-instr-array}{\mathsf{array.init\_data}}~x~y\).
\(\href{../syntax/instructions.html#syntax-instr-array}{\mathsf{array.init\_elem}}~x~y\)¶
Assert: due to validation, the defined type \(F.\href{../exec/runtime.html#syntax-frame}{\mathsf{module}}.\href{../exec/runtime.html#syntax-moduleinst}{\mathsf{types}}[x]\) exists.
Let \(\href{../valid/conventions.html#syntax-deftype}{\mathit{deftype}}\) be the defined type \(F.\href{../exec/runtime.html#syntax-frame}{\mathsf{module}}.\href{../exec/runtime.html#syntax-moduleinst}{\mathsf{types}}[x]\).
Assert: due to validation, the expansion of \(\href{../valid/conventions.html#syntax-deftype}{\mathit{deftype}}\) is an array type.
Let \(\href{../syntax/types.html#syntax-comptype}{\mathsf{array}}~\mathit{ft}\) be the expanded array type \(\href{../valid/conventions.html#syntax-deftype}{\mathit{deftype}}\).
Assert: due to validation, the element address \(F.\href{../exec/runtime.html#syntax-frame}{\mathsf{module}}.\href{../exec/runtime.html#syntax-moduleinst}{\mathsf{elemaddrs}}[y]\) exists.
Let \(\mathit{ea}\) be the element address \(F.\href{../exec/runtime.html#syntax-frame}{\mathsf{module}}.\href{../exec/runtime.html#syntax-moduleinst}{\mathsf{elemaddrs}}[y]\).
Assert: due to validation, the element instance \(S.\href{../exec/runtime.html#syntax-store}{\mathsf{elems}}[\mathit{ea}]\) exists.
Let \(\href{../exec/runtime.html#syntax-eleminst}{\mathit{eleminst}}\) be the element instance \(S.\href{../exec/runtime.html#syntax-store}{\mathsf{elems}}[\mathit{ea}]\).
Assert: due to validation, three values of type \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}\) are on the top of the stack.
Pop the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~n\) from the stack.
Pop the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~s\) from the stack.
Pop the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~d\) from the stack.
Assert: due to validation, a value of type \((\href{../syntax/types.html#syntax-reftype}{\mathsf{ref}}~\href{../syntax/types.html#syntax-reftype}{\mathsf{null}}~x)\) is on the top of the stack.
Pop the value \(\href{../exec/runtime.html#syntax-ref}{\mathit{ref}}\) from the stack.
If \(\href{../exec/runtime.html#syntax-ref}{\mathit{ref}}\) is \(\href{../syntax/instructions.html#syntax-instr-ref}{\mathsf{ref.null}}~t\), then:
Trap.
Assert: due to validation, \(\href{../exec/runtime.html#syntax-ref}{\mathit{ref}}\) is an array reference.
Let \(\href{../exec/runtime.html#syntax-ref}{\mathsf{ref{.}array}}~a\) be the reference value \(\href{../exec/runtime.html#syntax-ref}{\mathit{ref}}\).
Assert: due to validation, the array instance \(S.\href{../exec/runtime.html#syntax-store}{\mathsf{arrays}}[a]\) exists.
If \(d + n\) is larger than the length of \(S.\href{../exec/runtime.html#syntax-store}{\mathsf{arrays}}[a].\href{../exec/runtime.html#syntax-arrayinst}{\mathsf{fields}}\), or \(s + n\) is larger than the length of \(\href{../exec/runtime.html#syntax-eleminst}{\mathit{eleminst}}.\href{../exec/runtime.html#syntax-eleminst}{\mathsf{elem}}\), then:
Trap.
If \(n = 0\), then:
Return.
Let \(\href{../exec/runtime.html#syntax-ref}{\mathit{ref}}'\) be the reference value \(\href{../exec/runtime.html#syntax-eleminst}{\mathit{eleminst}}.\href{../exec/runtime.html#syntax-eleminst}{\mathsf{elem}}[s]\).
Push the value \(\href{../exec/runtime.html#syntax-ref}{\mathsf{ref{.}array}}~a\) to the stack.
Push the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~d\) to the stack.
Push the value \(\href{../exec/runtime.html#syntax-ref}{\mathit{ref}}'\) to the stack.
Execute the instruction \(\href{../syntax/instructions.html#syntax-instr-array}{\mathsf{array.set}}~x\).
Push the value \(\href{../exec/runtime.html#syntax-ref}{\mathsf{ref{.}array}}~a\) to the stack.
Push the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~(d+1)\) to the stack.
Push the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~(s+1)\) to the stack.
Push the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~(n-1)\) to the stack.
Execute the instruction \(\href{../syntax/instructions.html#syntax-instr-array}{\mathsf{array.init\_elem}}~x~y\).
\(\href{../syntax/instructions.html#syntax-instr-extern}{\mathsf{any.convert\_extern}}\)¶
Assert: due to validation, a reference value is on the top of the stack.
Pop the value \(\href{../exec/runtime.html#syntax-ref}{\mathit{ref}}\) from the stack.
If \(\href{../exec/runtime.html#syntax-ref}{\mathit{ref}}\) is \(\href{../syntax/instructions.html#syntax-instr-ref}{\mathsf{ref.null}}~\mathit{ht}\), then:
Push the reference value \((\href{../syntax/instructions.html#syntax-instr-ref}{\mathsf{ref.null}}~\href{../syntax/types.html#syntax-heaptype}{\mathsf{any}})\) to the stack.
Else:
Assert: due to validation, a \(\href{../exec/runtime.html#syntax-ref}{\mathit{ref}}\) is an external reference.
Let \(\href{../exec/runtime.html#syntax-ref}{\mathsf{ref{.}extern}}~\href{../exec/runtime.html#syntax-ref}{\mathit{ref}}'\) be the reference value \(\href{../exec/runtime.html#syntax-ref}{\mathit{ref}}\).
Push the reference value \(\href{../exec/runtime.html#syntax-ref}{\mathit{ref}}'\) to the stack.
\(\href{../syntax/instructions.html#syntax-instr-extern}{\mathsf{extern.convert\_any}}\)¶
Assert: due to validation, a reference value is on the top of the stack.
Pop the value \(\href{../exec/runtime.html#syntax-ref}{\mathit{ref}}\) from the stack.
If \(\href{../exec/runtime.html#syntax-ref}{\mathit{ref}}\) is \(\href{../syntax/instructions.html#syntax-instr-ref}{\mathsf{ref.null}}~\mathit{ht}\), then:
Push the reference value \((\href{../syntax/instructions.html#syntax-instr-ref}{\mathsf{ref.null}}~\href{../syntax/types.html#syntax-heaptype}{\mathsf{extern}})\) to the stack.
Else:
Let \(\href{../exec/runtime.html#syntax-ref}{\mathit{ref}}'\) be the reference value \((\href{../exec/runtime.html#syntax-ref}{\mathsf{ref{.}extern}}~\href{../exec/runtime.html#syntax-ref}{\mathit{ref}})\).
Push the reference value \(\href{../exec/runtime.html#syntax-ref}{\mathit{ref}}'\) to the stack.
Vector Instructions¶
Vector instructions that operate bitwise are handled as integer operations of respective width.
Most other vector instructions are defined in terms of numeric operators that are applied lane-wise according to the given shape.
Note
For example, the result of instruction \(\mathsf{i32x4}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{add}}\) applied to operands \(v_1, v_2\) invokes \(\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{add}}_{\mathsf{i32x4}}(v_1, v_2)\), which maps to \(\href{../exec/numerics.html#aux-lanes}{\mathrm{lanes}}^{-1}_{\mathsf{i32x4}}(\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{add}}_{\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}}(i_1, i_2)^\ast)\), where \(i_1^\ast\) and \(i_2^\ast\) are sequences resulting from invoking \(\href{../exec/numerics.html#aux-lanes}{\mathrm{lanes}}_{\mathsf{i32x4}}(v_1)\) and \(\href{../exec/numerics.html#aux-lanes}{\mathrm{lanes}}_{\mathsf{i32x4}}(v_2)\) respectively.
\(\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}\mathsf{.}\href{../syntax/instructions.html#syntax-instr-vec}{\mathsf{const}}~c\)¶
Push the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}.\href{../syntax/instructions.html#syntax-instr-vec}{\mathsf{const}}~c\) to the stack.
Note
No formal reduction rule is required for this instruction, since \(\href{../syntax/instructions.html#syntax-instr-vec}{\mathsf{const}}\) instructions coincide with values.
\(\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}\mathsf{.}\href{../syntax/instructions.html#syntax-vvunop}{\mathit{vvunop}}\)¶
Assert: due to validation, a value of value type \(\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}\) is on the top of the stack.
Pop the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}.\href{../syntax/instructions.html#syntax-instr-vec}{\mathsf{const}}~c_1\) from the stack.
Let \(c\) be the result of computing \(\href{../syntax/instructions.html#syntax-vvunop}{\mathit{vvunop}}_{\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}}(c_1)\).
Push the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}.\href{../syntax/instructions.html#syntax-instr-vec}{\mathsf{const}}~c\) to the stack.
\(\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}\mathsf{.}\href{../syntax/instructions.html#syntax-vvbinop}{\mathit{vvbinop}}\)¶
Assert: due to validation, two values of value type \(\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}\) are on the top of the stack.
Pop the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}.\href{../syntax/instructions.html#syntax-instr-vec}{\mathsf{const}}~c_2\) from the stack.
Pop the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}.\href{../syntax/instructions.html#syntax-instr-vec}{\mathsf{const}}~c_1\) from the stack.
Let \(c\) be the result of computing \(\href{../syntax/instructions.html#syntax-vvbinop}{\mathit{vvbinop}}_{\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}}(c_1, c_2)\).
Push the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}.\href{../syntax/instructions.html#syntax-instr-vec}{\mathsf{const}}~c\) to the stack.
\(\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}\mathsf{.}\href{../syntax/instructions.html#syntax-vvternop}{\mathit{vvternop}}\)¶
Assert: due to validation, three values of value type \(\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}\) are on the top of the stack.
Pop the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}.\href{../syntax/instructions.html#syntax-instr-vec}{\mathsf{const}}~c_3\) from the stack.
Pop the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}.\href{../syntax/instructions.html#syntax-instr-vec}{\mathsf{const}}~c_2\) from the stack.
Pop the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}.\href{../syntax/instructions.html#syntax-instr-vec}{\mathsf{const}}~c_1\) from the stack.
Let \(c\) be the result of computing \(\href{../syntax/instructions.html#syntax-vvternop}{\mathit{vvternop}}_{\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}}(c_1, c_2, c_3)\).
Push the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}.\href{../syntax/instructions.html#syntax-instr-vec}{\mathsf{const}}~c\) to the stack.
\(\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}\mathsf{.}\href{../syntax/instructions.html#syntax-instr-vec}{\mathsf{any\_true}}\)¶
Assert: due to validation, a value of value type \(\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}\) is on the top of the stack.
Pop the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}.\href{../syntax/instructions.html#syntax-instr-vec}{\mathsf{const}}~c_1\) from the stack.
Let \(i\) be the result of computing \(\href{../exec/numerics.html#op-ine}{\mathrm{ine}}_{128}(c_1, 0)\).
Push the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~i\) onto the stack.
\(\mathsf{i8x16.}\href{../syntax/instructions.html#syntax-instr-vec}{\mathsf{swizzle}}\)¶
Assert: due to validation, two values of value type \(\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}\) are on the top of the stack.
Pop the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}.\href{../syntax/instructions.html#syntax-instr-vec}{\mathsf{const}}~c_2\) from the stack.
Let \(i^\ast\) be the result of computing \(\href{../exec/numerics.html#aux-lanes}{\mathrm{lanes}}_{\href{../syntax/types.html#syntax-valtype}{\mathsf{i8x16}}}(c_2)\).
Pop the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}.\href{../syntax/instructions.html#syntax-instr-vec}{\mathsf{const}}~c_1\) from the stack.
Let \(j^\ast\) be the result of computing \(\href{../exec/numerics.html#aux-lanes}{\mathrm{lanes}}_{\href{../syntax/types.html#syntax-valtype}{\mathsf{i8x16}}}(c_1)\).
Let \(c^\ast\) be the concatenation of the two sequences \(j^\ast\) and \(0^{240}\).
Let \(c'\) be the result of computing \(\href{../exec/numerics.html#aux-lanes}{\mathrm{lanes}}^{-1}_{\href{../syntax/types.html#syntax-valtype}{\mathsf{i8x16}}}(c^\ast[ i^\ast[0] ] \dots c^\ast[ i^\ast[15] ])\).
Push the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}.\href{../syntax/instructions.html#syntax-instr-vec}{\mathsf{const}}~c'\) onto the stack.
\(\mathsf{i8x16.}\href{../syntax/instructions.html#syntax-instr-vec}{\mathsf{shuffle}}~x^\ast\)¶
Assert: due to validation, two values of value type \(\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}\) are on the top of the stack.
Assert: due to validation, for all \(x_i\) in \(x^\ast\) it holds that \(x_i < 32\).
Pop the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}.\href{../syntax/instructions.html#syntax-instr-vec}{\mathsf{const}}~c_2\) from the stack.
Let \(i_2^\ast\) be the result of computing \(\href{../exec/numerics.html#aux-lanes}{\mathrm{lanes}}_{\href{../syntax/types.html#syntax-valtype}{\mathsf{i8x16}}}(c_2)\).
Pop the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}.\href{../syntax/instructions.html#syntax-instr-vec}{\mathsf{const}}~c_1\) from the stack.
Let \(i_1^\ast\) be the result of computing \(\href{../exec/numerics.html#aux-lanes}{\mathrm{lanes}}_{\href{../syntax/types.html#syntax-valtype}{\mathsf{i8x16}}}(c_1)\).
Let \(i^\ast\) be the concatenation of the two sequences \(i_1^\ast\) and \(i_2^\ast\).
Let \(c\) be the result of computing \(\href{../exec/numerics.html#aux-lanes}{\mathrm{lanes}}^{-1}_{\href{../syntax/types.html#syntax-valtype}{\mathsf{i8x16}}}(i^\ast[x^\ast[0]] \dots i^\ast[x^\ast[15]])\).
Push the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}.\href{../syntax/instructions.html#syntax-instr-vec}{\mathsf{const}}~c\) onto the stack.
\(\href{../syntax/instructions.html#syntax-shape}{\mathit{shape}}\mathsf{.}\href{../syntax/instructions.html#syntax-instr-vec}{\mathsf{splat}}\)¶
Let \(t\) be the type \(\href{../valid/instructions.html#aux-unpackshape}{\mathrm{unpack}}(\href{../syntax/instructions.html#syntax-shape}{\mathit{shape}})\).
Assert: due to validation, a value of value type \(t\) is on the top of the stack.
Pop the value \(t.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~c_1\) from the stack.
Let \(N\) be the integer \(\href{../valid/instructions.html#aux-dim}{\mathrm{dim}}(\href{../syntax/instructions.html#syntax-shape}{\mathit{shape}})\).
Let \(c\) be the result of computing \(\href{../exec/numerics.html#aux-lanes}{\mathrm{lanes}}^{-1}_{\href{../syntax/instructions.html#syntax-shape}{\mathit{shape}}}(c_1^N)\).
Push the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}.\href{../syntax/instructions.html#syntax-instr-vec}{\mathsf{const}}~c\) to the stack.
\(t_1\mathsf{x}N\mathsf{.}\href{../syntax/instructions.html#syntax-instr-vec}{\mathsf{extract\_lane}}\mathsf{\_}\href{../syntax/instructions.html#syntax-sx}{\mathit{sx}}^?~x\)¶
Assert: due to validation, \(x < N\).
Assert: due to validation, a value of value type \(\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}\) is on the top of the stack.
Pop the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}.\href{../syntax/instructions.html#syntax-instr-vec}{\mathsf{const}}~c_1\) from the stack.
Let \(i^\ast\) be the result of computing \(\href{../exec/numerics.html#aux-lanes}{\mathrm{lanes}}_{t_1\mathsf{x}N}(c_1)\).
Let \(t_2\) be the type \(\href{../valid/instructions.html#aux-unpackshape}{\mathrm{unpack}}(t_1\mathsf{x}N)\).
Let \(c_2\) be the result of computing \(\href{../exec/numerics.html#op-extend-u}{\mathrm{extend}}^{sx^?}_{t_1,t_2}(i^\ast[x])\).
Push the value \(t_2.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~c_2\) to the stack.
\(\href{../syntax/instructions.html#syntax-shape}{\mathit{shape}}\mathsf{.}\href{../syntax/instructions.html#syntax-instr-vec}{\mathsf{replace\_lane}}~x\)¶
Assert: due to validation, \(x < \href{../valid/instructions.html#aux-dim}{\mathrm{dim}}(\href{../syntax/instructions.html#syntax-shape}{\mathit{shape}})\).
Let \(t_2\) be the type \(\href{../valid/instructions.html#aux-unpackshape}{\mathrm{unpack}}(\href{../syntax/instructions.html#syntax-shape}{\mathit{shape}})\).
Assert: due to validation, a value of value type \(t_1\) is on the top of the stack.
Pop the value \(t_2.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~c_2\) from the stack.
Assert: due to validation, a value of value type \(\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}\) is on the top of the stack.
Pop the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}.\href{../syntax/instructions.html#syntax-instr-vec}{\mathsf{const}}~c_1\) from the stack.
Let \(i^\ast\) be the result of computing \(\href{../exec/numerics.html#aux-lanes}{\mathrm{lanes}}_{\href{../syntax/instructions.html#syntax-shape}{\mathit{shape}}}(c_1)\).
Let \(c\) be the result of computing \(\href{../exec/numerics.html#aux-lanes}{\mathrm{lanes}}^{-1}_{\href{../syntax/instructions.html#syntax-shape}{\mathit{shape}}}(i^\ast \href{../syntax/conventions.html#notation-replace}{\mathrel{\mbox{with}}} [x] = c_2)\).
Push \(\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}.\href{../syntax/instructions.html#syntax-instr-vec}{\mathsf{const}}~c\) on the stack.
\(\href{../syntax/instructions.html#syntax-shape}{\mathit{shape}}\mathsf{.}\href{../syntax/instructions.html#syntax-vunop}{\mathit{vunop}}\)¶
Assert: due to validation, a value of value type \(\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}\) is on the top of the stack.
Pop the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}.\href{../syntax/instructions.html#syntax-instr-vec}{\mathsf{const}}~c_1\) from the stack.
Let \(c\) be the result of computing \(\href{../syntax/instructions.html#syntax-vunop}{\mathit{vunop}}_{\href{../syntax/instructions.html#syntax-shape}{\mathit{shape}}}(c_1)\).
Push the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}.\href{../syntax/instructions.html#syntax-instr-vec}{\mathsf{const}}~c\) to the stack.
\(\href{../syntax/instructions.html#syntax-shape}{\mathit{shape}}\mathsf{.}\href{../syntax/instructions.html#syntax-vbinop}{\mathit{vbinop}}\)¶
Assert: due to validation, two values of value type \(\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}\) are on the top of the stack.
Pop the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}.\href{../syntax/instructions.html#syntax-instr-vec}{\mathsf{const}}~c_2\) from the stack.
Pop the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}.\href{../syntax/instructions.html#syntax-instr-vec}{\mathsf{const}}~c_1\) from the stack.
If \(\href{../syntax/instructions.html#syntax-vbinop}{\mathit{vbinop}}_{\href{../syntax/instructions.html#syntax-shape}{\mathit{shape}}}(c_1, c_2)\) is defined:
Let \(c\) be a possible result of computing \(\href{../syntax/instructions.html#syntax-vbinop}{\mathit{vbinop}}_{\href{../syntax/instructions.html#syntax-shape}{\mathit{shape}}}(c_1, c_2)\).
Push the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}.\href{../syntax/instructions.html#syntax-instr-vec}{\mathsf{const}}~c\) to the stack.
Else:
Trap.
\(t\mathsf{x}N\mathsf{.}\href{../syntax/instructions.html#syntax-vrelop}{\mathit{vrelop}}\)¶
Assert: due to validation, two values of value type \(\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}\) are on the top of the stack.
Pop the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}.\href{../syntax/instructions.html#syntax-instr-vec}{\mathsf{const}}~c_2\) from the stack.
Pop the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}.\href{../syntax/instructions.html#syntax-instr-vec}{\mathsf{const}}~c_1\) from the stack.
Let \(i_1^\ast\) be the result of computing \(\href{../exec/numerics.html#aux-lanes}{\mathrm{lanes}}_{t\mathsf{x}N}(c_1)\).
Let \(i_2^\ast\) be the result of computing \(\href{../exec/numerics.html#aux-lanes}{\mathrm{lanes}}_{t\mathsf{x}N}(c_2)\).
Let \(i^\ast\) be the result of computing \(\href{../syntax/instructions.html#syntax-vrelop}{\mathit{vrelop}}_t(i_1^\ast, i_2^\ast)\).
Let \(j^\ast\) be the result of computing \(\href{../exec/numerics.html#op-extend-s}{\mathrm{extend}^{\mathsf{s}}}_{1,|t|}(i^\ast)\).
Let \(c\) be the result of computing \(\href{../exec/numerics.html#aux-lanes}{\mathrm{lanes}}^{-1}_{t\mathsf{x}N}(j^\ast)\).
Push the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}.\href{../syntax/instructions.html#syntax-instr-vec}{\mathsf{const}}~c\) to the stack.
\(t\mathsf{x}N\mathsf{.}\href{../syntax/instructions.html#syntax-vishiftop}{\mathit{vishiftop}}\)¶
Assert: due to validation, a value of value type \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}\) is on the top of the stack.
Pop the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~s\) from the stack.
Assert: due to validation, a value of value type \(\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}\) is on the top of the stack.
Pop the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}.\href{../syntax/instructions.html#syntax-instr-vec}{\mathsf{const}}~c_1\) from the stack.
Let \(i^\ast\) be the result of computing \(\href{../exec/numerics.html#aux-lanes}{\mathrm{lanes}}_{t\mathsf{x}N}(c_1)\).
Let \(j^\ast\) be the result of computing \(\href{../syntax/instructions.html#syntax-vishiftop}{\mathit{vishiftop}}_{t}(i^\ast, s^N)\).
Let \(c\) be the result of computing \(\href{../exec/numerics.html#aux-lanes}{\mathrm{lanes}}^{-1}_{t\mathsf{x}N}(j^\ast)\).
Push the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}.\href{../syntax/instructions.html#syntax-instr-vec}{\mathsf{const}}~c\) to the stack.
\(\href{../syntax/instructions.html#syntax-shape}{\mathit{shape}}\mathsf{.}\href{../syntax/instructions.html#syntax-instr-vec}{\mathsf{all\_true}}\)¶
Assert: due to validation, a value of value type \(\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}\) is on the top of the stack.
Pop the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}.\href{../syntax/instructions.html#syntax-instr-vec}{\mathsf{const}}~c\) from the stack.
Let \(i_1^\ast\) be the result of computing \(\href{../exec/numerics.html#aux-lanes}{\mathrm{lanes}}_{\href{../syntax/instructions.html#syntax-shape}{\mathit{shape}}}(c)\).
Let \(i\) be the result of computing \(\href{../exec/numerics.html#aux-tobool}{\mathrm{bool}}(\bigwedge(i_1 \neq 0)^\ast)\).
Push the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~i\) onto the stack.
\(t\mathsf{x}N\mathsf{.}\href{../syntax/instructions.html#syntax-instr-vec}{\mathsf{bitmask}}\)¶
Assert: due to validation, a value of value type \(\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}\) is on the top of the stack.
Pop the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}.\href{../syntax/instructions.html#syntax-instr-vec}{\mathsf{const}}~c\) from the stack.
Let \(i_1^N\) be the result of computing \(\href{../exec/numerics.html#aux-lanes}{\mathrm{lanes}}_{t\mathsf{x}N}(c)\).
Let \(B\) be the bit width \(|t|\) of value type \(t\).
Let \(i_2^N\) be the result of computing \(\href{../exec/numerics.html#op-ilt-s}{\mathrm{ilt\_s}}_{B}(i_1^N, 0^N)\).
Let \(j^\ast\) be the concatenation of the two sequences \(i_2^N\) and \(0^{32-N}\).
Let \(i\) be the result of computing \(\href{../exec/numerics.html#aux-ibits}{\mathrm{ibits}}_{32}^{-1}(j^\ast)\).
Push the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~i\) onto the stack.
\(t_2\mathsf{x}N\mathsf{.}\href{../syntax/instructions.html#syntax-instr-vec}{\mathsf{narrow}}\mathsf{\_}t_1\mathsf{x}M\mathsf{\_}\href{../syntax/instructions.html#syntax-sx}{\mathit{sx}}\)¶
Assert: due to syntax, \(N = 2\cdot M\).
Assert: due to validation, two values of value type \(\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}\) are on the top of the stack.
Pop the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}.\href{../syntax/instructions.html#syntax-instr-vec}{\mathsf{const}}~c_2\) from the stack.
Let \(i_2^M\) be the result of computing \(\href{../exec/numerics.html#aux-lanes}{\mathrm{lanes}}_{t_1\mathsf{x}M}(c_2)\).
Let \(d_2^M\) be the result of computing \(\href{../exec/numerics.html#op-narrow-u}{\mathrm{narrow}}^{\href{../syntax/instructions.html#syntax-sx}{\mathit{sx}}}_{|t_1|,|t_2|}(i_2^M)\).
Pop the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}.\href{../syntax/instructions.html#syntax-instr-vec}{\mathsf{const}}~c_1\) from the stack.
Let \(i_1^M\) be the result of computing \(\href{../exec/numerics.html#aux-lanes}{\mathrm{lanes}}_{t_1\mathsf{x}M}(c_1)\).
Let \(d_1^M\) be the result of computing \(\href{../exec/numerics.html#op-narrow-u}{\mathrm{narrow}}^{\href{../syntax/instructions.html#syntax-sx}{\mathit{sx}}}_{|t_1|,|t_2|}(i_1^M)\).
Let \(j^N\) be the concatenation of the two sequences \(d_1^M\) and \(d_2^M\).
Let \(c\) be the result of computing \(\href{../exec/numerics.html#aux-lanes}{\mathrm{lanes}}^{-1}_{t_2\mathsf{x}N}(j^N)\).
Push the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}.\href{../syntax/instructions.html#syntax-instr-vec}{\mathsf{const}}~c\) onto the stack.
\(t_2\mathsf{x}N\mathsf{.}\href{../syntax/instructions.html#syntax-vcvtop}{\mathit{vcvtop}}\mathsf{\_}t_1\mathsf{x}M\mathsf{\_}\href{../syntax/instructions.html#syntax-sx}{\mathit{sx}}\)¶
Assert: due to syntax, \(N = M\).
Assert: due to validation, a value of value type \(\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}\) is on the top of the stack.
Pop the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}.\href{../syntax/instructions.html#syntax-instr-vec}{\mathsf{const}}~c_1\) from the stack.
Let \(i^\ast\) be the result of computing \(\href{../exec/numerics.html#aux-lanes}{\mathrm{lanes}}_{t_1\mathsf{x}M}(c_1)\).
Let \(j^\ast\) be the result of computing \(\href{../syntax/instructions.html#syntax-vcvtop}{\mathit{vcvtop}}^{\href{../syntax/instructions.html#syntax-sx}{\mathit{sx}}}_{|t_1|,|t_2|}(i^\ast)\).
Let \(c\) be the result of computing \(\href{../exec/numerics.html#aux-lanes}{\mathrm{lanes}}^{-1}_{t_2\mathsf{x}N}(j^\ast)\).
Push the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}.\href{../syntax/instructions.html#syntax-instr-vec}{\mathsf{const}}~c\) onto the stack.
\(t_2\mathsf{x}N\mathsf{.}\href{../syntax/instructions.html#syntax-vcvtop}{\mathit{vcvtop}}\mathsf{\_}\href{../syntax/instructions.html#syntax-half}{\mathit{half}}\mathsf{\_}t_1\mathsf{x}M\mathsf{\_}\href{../syntax/instructions.html#syntax-sx}{\mathit{sx}}^?\)¶
Assert: due to syntax, \(N = M / 2\).
Assert: due to validation, a value of value type \(\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}\) is on the top of the stack.
Pop the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}.\href{../syntax/instructions.html#syntax-instr-vec}{\mathsf{const}}~c_1\) from the stack.
Let \(i^\ast\) be the result of computing \(\href{../exec/numerics.html#aux-lanes}{\mathrm{lanes}}_{t_1\mathsf{x}M}(c_1)\).
If \(\href{../syntax/instructions.html#syntax-half}{\mathit{half}}\) is \(\mathsf{low}\), then:
Let \(j^\ast\) be the sequence \(i^\ast[0 \href{../syntax/conventions.html#notation-slice}{\mathrel{\mathbf{:}}} N]\).
Else:
Let \(j^\ast\) be the sequence \(i^\ast[N \href{../syntax/conventions.html#notation-slice}{\mathrel{\mathbf{:}}} N]\).
Let \(k^\ast\) be the result of computing \(\href{../syntax/instructions.html#syntax-vcvtop}{\mathit{vcvtop}}^{\href{../syntax/instructions.html#syntax-sx}{\mathit{sx}}^?}_{|t_1|,|t_2|}(j^\ast)\).
Let \(c\) be the result of computing \(\href{../exec/numerics.html#aux-lanes}{\mathrm{lanes}}^{-1}_{t_2\mathsf{x}N}(k^\ast)\).
Push the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}.\href{../syntax/instructions.html#syntax-instr-vec}{\mathsf{const}}~c\) onto the stack.
where:
\(t_2\mathsf{x}N\mathsf{.}\href{../syntax/instructions.html#syntax-vcvtop}{\mathit{vcvtop}}\mathsf{\_}t_1\mathsf{x}M\mathsf{\_}\href{../syntax/instructions.html#syntax-sx}{\mathit{sx}}^?\mathsf{\_zero}\)¶
Assert: due to syntax, \(N = 2 \cdot M\).
Assert: due to validation, a value of value type \(\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}\) is on the top of the stack.
Pop the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}.\href{../syntax/instructions.html#syntax-instr-vec}{\mathsf{const}}~c_1\) from the stack.
Let \(i^\ast\) be the result of computing \(\href{../exec/numerics.html#aux-lanes}{\mathrm{lanes}}_{t_1\mathsf{x}M}(c_1)\).
Let \(j^\ast\) be the result of computing \(\href{../syntax/instructions.html#syntax-vcvtop}{\mathit{vcvtop}}^{\href{../syntax/instructions.html#syntax-sx}{\mathit{sx}}^?}_{|t_1|,|t_2|}(i^\ast)\).
Let \(k^\ast\) be the concatenation of the two sequences \(j^\ast\) and \(0^M\).
Let \(c\) be the result of computing \(\href{../exec/numerics.html#aux-lanes}{\mathrm{lanes}}^{-1}_{t_2\mathsf{x}N}(k^\ast)\).
Push the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}.\href{../syntax/instructions.html#syntax-instr-vec}{\mathsf{const}}~c\) onto the stack.
\(\mathsf{i32x4.}\href{../syntax/instructions.html#syntax-instr-vec}{\mathsf{dot}}\mathsf{\_i16x8\_s}\)¶
Assert: due to validation, two values of value type \(\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}\) are on the top of the stack.
Pop the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}.\href{../syntax/instructions.html#syntax-instr-vec}{\mathsf{const}}~c_2\) from the stack.
Pop the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}.\href{../syntax/instructions.html#syntax-instr-vec}{\mathsf{const}}~c_1\) from the stack.
Let \(i_1^\ast\) be the result of computing \(\href{../exec/numerics.html#aux-lanes}{\mathrm{lanes}}_{\href{../syntax/types.html#syntax-valtype}{\mathsf{i16x8}}}(c_1)\).
Let \(j_1^\ast\) be the result of computing \(\href{../exec/numerics.html#op-extend-s}{\mathrm{extend}^{\mathsf{s}}}_{16,32}(i_1^\ast)\).
Let \(i_2^\ast\) be the result of computing \(\href{../exec/numerics.html#aux-lanes}{\mathrm{lanes}}_{\href{../syntax/types.html#syntax-valtype}{\mathsf{i16x8}}}(c_2)\).
Let \(j_2^\ast\) be the result of computing \(\href{../exec/numerics.html#op-extend-s}{\mathrm{extend}^{\mathsf{s}}}_{16,32}(i_2^\ast)\).
Let \((k_1~k_2)^\ast\) be the result of computing \(\href{../exec/numerics.html#op-imul}{\mathrm{imul}}_{32}(j_1^\ast, j_2^\ast)\).
Let \(k^\ast\) be the result of computing \(\href{../exec/numerics.html#op-iadd}{\mathrm{iadd}}_{32}(k_1, k_2)^\ast\).
Let \(c\) be the result of computing \(\href{../exec/numerics.html#aux-lanes}{\mathrm{lanes}}^{-1}_{\href{../syntax/types.html#syntax-valtype}{\mathsf{i32x4}}}(k^\ast)\).
Push the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}.\href{../syntax/instructions.html#syntax-instr-vec}{\mathsf{const}}~c\) onto the stack.
\(t_2\mathsf{x}N\mathsf{.}\href{../syntax/instructions.html#syntax-instr-vec}{\mathsf{extmul}}\mathsf{\_}\href{../syntax/instructions.html#syntax-half}{\mathit{half}}\mathsf{\_}t_1\mathsf{x}M\mathsf{\_}\href{../syntax/instructions.html#syntax-sx}{\mathit{sx}}\)¶
Assert: due to syntax, \(N = M / 2\).
Assert: due to validation, two values of value type \(\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}\) are on the top of the stack.
Pop the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}.\href{../syntax/instructions.html#syntax-instr-vec}{\mathsf{const}}~c_2\) from the stack.
Pop the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}.\href{../syntax/instructions.html#syntax-instr-vec}{\mathsf{const}}~c_1\) from the stack.
Let \(i_1^\ast\) be the result of computing \(\href{../exec/numerics.html#aux-lanes}{\mathrm{lanes}}_{t_1\mathsf{x}M}(c_1)\).
Let \(i_2^\ast\) be the result of computing \(\href{../exec/numerics.html#aux-lanes}{\mathrm{lanes}}_{t_1\mathsf{x}M}(c_2)\).
If \(\href{../syntax/instructions.html#syntax-half}{\mathit{half}}\) is \(\mathsf{low}\), then:
Let \(j_1^\ast\) be the sequence \(i_1^\ast[0 \href{../syntax/conventions.html#notation-slice}{\mathrel{\mathbf{:}}} N]\).
Let \(j_2^\ast\) be the sequence \(i_2^\ast[0 \href{../syntax/conventions.html#notation-slice}{\mathrel{\mathbf{:}}} N]\).
Else:
Let \(j_1^\ast\) be the sequence \(i_1^\ast[N \href{../syntax/conventions.html#notation-slice}{\mathrel{\mathbf{:}}} N]\).
Let \(j_2^\ast\) be the sequence \(i_2^\ast[N \href{../syntax/conventions.html#notation-slice}{\mathrel{\mathbf{:}}} N]\).
Let \(k_1^\ast\) be the result of computing \(\href{../exec/numerics.html#op-extend-u}{\mathrm{extend}}^{\href{../syntax/instructions.html#syntax-sx}{\mathit{sx}}}_{|t_1|,|t_2|}(j_1^\ast)\).
Let \(k_2^\ast\) be the result of computing \(\href{../exec/numerics.html#op-extend-u}{\mathrm{extend}}^{\href{../syntax/instructions.html#syntax-sx}{\mathit{sx}}}_{|t_1|,|t_2|}(j_2^\ast)\).
Let \(k^\ast\) be the result of computing \(\href{../exec/numerics.html#op-imul}{\mathrm{imul}}_{|t_2|}(k_1^\ast, k_2^\ast)\).
Let \(c\) be the result of computing \(\href{../exec/numerics.html#aux-lanes}{\mathrm{lanes}}^{-1}_{t_2\mathsf{x}N}(k^\ast)\).
Push the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}.\href{../syntax/instructions.html#syntax-instr-vec}{\mathsf{const}}~c\) onto the stack.
where:
\(t_2\mathsf{x}N\mathsf{.}\href{../syntax/instructions.html#syntax-instr-vec}{\mathsf{extadd\_pairwise}}\_t_1\mathsf{x}M\_\href{../syntax/instructions.html#syntax-sx}{\mathit{sx}}\)¶
Assert: due to syntax, \(N = M / 2\).
Assert: due to validation, a value of value type \(\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}\) is on the top of the stack.
Pop the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}.\href{../syntax/instructions.html#syntax-instr-vec}{\mathsf{const}}~c_1\) from the stack.
Let \(i^\ast\) be the result of computing \(\href{../exec/numerics.html#aux-lanes}{\mathrm{lanes}}_{t_1\mathsf{x}M}(c_1)\).
Let \((j_1~j_2)^\ast\) be the result of computing \(\href{../exec/numerics.html#op-extend-u}{\mathrm{extend}}^{\href{../syntax/instructions.html#syntax-sx}{\mathit{sx}}}_{|t_1|,|t_2|}(i^\ast)\).
Let \(k^\ast\) be the result of computing \(\href{../exec/numerics.html#op-iadd}{\mathrm{iadd}}_{|t_2|}(j_1, j_2)^\ast\).
Let \(c\) be the result of computing \(\href{../exec/numerics.html#aux-lanes}{\mathrm{lanes}}^{-1}_{t_2\mathsf{x}N}(k^\ast)\).
Push the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}.\href{../syntax/instructions.html#syntax-instr-vec}{\mathsf{const}}~c\) to the stack.
Parametric Instructions¶
\(\href{../syntax/instructions.html#syntax-instr-parametric}{\mathsf{drop}}\)¶
Assert: due to validation, a value is on the top of the stack.
Pop the value \(\href{../exec/runtime.html#syntax-val}{\mathit{val}}\) from the stack.
\(\href{../syntax/instructions.html#syntax-instr-parametric}{\mathsf{select}}~(t^\ast)^?\)¶
Assert: due to validation, a value of value type \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}\) is on the top of the stack.
Pop the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~c\) from the stack.
Assert: due to validation, two more values (of the same value type) are on the top of the stack.
Pop the value \(\href{../exec/runtime.html#syntax-val}{\mathit{val}}_2\) from the stack.
Pop the value \(\href{../exec/runtime.html#syntax-val}{\mathit{val}}_1\) from the stack.
If \(c\) is not \(0\), then:
Push the value \(\href{../exec/runtime.html#syntax-val}{\mathit{val}}_1\) back to the stack.
Else:
Push the value \(\href{../exec/runtime.html#syntax-val}{\mathit{val}}_2\) back to the stack.
Note
In future versions of WebAssembly, \(\href{../syntax/instructions.html#syntax-instr-parametric}{\mathsf{select}}\) may allow more than one value per choice.
Variable Instructions¶
\(\href{../syntax/instructions.html#syntax-instr-variable}{\mathsf{local.get}}~x\)¶
Assert: due to validation, \(F.\href{../exec/runtime.html#syntax-frame}{\mathsf{locals}}[x]\) exists and is non-empty.
Let \(\href{../exec/runtime.html#syntax-val}{\mathit{val}}\) be the value \(F.\href{../exec/runtime.html#syntax-frame}{\mathsf{locals}}[x]\).
Push the value \(\href{../exec/runtime.html#syntax-val}{\mathit{val}}\) to the stack.
\(\href{../syntax/instructions.html#syntax-instr-variable}{\mathsf{local.set}}~x\)¶
Assert: due to validation, \(F.\href{../exec/runtime.html#syntax-frame}{\mathsf{locals}}[x]\) exists.
Assert: due to validation, a value is on the top of the stack.
Pop the value \(\href{../exec/runtime.html#syntax-val}{\mathit{val}}\) from the stack.
Replace \(F.\href{../exec/runtime.html#syntax-frame}{\mathsf{locals}}[x]\) with the value \(\href{../exec/runtime.html#syntax-val}{\mathit{val}}\).
\(\href{../syntax/instructions.html#syntax-instr-variable}{\mathsf{local.tee}}~x\)¶
Assert: due to validation, a value is on the top of the stack.
Pop the value \(\href{../exec/runtime.html#syntax-val}{\mathit{val}}\) from the stack.
Push the value \(\href{../exec/runtime.html#syntax-val}{\mathit{val}}\) to the stack.
Push the value \(\href{../exec/runtime.html#syntax-val}{\mathit{val}}\) to the stack.
Execute the instruction \(\href{../syntax/instructions.html#syntax-instr-variable}{\mathsf{local.set}}~x\).
\(\href{../syntax/instructions.html#syntax-instr-variable}{\mathsf{global.get}}~x\)¶
Assert: due to validation, \(F.\href{../exec/runtime.html#syntax-frame}{\mathsf{module}}.\href{../exec/runtime.html#syntax-moduleinst}{\mathsf{globaladdrs}}[x]\) exists.
Let \(a\) be the global address \(F.\href{../exec/runtime.html#syntax-frame}{\mathsf{module}}.\href{../exec/runtime.html#syntax-moduleinst}{\mathsf{globaladdrs}}[x]\).
Assert: due to validation, \(S.\href{../exec/runtime.html#syntax-store}{\mathsf{globals}}[a]\) exists.
Let \(\mathit{glob}\) be the global instance \(S.\href{../exec/runtime.html#syntax-store}{\mathsf{globals}}[a]\).
Let \(\href{../exec/runtime.html#syntax-val}{\mathit{val}}\) be the value \(\mathit{glob}.\href{../exec/runtime.html#syntax-globalinst}{\mathsf{value}}\).
Push the value \(\href{../exec/runtime.html#syntax-val}{\mathit{val}}\) to the stack.
\(\href{../syntax/instructions.html#syntax-instr-variable}{\mathsf{global.set}}~x\)¶
Assert: due to validation, \(F.\href{../exec/runtime.html#syntax-frame}{\mathsf{module}}.\href{../exec/runtime.html#syntax-moduleinst}{\mathsf{globaladdrs}}[x]\) exists.
Let \(a\) be the global address \(F.\href{../exec/runtime.html#syntax-frame}{\mathsf{module}}.\href{../exec/runtime.html#syntax-moduleinst}{\mathsf{globaladdrs}}[x]\).
Assert: due to validation, \(S.\href{../exec/runtime.html#syntax-store}{\mathsf{globals}}[a]\) exists.
Let \(\mathit{glob}\) be the global instance \(S.\href{../exec/runtime.html#syntax-store}{\mathsf{globals}}[a]\).
Assert: due to validation, a value is on the top of the stack.
Pop the value \(\href{../exec/runtime.html#syntax-val}{\mathit{val}}\) from the stack.
Replace \(\mathit{glob}.\href{../exec/runtime.html#syntax-globalinst}{\mathsf{value}}\) with the value \(\href{../exec/runtime.html#syntax-val}{\mathit{val}}\).
Note
Validation ensures that the global is, in fact, marked as mutable.
Table Instructions¶
\(\href{../syntax/instructions.html#syntax-instr-table}{\mathsf{table.get}}~x\)¶
Assert: due to validation, \(F.\href{../exec/runtime.html#syntax-frame}{\mathsf{module}}.\href{../exec/runtime.html#syntax-moduleinst}{\mathsf{tableaddrs}}[x]\) exists.
Let \(a\) be the table address \(F.\href{../exec/runtime.html#syntax-frame}{\mathsf{module}}.\href{../exec/runtime.html#syntax-moduleinst}{\mathsf{tableaddrs}}[x]\).
Assert: due to validation, \(S.\href{../exec/runtime.html#syntax-store}{\mathsf{tables}}[a]\) exists.
Let \(\mathit{tab}\) be the table instance \(S.\href{../exec/runtime.html#syntax-store}{\mathsf{tables}}[a]\).
Assert: due to validation, a value of value type \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}\) is on the top of the stack.
Pop the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~i\) from the stack.
If \(i\) is not smaller than the length of \(\mathit{tab}.\href{../exec/runtime.html#syntax-tableinst}{\mathsf{elem}}\), then:
Trap.
Let \(\href{../exec/runtime.html#syntax-val}{\mathit{val}}\) be the value \(\mathit{tab}.\href{../exec/runtime.html#syntax-tableinst}{\mathsf{elem}}[i]\).
Push the value \(\href{../exec/runtime.html#syntax-val}{\mathit{val}}\) to the stack.
\(\href{../syntax/instructions.html#syntax-instr-table}{\mathsf{table.set}}~x\)¶
Assert: due to validation, \(F.\href{../exec/runtime.html#syntax-frame}{\mathsf{module}}.\href{../exec/runtime.html#syntax-moduleinst}{\mathsf{tableaddrs}}[x]\) exists.
Let \(a\) be the table address \(F.\href{../exec/runtime.html#syntax-frame}{\mathsf{module}}.\href{../exec/runtime.html#syntax-moduleinst}{\mathsf{tableaddrs}}[x]\).
Assert: due to validation, \(S.\href{../exec/runtime.html#syntax-store}{\mathsf{tables}}[a]\) exists.
Let \(\mathit{tab}\) be the table instance \(S.\href{../exec/runtime.html#syntax-store}{\mathsf{tables}}[a]\).
Assert: due to validation, a reference value is on the top of the stack.
Pop the value \(\href{../exec/runtime.html#syntax-val}{\mathit{val}}\) from the stack.
Assert: due to validation, a value of value type \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}\) is on the top of the stack.
Pop the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~i\) from the stack.
If \(i\) is not smaller than the length of \(\mathit{tab}.\href{../exec/runtime.html#syntax-tableinst}{\mathsf{elem}}\), then:
Trap.
Replace the element \(\mathit{tab}.\href{../exec/runtime.html#syntax-tableinst}{\mathsf{elem}}[i]\) with \(\href{../exec/runtime.html#syntax-val}{\mathit{val}}\).
\(\href{../syntax/instructions.html#syntax-instr-table}{\mathsf{table.size}}~x\)¶
Assert: due to validation, \(F.\href{../exec/runtime.html#syntax-frame}{\mathsf{module}}.\href{../exec/runtime.html#syntax-moduleinst}{\mathsf{tableaddrs}}[x]\) exists.
Let \(a\) be the table address \(F.\href{../exec/runtime.html#syntax-frame}{\mathsf{module}}.\href{../exec/runtime.html#syntax-moduleinst}{\mathsf{tableaddrs}}[x]\).
Assert: due to validation, \(S.\href{../exec/runtime.html#syntax-store}{\mathsf{tables}}[a]\) exists.
Let \(\mathit{tab}\) be the table instance \(S.\href{../exec/runtime.html#syntax-store}{\mathsf{tables}}[a]\).
Let \(\mathit{sz}\) be the length of \(\mathit{tab}.\href{../exec/runtime.html#syntax-tableinst}{\mathsf{elem}}\).
Push the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~\mathit{sz}\) to the stack.
\(\href{../syntax/instructions.html#syntax-instr-table}{\mathsf{table.grow}}~x\)¶
Assert: due to validation, \(F.\href{../exec/runtime.html#syntax-frame}{\mathsf{module}}.\href{../exec/runtime.html#syntax-moduleinst}{\mathsf{tableaddrs}}[x]\) exists.
Let \(a\) be the table address \(F.\href{../exec/runtime.html#syntax-frame}{\mathsf{module}}.\href{../exec/runtime.html#syntax-moduleinst}{\mathsf{tableaddrs}}[x]\).
Assert: due to validation, \(S.\href{../exec/runtime.html#syntax-store}{\mathsf{tables}}[a]\) exists.
Let \(\mathit{tab}\) be the table instance \(S.\href{../exec/runtime.html#syntax-store}{\mathsf{tables}}[a]\).
Let \(\mathit{sz}\) be the length of \(S.\href{../exec/runtime.html#syntax-store}{\mathsf{tables}}[a]\).
Assert: due to validation, a value of value type \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}\) is on the top of the stack.
Pop the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~n\) from the stack.
Assert: due to validation, a reference value is on the top of the stack.
Pop the value \(\href{../exec/runtime.html#syntax-val}{\mathit{val}}\) from the stack.
Let \(\mathit{err}\) be the \(\href{../syntax/values.html#syntax-int}{\mathit{i32}}\) value \(2^{32}-1\), for which \(\href{../exec/numerics.html#aux-signed}{\mathrm{signed}}_{32}(\mathit{err})\) is \(-1\).
Either:
If growing \(\mathit{tab}\) by \(n\) entries with initialization value \(\href{../exec/runtime.html#syntax-val}{\mathit{val}}\) succeeds, then:
Push the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~\mathit{sz}\) to the stack.
Else:
Push the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~\mathit{err}\) to the stack.
Or:
push the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~\mathit{err}\) to the stack.
Note
The \(\href{../syntax/instructions.html#syntax-instr-table}{\mathsf{table.grow}}\) instruction is non-deterministic. It may either succeed, returning the old table size \(\mathit{sz}\), or fail, returning \({-1}\). Failure must occur if the referenced table instance has a maximum size defined that would be exceeded. However, failure can occur in other cases as well. In practice, the choice depends on the resources available to the embedder.
\(\href{../syntax/instructions.html#syntax-instr-table}{\mathsf{table.fill}}~x\)¶
Assert: due to validation, \(F.\href{../exec/runtime.html#syntax-frame}{\mathsf{module}}.\href{../exec/runtime.html#syntax-moduleinst}{\mathsf{tableaddrs}}[x]\) exists.
Let \(\mathit{ta}\) be the table address \(F.\href{../exec/runtime.html#syntax-frame}{\mathsf{module}}.\href{../exec/runtime.html#syntax-moduleinst}{\mathsf{tableaddrs}}[x]\).
Assert: due to validation, \(S.\href{../exec/runtime.html#syntax-store}{\mathsf{tables}}[\mathit{ta}]\) exists.
Let \(\mathit{tab}\) be the table instance \(S.\href{../exec/runtime.html#syntax-store}{\mathsf{tables}}[\mathit{ta}]\).
Assert: due to validation, a value of value type \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}\) is on the top of the stack.
Pop the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~n\) from the stack.
Assert: due to validation, a reference value is on the top of the stack.
Pop the value \(\href{../exec/runtime.html#syntax-val}{\mathit{val}}\) from the stack.
Assert: due to validation, a value of value type \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}\) is on the top of the stack.
Pop the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~i\) from the stack.
If \(i + n\) is larger than the length of \(\mathit{tab}.\href{../exec/runtime.html#syntax-tableinst}{\mathsf{elem}}\), then:
Trap.
If \(n\) is \(0\), then:
Return.
Push the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~i\) to the stack.
Push the value \(\href{../exec/runtime.html#syntax-val}{\mathit{val}}\) to the stack.
Execute the instruction \(\href{../syntax/instructions.html#syntax-instr-table}{\mathsf{table.set}}~x\).
Push the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~(i+1)\) to the stack.
Push the value \(\href{../exec/runtime.html#syntax-val}{\mathit{val}}\) to the stack.
Push the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~(n-1)\) to the stack.
Execute the instruction \(\href{../syntax/instructions.html#syntax-instr-table}{\mathsf{table.fill}}~x\).
\(\href{../syntax/instructions.html#syntax-instr-table}{\mathsf{table.copy}}~x~y\)¶
Assert: due to validation, \(F.\href{../exec/runtime.html#syntax-frame}{\mathsf{module}}.\href{../exec/runtime.html#syntax-moduleinst}{\mathsf{tableaddrs}}[x]\) exists.
Let \(\mathit{ta}_x\) be the table address \(F.\href{../exec/runtime.html#syntax-frame}{\mathsf{module}}.\href{../exec/runtime.html#syntax-moduleinst}{\mathsf{tableaddrs}}[x]\).
Assert: due to validation, \(S.\href{../exec/runtime.html#syntax-store}{\mathsf{tables}}[\mathit{ta}_x]\) exists.
Let \(\mathit{tab}_x\) be the table instance \(S.\href{../exec/runtime.html#syntax-store}{\mathsf{tables}}[\mathit{ta}_x]\).
Assert: due to validation, \(F.\href{../exec/runtime.html#syntax-frame}{\mathsf{module}}.\href{../exec/runtime.html#syntax-moduleinst}{\mathsf{tableaddrs}}[y]\) exists.
Let \(\mathit{ta}_y\) be the table address \(F.\href{../exec/runtime.html#syntax-frame}{\mathsf{module}}.\href{../exec/runtime.html#syntax-moduleinst}{\mathsf{tableaddrs}}[y]\).
Assert: due to validation, \(S.\href{../exec/runtime.html#syntax-store}{\mathsf{tables}}[\mathit{ta}_y]\) exists.
Let \(\mathit{tab}_y\) be the table instance \(S.\href{../exec/runtime.html#syntax-store}{\mathsf{tables}}[\mathit{ta}_y]\).
Assert: due to validation, a value of value type \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}\) is on the top of the stack.
Pop the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~n\) from the stack.
Assert: due to validation, a value of value type \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}\) is on the top of the stack.
Pop the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~s\) from the stack.
Assert: due to validation, a value of value type \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}\) is on the top of the stack.
Pop the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~d\) from the stack.
If \(s + n\) is larger than the length of \(\mathit{tab}_y.\href{../exec/runtime.html#syntax-tableinst}{\mathsf{elem}}\) or \(d + n\) is larger than the length of \(\mathit{tab}_x.\href{../exec/runtime.html#syntax-tableinst}{\mathsf{elem}}\), then:
Trap.
If \(n = 0\), then:
Return.
If \(d \leq s\), then:
Push the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~d\) to the stack.
Push the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~s\) to the stack.
Execute the instruction \(\href{../syntax/instructions.html#syntax-instr-table}{\mathsf{table.get}}~y\).
Execute the instruction \(\href{../syntax/instructions.html#syntax-instr-table}{\mathsf{table.set}}~x\).
Assert: due to the earlier check against the table size, \(d+1 < 2^{32}\).
Push the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~(d+1)\) to the stack.
Assert: due to the earlier check against the table size, \(s+1 < 2^{32}\).
Push the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~(s+1)\) to the stack.
Else:
Assert: due to the earlier check against the table size, \(d+n-1 < 2^{32}\).
Push the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~(d+n-1)\) to the stack.
Assert: due to the earlier check against the table size, \(s+n-1 < 2^{32}\).
Push the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~(s+n-1)\) to the stack.
Execute the instruction \(\href{../syntax/instructions.html#syntax-instr-table}{\mathsf{table.get}}~y\).
Execute the instruction \(\href{../syntax/instructions.html#syntax-instr-table}{\mathsf{table.set}}~x\).
Push the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~d\) to the stack.
Push the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~s\) to the stack.
Push the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~(n-1)\) to the stack.
Execute the instruction \(\href{../syntax/instructions.html#syntax-instr-table}{\mathsf{table.copy}}~x~y\).
\(\href{../syntax/instructions.html#syntax-instr-table}{\mathsf{table.init}}~x~y\)¶
Assert: due to validation, \(F.\href{../exec/runtime.html#syntax-frame}{\mathsf{module}}.\href{../exec/runtime.html#syntax-moduleinst}{\mathsf{tableaddrs}}[x]\) exists.
Let \(\mathit{ta}\) be the table address \(F.\href{../exec/runtime.html#syntax-frame}{\mathsf{module}}.\href{../exec/runtime.html#syntax-moduleinst}{\mathsf{tableaddrs}}[x]\).
Assert: due to validation, \(S.\href{../exec/runtime.html#syntax-store}{\mathsf{tables}}[\mathit{ta}]\) exists.
Let \(\mathit{tab}\) be the table instance \(S.\href{../exec/runtime.html#syntax-store}{\mathsf{tables}}[\mathit{ta}]\).
Assert: due to validation, \(F.\href{../exec/runtime.html#syntax-frame}{\mathsf{module}}.\href{../exec/runtime.html#syntax-moduleinst}{\mathsf{elemaddrs}}[y]\) exists.
Let \(\mathit{ea}\) be the element address \(F.\href{../exec/runtime.html#syntax-frame}{\mathsf{module}}.\href{../exec/runtime.html#syntax-moduleinst}{\mathsf{elemaddrs}}[y]\).
Assert: due to validation, \(S.\href{../exec/runtime.html#syntax-store}{\mathsf{elems}}[\mathit{ea}]\) exists.
Let \(\mathit{elem}\) be the element instance \(S.\href{../exec/runtime.html#syntax-store}{\mathsf{elems}}[\mathit{ea}]\).
Assert: due to validation, a value of value type \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}\) is on the top of the stack.
Pop the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~n\) from the stack.
Assert: due to validation, a value of value type \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}\) is on the top of the stack.
Pop the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~s\) from the stack.
Assert: due to validation, a value of value type \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}\) is on the top of the stack.
Pop the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~d\) from the stack.
If \(s + n\) is larger than the length of \(\mathit{elem}.\href{../exec/runtime.html#syntax-eleminst}{\mathsf{elem}}\) or \(d + n\) is larger than the length of \(\mathit{tab}.\href{../exec/runtime.html#syntax-tableinst}{\mathsf{elem}}\), then:
Trap.
If \(n = 0\), then:
Return.
Let \(\href{../exec/runtime.html#syntax-val}{\mathit{val}}\) be the reference value \(\mathit{elem}.\href{../exec/runtime.html#syntax-eleminst}{\mathsf{elem}}[s]\).
Push the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~d\) to the stack.
Push the value \(\href{../exec/runtime.html#syntax-val}{\mathit{val}}\) to the stack.
Execute the instruction \(\href{../syntax/instructions.html#syntax-instr-table}{\mathsf{table.set}}~x\).
Assert: due to the earlier check against the table size, \(d+1 < 2^{32}\).
Push the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~(d+1)\) to the stack.
Assert: due to the earlier check against the segment size, \(s+1 < 2^{32}\).
Push the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~(s+1)\) to the stack.
Push the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~(n-1)\) to the stack.
Execute the instruction \(\href{../syntax/instructions.html#syntax-instr-table}{\mathsf{table.init}}~x~y\).
\(\href{../syntax/instructions.html#syntax-instr-table}{\mathsf{elem.drop}}~x\)¶
Assert: due to validation, \(F.\href{../exec/runtime.html#syntax-frame}{\mathsf{module}}.\href{../exec/runtime.html#syntax-moduleinst}{\mathsf{elemaddrs}}[x]\) exists.
Let \(a\) be the element address \(F.\href{../exec/runtime.html#syntax-frame}{\mathsf{module}}.\href{../exec/runtime.html#syntax-moduleinst}{\mathsf{elemaddrs}}[x]\).
Assert: due to validation, \(S.\href{../exec/runtime.html#syntax-store}{\mathsf{elems}}[a]\) exists.
Replace \(S.\href{../exec/runtime.html#syntax-store}{\mathsf{elems}}[a].\href{../exec/runtime.html#syntax-eleminst}{\mathsf{elem}}\) with \(\epsilon\).
Memory Instructions¶
Note
The alignment \(\href{../syntax/instructions.html#syntax-memarg}{\mathit{memarg}}.\href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{align}}\) in load and store instructions does not affect the semantics. It is an indication that the offset \(\mathit{ea}\) at which the memory is accessed is intended to satisfy the property \(\mathit{ea} \mathbin{\mathrm{mod}} 2^{\href{../syntax/instructions.html#syntax-memarg}{\mathit{memarg}}.\href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{align}}} = 0\). A WebAssembly implementation can use this hint to optimize for the intended use. Unaligned access violating that property is still allowed and must succeed regardless of the annotation. However, it may be substantially slower on some hardware.
\(t\mathsf{.}\href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{load}}~x~\href{../syntax/instructions.html#syntax-memarg}{\mathit{memarg}}\) and \(t\mathsf{.}\href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{load}}{N}\mathsf{\_}\href{../syntax/instructions.html#syntax-sx}{\mathit{sx}}~x~\href{../syntax/instructions.html#syntax-memarg}{\mathit{memarg}}\)¶
Assert: due to validation, \(F.\href{../exec/runtime.html#syntax-frame}{\mathsf{module}}.\href{../exec/runtime.html#syntax-moduleinst}{\mathsf{memaddrs}}[x]\) exists.
Let \(a\) be the memory address \(F.\href{../exec/runtime.html#syntax-frame}{\mathsf{module}}.\href{../exec/runtime.html#syntax-moduleinst}{\mathsf{memaddrs}}[x]\).
Assert: due to validation, \(S.\href{../exec/runtime.html#syntax-store}{\mathsf{mems}}[a]\) exists.
Let \(\mathit{mem}\) be the memory instance \(S.\href{../exec/runtime.html#syntax-store}{\mathsf{mems}}[a]\).
Assert: due to validation, a value of value type \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}\) is on the top of the stack.
Pop the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~i\) from the stack.
Let \(\mathit{ea}\) be the integer \(i + \href{../syntax/instructions.html#syntax-memarg}{\mathit{memarg}}.\href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{offset}}\).
If \(N\) is not part of the instruction, then:
Let \(N\) be the bit width \(|t|\) of number type \(t\).
If \(\mathit{ea} + N/8\) is larger than the length of \(\mathit{mem}.\href{../exec/runtime.html#syntax-meminst}{\mathsf{data}}\), then:
Trap.
Let \(b^\ast\) be the byte sequence \(\mathit{mem}.\href{../exec/runtime.html#syntax-meminst}{\mathsf{data}}[\mathit{ea} \href{../syntax/conventions.html#notation-slice}{\mathrel{\mathbf{:}}} N/8]\).
If \(N\) and \(\href{../syntax/instructions.html#syntax-sx}{\mathit{sx}}\) are part of the instruction, then:
Let \(n\) be the integer for which \(\href{../exec/numerics.html#aux-bytes}{\mathrm{bytes}}_{\href{../syntax/values.html#syntax-int}{\mathit{i}N}}(n) = b^\ast\).
Let \(c\) be the result of computing \(\href{../exec/numerics.html#op-extend-u}{\mathrm{extend}}^{\href{../syntax/instructions.html#syntax-sx}{\mathit{sx}}}_{N,|t|}(n)\).
Else:
Let \(c\) be the constant for which \(\href{../exec/numerics.html#aux-bytes}{\mathrm{bytes}}_t(c) = b^\ast\).
Push the value \(t.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~c\) to the stack.
\(\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}\mathsf{.}\href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{load}}{M}\mathsf{x}N\_\href{../syntax/instructions.html#syntax-sx}{\mathit{sx}}~x~\href{../syntax/instructions.html#syntax-memarg}{\mathit{memarg}}\)¶
Assert: due to validation, \(F.\href{../exec/runtime.html#syntax-frame}{\mathsf{module}}.\href{../exec/runtime.html#syntax-moduleinst}{\mathsf{memaddrs}}[x]\) exists.
Let \(a\) be the memory address \(F.\href{../exec/runtime.html#syntax-frame}{\mathsf{module}}.\href{../exec/runtime.html#syntax-moduleinst}{\mathsf{memaddrs}}[x]\).
Assert: due to validation, \(S.\href{../exec/runtime.html#syntax-store}{\mathsf{mems}}[a]\) exists.
Let \(\mathit{mem}\) be the memory instance \(S.\href{../exec/runtime.html#syntax-store}{\mathsf{mems}}[a]\).
Assert: due to validation, a value of value type \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}\) is on the top of the stack.
Pop the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~i\) from the stack.
Let \(\mathit{ea}\) be the integer \(i + \href{../syntax/instructions.html#syntax-memarg}{\mathit{memarg}}.\href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{offset}}\).
If \(\mathit{ea} + M \cdot N /8\) is larger than the length of \(\mathit{mem}.\href{../exec/runtime.html#syntax-meminst}{\mathsf{data}}\), then:
Trap.
Let \(b^\ast\) be the byte sequence \(\mathit{mem}.\href{../exec/runtime.html#syntax-meminst}{\mathsf{data}}[\mathit{ea} \href{../syntax/conventions.html#notation-slice}{\mathrel{\mathbf{:}}} M \cdot N /8]\).
Let \(m_k\) be the integer for which \(\href{../exec/numerics.html#aux-bytes}{\mathrm{bytes}}_{\href{../syntax/values.html#syntax-int}{\mathit{i}M}}(m_k) = b^\ast[k \cdot M/8 \href{../syntax/conventions.html#notation-slice}{\mathrel{\mathbf{:}}} M/8]\).
Let \(W\) be the integer \(M \cdot 2\).
Let \(n_k\) be the result of computing \(\href{../exec/numerics.html#op-extend-u}{\mathrm{extend}}^{\href{../syntax/instructions.html#syntax-sx}{\mathit{sx}}}_{M,W}(m_k)\).
Let \(c\) be the result of computing \(\href{../exec/numerics.html#aux-lanes}{\mathrm{lanes}}^{-1}_{\mathsf{i}W\mathsf{x}N}(n_0 \dots n_{N-1})\).
Push the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~c\) to the stack.
\(\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}\mathsf{.}\href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{load}}{N}\mathsf{\_splat}~x~\href{../syntax/instructions.html#syntax-memarg}{\mathit{memarg}}\)¶
Assert: due to validation, \(F.\href{../exec/runtime.html#syntax-frame}{\mathsf{module}}.\href{../exec/runtime.html#syntax-moduleinst}{\mathsf{memaddrs}}[x]\) exists.
Let \(a\) be the memory address \(F.\href{../exec/runtime.html#syntax-frame}{\mathsf{module}}.\href{../exec/runtime.html#syntax-moduleinst}{\mathsf{memaddrs}}[x]\).
Assert: due to validation, \(S.\href{../exec/runtime.html#syntax-store}{\mathsf{mems}}[a]\) exists.
Let \(\mathit{mem}\) be the memory instance \(S.\href{../exec/runtime.html#syntax-store}{\mathsf{mems}}[a]\).
Assert: due to validation, a value of value type \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}\) is on the top of the stack.
Pop the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~i\) from the stack.
Let \(\mathit{ea}\) be the integer \(i + \href{../syntax/instructions.html#syntax-memarg}{\mathit{memarg}}.\href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{offset}}\).
If \(\mathit{ea} + N/8\) is larger than the length of \(\mathit{mem}.\href{../exec/runtime.html#syntax-meminst}{\mathsf{data}}\), then:
Trap.
Let \(b^\ast\) be the byte sequence \(\mathit{mem}.\href{../exec/runtime.html#syntax-meminst}{\mathsf{data}}[\mathit{ea} \href{../syntax/conventions.html#notation-slice}{\mathrel{\mathbf{:}}} N/8]\).
Let \(n\) be the integer for which \(\href{../exec/numerics.html#aux-bytes}{\mathrm{bytes}}_{\href{../syntax/values.html#syntax-int}{\mathit{i}N}}(n) = b^\ast\).
Let \(L\) be the integer \(128 / N\).
Let \(c\) be the result of computing \(\href{../exec/numerics.html#aux-lanes}{\mathrm{lanes}}^{-1}_{\href{../syntax/types.html#syntax-valtype}{\mathsf{i}N}\mathsf{x}L}(n^L)\).
Push the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~c\) to the stack.
\(\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}\mathsf{.}\href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{load}}{N}\mathsf{\_zero}~x~\href{../syntax/instructions.html#syntax-memarg}{\mathit{memarg}}\)¶
Assert: due to validation, \(F.\href{../exec/runtime.html#syntax-frame}{\mathsf{module}}.\href{../exec/runtime.html#syntax-moduleinst}{\mathsf{memaddrs}}[x]\) exists.
Let \(a\) be the memory address \(F.\href{../exec/runtime.html#syntax-frame}{\mathsf{module}}.\href{../exec/runtime.html#syntax-moduleinst}{\mathsf{memaddrs}}[x]\).
Assert: due to validation, \(S.\href{../exec/runtime.html#syntax-store}{\mathsf{mems}}[a]\) exists.
Let \(\mathit{mem}\) be the memory instance \(S.\href{../exec/runtime.html#syntax-store}{\mathsf{mems}}[a]\).
Assert: due to validation, a value of value type \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}\) is on the top of the stack.
Pop the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~i\) from the stack.
Let \(\mathit{ea}\) be the integer \(i + \href{../syntax/instructions.html#syntax-memarg}{\mathit{memarg}}.\href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{offset}}\).
If \(\mathit{ea} + N/8\) is larger than the length of \(\mathit{mem}.\href{../exec/runtime.html#syntax-meminst}{\mathsf{data}}\), then:
Trap.
Let \(b^\ast\) be the byte sequence \(\mathit{mem}.\href{../exec/runtime.html#syntax-meminst}{\mathsf{data}}[\mathit{ea} \href{../syntax/conventions.html#notation-slice}{\mathrel{\mathbf{:}}} N/8]\).
Let \(n\) be the integer for which \(\href{../exec/numerics.html#aux-bytes}{\mathrm{bytes}}_{\href{../syntax/values.html#syntax-int}{\mathit{i}N}}(n) = b^\ast\).
Let \(c\) be the result of computing \(\href{../exec/numerics.html#op-extend-u}{\mathrm{extend}^{\mathsf{u}}}_{N,128}(n)\).
Push the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~c\) to the stack.
\(\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}\mathsf{.}\href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{load}}{N}\mathsf{\_lane}~x~\href{../syntax/instructions.html#syntax-memarg}{\mathit{memarg}}~y\)¶
Assert: due to validation, \(F.\href{../exec/runtime.html#syntax-frame}{\mathsf{module}}.\href{../exec/runtime.html#syntax-moduleinst}{\mathsf{memaddrs}}[x]\) exists.
Let \(a\) be the memory address \(F.\href{../exec/runtime.html#syntax-frame}{\mathsf{module}}.\href{../exec/runtime.html#syntax-moduleinst}{\mathsf{memaddrs}}[x]\).
Assert: due to validation, \(S.\href{../exec/runtime.html#syntax-store}{\mathsf{mems}}[a]\) exists.
Let \(\mathit{mem}\) be the memory instance \(S.\href{../exec/runtime.html#syntax-store}{\mathsf{mems}}[a]\).
Assert: due to validation, a value of value type \(\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}\) is on the top of the stack.
Pop the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~v\) from the stack.
Assert: due to validation, a value of value type \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}\) is on the top of the stack.
Pop the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~i\) from the stack.
Let \(\mathit{ea}\) be the integer \(i + \href{../syntax/instructions.html#syntax-memarg}{\mathit{memarg}}.\href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{offset}}\).
If \(\mathit{ea} + N/8\) is larger than the length of \(\mathit{mem}.\href{../exec/runtime.html#syntax-meminst}{\mathsf{data}}\), then:
Trap.
Let \(b^\ast\) be the byte sequence \(\mathit{mem}.\href{../exec/runtime.html#syntax-meminst}{\mathsf{data}}[\mathit{ea} \href{../syntax/conventions.html#notation-slice}{\mathrel{\mathbf{:}}} N/8]\).
Let \(r\) be the constant for which \(\href{../exec/numerics.html#aux-bytes}{\mathrm{bytes}}_{\href{../syntax/values.html#syntax-int}{\mathit{i}N}}(r) = b^\ast\).
Let \(L\) be \(128 / N\).
Let \(j^\ast\) be the result of computing \(\href{../exec/numerics.html#aux-lanes}{\mathrm{lanes}}_{\href{../syntax/types.html#syntax-valtype}{\mathsf{i}N}\mathsf{x}L}(v)\).
Let \(c\) be the result of computing \(\href{../exec/numerics.html#aux-lanes}{\mathrm{lanes}}^{-1}_{\href{../syntax/types.html#syntax-valtype}{\mathsf{i}N}\mathsf{x}L}(j^\ast \href{../syntax/conventions.html#notation-replace}{\mathrel{\mbox{with}}} [y] = r)\).
Push the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~c\) to the stack.
\(t\mathsf{.}\href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{store}}~x~\href{../syntax/instructions.html#syntax-memarg}{\mathit{memarg}}\) and \(t\mathsf{.}\href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{store}}{N}~x~\href{../syntax/instructions.html#syntax-memarg}{\mathit{memarg}}\)¶
Assert: due to validation, \(F.\href{../exec/runtime.html#syntax-frame}{\mathsf{module}}.\href{../exec/runtime.html#syntax-moduleinst}{\mathsf{memaddrs}}[x]\) exists.
Let \(a\) be the memory address \(F.\href{../exec/runtime.html#syntax-frame}{\mathsf{module}}.\href{../exec/runtime.html#syntax-moduleinst}{\mathsf{memaddrs}}[x]\).
Assert: due to validation, \(S.\href{../exec/runtime.html#syntax-store}{\mathsf{mems}}[a]\) exists.
Let \(\mathit{mem}\) be the memory instance \(S.\href{../exec/runtime.html#syntax-store}{\mathsf{mems}}[a]\).
Assert: due to validation, a value of value type \(t\) is on the top of the stack.
Pop the value \(t.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~c\) from the stack.
Assert: due to validation, a value of value type \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}\) is on the top of the stack.
Pop the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~i\) from the stack.
Let \(\mathit{ea}\) be the integer \(i + \href{../syntax/instructions.html#syntax-memarg}{\mathit{memarg}}.\href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{offset}}\).
If \(N\) is not part of the instruction, then:
Let \(N\) be the bit width \(|t|\) of number type \(t\).
If \(\mathit{ea} + N/8\) is larger than the length of \(\mathit{mem}.\href{../exec/runtime.html#syntax-meminst}{\mathsf{data}}\), then:
Trap.
If \(N\) is part of the instruction, then:
Let \(n\) be the result of computing \(\href{../exec/numerics.html#op-wrap}{\mathrm{wrap}}_{|t|,N}(c)\).
Let \(b^\ast\) be the byte sequence \(\href{../exec/numerics.html#aux-bytes}{\mathrm{bytes}}_{\href{../syntax/values.html#syntax-int}{\mathit{i}N}}(n)\).
Else:
Let \(b^\ast\) be the byte sequence \(\href{../exec/numerics.html#aux-bytes}{\mathrm{bytes}}_t(c)\).
Replace the bytes \(\mathit{mem}.\href{../exec/runtime.html#syntax-meminst}{\mathsf{data}}[\mathit{ea} \href{../syntax/conventions.html#notation-slice}{\mathrel{\mathbf{:}}} N/8]\) with \(b^\ast\).
\(\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}\mathsf{.}\href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{store}}{N}\mathsf{\_lane}~x~\href{../syntax/instructions.html#syntax-memarg}{\mathit{memarg}}~y\)¶
Assert: due to validation, \(F.\href{../exec/runtime.html#syntax-frame}{\mathsf{module}}.\href{../exec/runtime.html#syntax-moduleinst}{\mathsf{memaddrs}}[x]\) exists.
Let \(a\) be the memory address \(F.\href{../exec/runtime.html#syntax-frame}{\mathsf{module}}.\href{../exec/runtime.html#syntax-moduleinst}{\mathsf{memaddrs}}[x]\).
Assert: due to validation, \(S.\href{../exec/runtime.html#syntax-store}{\mathsf{mems}}[a]\) exists.
Let \(\mathit{mem}\) be the memory instance \(S.\href{../exec/runtime.html#syntax-store}{\mathsf{mems}}[a]\).
Assert: due to validation, a value of value type \(\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}\) is on the top of the stack.
Pop the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~c\) from the stack.
Assert: due to validation, a value of value type \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}\) is on the top of the stack.
Pop the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~i\) from the stack.
Let \(\mathit{ea}\) be the integer \(i + \href{../syntax/instructions.html#syntax-memarg}{\mathit{memarg}}.\href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{offset}}\).
If \(\mathit{ea} + N/8\) is larger than the length of \(\mathit{mem}.\href{../exec/runtime.html#syntax-meminst}{\mathsf{data}}\), then:
Trap.
Let \(L\) be \(128/N\).
Let \(j^\ast\) be the result of computing \(\href{../exec/numerics.html#aux-lanes}{\mathrm{lanes}}_{\href{../syntax/types.html#syntax-valtype}{\mathsf{i}N}\mathsf{x}L}(c)\).
Let \(b^\ast\) be the result of computing \(\href{../exec/numerics.html#aux-bytes}{\mathrm{bytes}}_{\href{../syntax/values.html#syntax-int}{\mathit{i}N}}(j^\ast[y])\).
Replace the bytes \(\mathit{mem}.\href{../exec/runtime.html#syntax-meminst}{\mathsf{data}}[\mathit{ea} \href{../syntax/conventions.html#notation-slice}{\mathrel{\mathbf{:}}} N/8]\) with \(b^\ast\).
\(\href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{memory.size}}~x\)¶
Assert: due to validation, \(F.\href{../exec/runtime.html#syntax-frame}{\mathsf{module}}.\href{../exec/runtime.html#syntax-moduleinst}{\mathsf{memaddrs}}[x]\) exists.
Let \(a\) be the memory address \(F.\href{../exec/runtime.html#syntax-frame}{\mathsf{module}}.\href{../exec/runtime.html#syntax-moduleinst}{\mathsf{memaddrs}}[x]\).
Assert: due to validation, \(S.\href{../exec/runtime.html#syntax-store}{\mathsf{mems}}[a]\) exists.
Let \(\mathit{mem}\) be the memory instance \(S.\href{../exec/runtime.html#syntax-store}{\mathsf{mems}}[a]\).
Let \(\mathit{sz}\) be the length of \(\mathit{mem}.\href{../exec/runtime.html#syntax-meminst}{\mathsf{data}}\) divided by the page size.
Push the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~\mathit{sz}\) to the stack.
\(\href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{memory.grow}}~x\)¶
Assert: due to validation, \(F.\href{../exec/runtime.html#syntax-frame}{\mathsf{module}}.\href{../exec/runtime.html#syntax-moduleinst}{\mathsf{memaddrs}}[x]\) exists.
Let \(a\) be the memory address \(F.\href{../exec/runtime.html#syntax-frame}{\mathsf{module}}.\href{../exec/runtime.html#syntax-moduleinst}{\mathsf{memaddrs}}[x]\).
Assert: due to validation, \(S.\href{../exec/runtime.html#syntax-store}{\mathsf{mems}}[a]\) exists.
Let \(\mathit{mem}\) be the memory instance \(S.\href{../exec/runtime.html#syntax-store}{\mathsf{mems}}[a]\).
Let \(\mathit{sz}\) be the length of \(S.\href{../exec/runtime.html#syntax-store}{\mathsf{mems}}[a]\) divided by the page size.
Assert: due to validation, a value of value type \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}\) is on the top of the stack.
Pop the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~n\) from the stack.
Let \(\mathit{err}\) be the \(\href{../syntax/values.html#syntax-int}{\mathit{i32}}\) value \(2^{32}-1\), for which \(\href{../exec/numerics.html#aux-signed}{\mathrm{signed}}_{32}(\mathit{err})\) is \(-1\).
Either:
If growing \(\mathit{mem}\) by \(n\) pages succeeds, then:
Push the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~\mathit{sz}\) to the stack.
Else:
Push the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~\mathit{err}\) to the stack.
Or:
Push the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~\mathit{err}\) to the stack.
Note
The \(\href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{memory.grow}}\) instruction is non-deterministic. It may either succeed, returning the old memory size \(\mathit{sz}\), or fail, returning \({-1}\). Failure must occur if the referenced memory instance has a maximum size defined that would be exceeded. However, failure can occur in other cases as well. In practice, the choice depends on the resources available to the embedder.
\(\href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{memory.fill}}~x\)¶
Assert: due to validation, \(F.\href{../exec/runtime.html#syntax-frame}{\mathsf{module}}.\href{../exec/runtime.html#syntax-moduleinst}{\mathsf{memaddrs}}[x]\) exists.
Let \(\mathit{ma}\) be the memory address \(F.\href{../exec/runtime.html#syntax-frame}{\mathsf{module}}.\href{../exec/runtime.html#syntax-moduleinst}{\mathsf{memaddrs}}[x]\).
Assert: due to validation, \(S.\href{../exec/runtime.html#syntax-store}{\mathsf{mems}}[\mathit{ma}]\) exists.
Let \(\mathit{mem}\) be the memory instance \(S.\href{../exec/runtime.html#syntax-store}{\mathsf{mems}}[\mathit{ma}]\).
Assert: due to validation, a value of value type \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}\) is on the top of the stack.
Pop the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~n\) from the stack.
Assert: due to validation, a value of value type \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}\) is on the top of the stack.
Pop the value \(\href{../exec/runtime.html#syntax-val}{\mathit{val}}\) from the stack.
Assert: due to validation, a value of value type \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}\) is on the top of the stack.
Pop the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~d\) from the stack.
If \(d + n\) is larger than the length of \(\mathit{mem}.\href{../exec/runtime.html#syntax-meminst}{\mathsf{data}}\), then:
Trap.
If \(n = 0\), then:
Return.
Push the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~d\) to the stack.
Push the value \(\href{../exec/runtime.html#syntax-val}{\mathit{val}}\) to the stack.
Execute the instruction \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}\mathsf{.}\href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{store}}\mathsf{8}~\{ \href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{offset}}~0, \href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{align}}~0 \}\).
Assert: due to the earlier check against the memory size, \(d+1 < 2^{32}\).
Push the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~(d+1)\) to the stack.
Push the value \(\href{../exec/runtime.html#syntax-val}{\mathit{val}}\) to the stack.
Push the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~(n-1)\) to the stack.
Execute the instruction \(\href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{memory.fill}}~x\).
\(\href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{memory.copy}}~x~y\)¶
Assert: due to validation, \(F.\href{../exec/runtime.html#syntax-frame}{\mathsf{module}}.\href{../exec/runtime.html#syntax-moduleinst}{\mathsf{memaddrs}}[x]\) exists.
Assert: due to validation, \(F.\href{../exec/runtime.html#syntax-frame}{\mathsf{module}}.\href{../exec/runtime.html#syntax-moduleinst}{\mathsf{memaddrs}}[y]\) exists.
Let \(\mathit{da}\) be the memory address \(F.\href{../exec/runtime.html#syntax-frame}{\mathsf{module}}.\href{../exec/runtime.html#syntax-moduleinst}{\mathsf{memaddrs}}[x]\).
Let \(\mathit{sa}\) be the memory address \(F.\href{../exec/runtime.html#syntax-frame}{\mathsf{module}}.\href{../exec/runtime.html#syntax-moduleinst}{\mathsf{memaddrs}}[y]\).
Assert: due to validation, \(S.\href{../exec/runtime.html#syntax-store}{\mathsf{mems}}[\mathit{da}]\) exists.
Assert: due to validation, \(S.\href{../exec/runtime.html#syntax-store}{\mathsf{mems}}[\mathit{sa}]\) exists.
Let \(\mathit{mem}_d\) be the memory instance \(S.\href{../exec/runtime.html#syntax-store}{\mathsf{mems}}[\mathit{da}]\).
Let \(\mathit{mem}_s\) be the memory instance \(S.\href{../exec/runtime.html#syntax-store}{\mathsf{mems}}[\mathit{sa}]\).
Assert: due to validation, a value of value type \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}\) is on the top of the stack.
Pop the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~n\) from the stack.
Assert: due to validation, a value of value type \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}\) is on the top of the stack.
Pop the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~s\) from the stack.
Assert: due to validation, a value of value type \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}\) is on the top of the stack.
Pop the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~d\) from the stack.
If \(s + n\) is larger than the length of \(\mathit{mem}_s.\href{../exec/runtime.html#syntax-meminst}{\mathsf{data}}\) or \(d + n\) is larger than the length of \(\mathit{mem}_d.\href{../exec/runtime.html#syntax-meminst}{\mathsf{data}}\), then:
Trap.
If \(n = 0\), then:
Return.
If \(d \leq s\), then:
Push the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~d\) to the stack.
Push the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~s\) to the stack.
Execute the instruction \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}\mathsf{.}\href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{load}}\mathsf{8\_u}~y~\{ \href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{offset}}~0, \href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{align}}~0 \}\).
Execute the instruction \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}\mathsf{.}\href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{store}}\mathsf{8}~x~\{ \href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{offset}}~0, \href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{align}}~0 \}\).
Assert: due to the earlier check against the memory size, \(d+1 < 2^{32}\).
Push the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~(d+1)\) to the stack.
Assert: due to the earlier check against the memory size, \(s+1 < 2^{32}\).
Push the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~(s+1)\) to the stack.
Else:
Assert: due to the earlier check against the memory size, \(d+n-1 < 2^{32}\).
Push the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~(d+n-1)\) to the stack.
Assert: due to the earlier check against the memory size, \(s+n-1 < 2^{32}\).
Push the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~(s+n-1)\) to the stack.
Execute the instruction \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}\mathsf{.}\href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{load}}\mathsf{8\_u}~y~\{ \href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{offset}}~0, \href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{align}}~0 \}\).
Execute the instruction \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}\mathsf{.}\href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{store}}\mathsf{8}~x~\{ \href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{offset}}~0, \href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{align}}~0 \}\).
Push the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~d\) to the stack.
Push the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~s\) to the stack.
Push the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~(n-1)\) to the stack.
Execute the instruction \(\href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{memory.copy}}~x~y\).
\(\href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{memory.init}}~x~y\)¶
Assert: due to validation, \(F.\href{../exec/runtime.html#syntax-frame}{\mathsf{module}}.\href{../exec/runtime.html#syntax-moduleinst}{\mathsf{memaddrs}}[x]\) exists.
Let \(\mathit{ma}\) be the memory address \(F.\href{../exec/runtime.html#syntax-frame}{\mathsf{module}}.\href{../exec/runtime.html#syntax-moduleinst}{\mathsf{memaddrs}}[x]\).
Assert: due to validation, \(S.\href{../exec/runtime.html#syntax-store}{\mathsf{mems}}[\mathit{ma}]\) exists.
Let \(\mathit{mem}\) be the memory instance \(S.\href{../exec/runtime.html#syntax-store}{\mathsf{mems}}[\mathit{ma}]\).
Assert: due to validation, \(F.\href{../exec/runtime.html#syntax-frame}{\mathsf{module}}.\href{../exec/runtime.html#syntax-moduleinst}{\mathsf{dataaddrs}}[y]\) exists.
Let \(\mathit{da}\) be the data address \(F.\href{../exec/runtime.html#syntax-frame}{\mathsf{module}}.\href{../exec/runtime.html#syntax-moduleinst}{\mathsf{dataaddrs}}[y]\).
Assert: due to validation, \(S.\href{../exec/runtime.html#syntax-store}{\mathsf{datas}}[\mathit{da}]\) exists.
Let \(\mathit{data}\) be the data instance \(S.\href{../exec/runtime.html#syntax-store}{\mathsf{datas}}[\mathit{da}]\).
Assert: due to validation, a value of value type \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}\) is on the top of the stack.
Pop the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~n\) from the stack.
Assert: due to validation, a value of value type \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}\) is on the top of the stack.
Pop the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~s\) from the stack.
Assert: due to validation, a value of value type \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}\) is on the top of the stack.
Pop the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~d\) from the stack.
If \(s + n\) is larger than the length of \(\mathit{data}.\href{../exec/runtime.html#syntax-datainst}{\mathsf{data}}\) or \(d + n\) is larger than the length of \(\mathit{mem}.\href{../exec/runtime.html#syntax-meminst}{\mathsf{data}}\), then:
Trap.
If \(n = 0\), then:
Return.
Let \(b\) be the byte \(\mathit{data}.\href{../exec/runtime.html#syntax-datainst}{\mathsf{data}}[s]\).
Push the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~d\) to the stack.
Push the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~b\) to the stack.
Execute the instruction \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}\mathsf{.}\href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{store}}\mathsf{8}~x~\{ \href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{offset}}~0, \href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{align}}~0 \}\).
Assert: due to the earlier check against the memory size, \(d+1 < 2^{32}\).
Push the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~(d+1)\) to the stack.
Assert: due to the earlier check against the memory size, \(s+1 < 2^{32}\).
Push the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~(s+1)\) to the stack.
Push the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~(n-1)\) to the stack.
Execute the instruction \(\href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{memory.init}}~x~y\).
\(\href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{data.drop}}~x\)¶
Assert: due to validation, \(F.\href{../exec/runtime.html#syntax-frame}{\mathsf{module}}.\href{../exec/runtime.html#syntax-moduleinst}{\mathsf{dataaddrs}}[x]\) exists.
Let \(a\) be the data address \(F.\href{../exec/runtime.html#syntax-frame}{\mathsf{module}}.\href{../exec/runtime.html#syntax-moduleinst}{\mathsf{dataaddrs}}[x]\).
Assert: due to validation, \(S.\href{../exec/runtime.html#syntax-store}{\mathsf{datas}}[a]\) exists.
Replace \(S.\href{../exec/runtime.html#syntax-store}{\mathsf{datas}}[a]\) with the data instance \(\{\href{../exec/runtime.html#syntax-datainst}{\mathsf{data}}~\epsilon\}\).
Control Instructions¶
\(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{nop}}\)¶
Do nothing.
\(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{unreachable}}\)¶
Trap.
\(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{block}}~\href{../syntax/instructions.html#syntax-blocktype}{\mathit{blocktype}}~\href{../syntax/instructions.html#syntax-instr}{\mathit{instr}}^\ast~\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{end}}\)¶
Assert: due to validation, \(\href{../exec/runtime.html#aux-fblocktype}{\mathrm{instrtype}}_{S;F}(\href{../syntax/instructions.html#syntax-blocktype}{\mathit{blocktype}})\) is defined.
Let \([t_1^m] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [t_2^n]\) be the instruction type \(\href{../exec/runtime.html#aux-fblocktype}{\mathrm{instrtype}}_{S;F}(\href{../syntax/instructions.html#syntax-blocktype}{\mathit{blocktype}})\).
Let \(L\) be the label whose arity is \(n\) and whose continuation is the end of the block.
Assert: due to validation, there are at least \(m\) values on the top of the stack.
Pop the values \(\href{../exec/runtime.html#syntax-val}{\mathit{val}}^m\) from the stack.
Enter the block \(\href{../exec/runtime.html#syntax-val}{\mathit{val}}^m~\href{../syntax/instructions.html#syntax-instr}{\mathit{instr}}^\ast\) with label \(L\).
\(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{loop}}~\href{../syntax/instructions.html#syntax-blocktype}{\mathit{blocktype}}~\href{../syntax/instructions.html#syntax-instr}{\mathit{instr}}^\ast~\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{end}}\)¶
Assert: due to validation, \(\href{../exec/runtime.html#aux-fblocktype}{\mathrm{instrtype}}_{S;F}(\href{../syntax/instructions.html#syntax-blocktype}{\mathit{blocktype}})\) is defined.
Let \([t_1^m] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [t_2^n]\) be the instruction type \(\href{../exec/runtime.html#aux-fblocktype}{\mathrm{instrtype}}_{S;F}(\href{../syntax/instructions.html#syntax-blocktype}{\mathit{blocktype}})\).
Let \(L\) be the label whose arity is \(m\) and whose continuation is the start of the loop.
Assert: due to validation, there are at least \(m\) values on the top of the stack.
Pop the values \(\href{../exec/runtime.html#syntax-val}{\mathit{val}}^m\) from the stack.
Enter the block \(\href{../exec/runtime.html#syntax-val}{\mathit{val}}^m~\href{../syntax/instructions.html#syntax-instr}{\mathit{instr}}^\ast\) with label \(L\).
\(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{if}}~\href{../syntax/instructions.html#syntax-blocktype}{\mathit{blocktype}}~\href{../syntax/instructions.html#syntax-instr}{\mathit{instr}}_1^\ast~\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{else}}~\href{../syntax/instructions.html#syntax-instr}{\mathit{instr}}_2^\ast~\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{end}}\)¶
Assert: due to validation, a value of value type \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}\) is on the top of the stack.
Pop the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~c\) from the stack.
If \(c\) is non-zero, then:
Execute the block instruction \(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{block}}~\href{../syntax/instructions.html#syntax-blocktype}{\mathit{blocktype}}~\href{../syntax/instructions.html#syntax-instr}{\mathit{instr}}_1^\ast~\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{end}}\).
Else:
Execute the block instruction \(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{block}}~\href{../syntax/instructions.html#syntax-blocktype}{\mathit{blocktype}}~\href{../syntax/instructions.html#syntax-instr}{\mathit{instr}}_2^\ast~\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{end}}\).
\(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{throw}}~x\)¶
Assert: due to validation, \(F.\href{../exec/runtime.html#syntax-frame}{\mathsf{module}}.\href{../exec/runtime.html#syntax-moduleinst}{\mathsf{tagaddrs}}[x]\) exists.
Let \(ta\) be the tag address \(F.\href{../exec/runtime.html#syntax-frame}{\mathsf{module}}.\href{../exec/runtime.html#syntax-moduleinst}{\mathsf{tagaddrs}}[x]\).
Assert: due to validation, \(S.\href{../exec/runtime.html#syntax-store}{\mathsf{tags}}[ta]\) exists.
Let \(\mathit{ti}\) be the tag instance \(S.\href{../exec/runtime.html#syntax-store}{\mathsf{tags}}[ta]\).
Let \([t^n] \href{../syntax/types.html#syntax-functype}{\rightarrow} [{t'}^\ast]\) be the tag type \(\mathit{ti}.\href{../exec/runtime.html#syntax-taginst}{\mathsf{type}}\).
Assert: due to validation, there are at least \(n\) values on the top of the stack.
Pop the \(n\) values \(\href{../exec/runtime.html#syntax-val}{\mathit{val}}^n\) from the stack.
Let \(\mathit{ea}\) be the exception address resulting from allocating an exception instance with tag address \(ta\) and initializer values \(\href{../exec/runtime.html#syntax-val}{\mathit{val}}^n\).
Let \(\mathit{exn}\) be \(S.\href{../exec/runtime.html#syntax-store}{\mathsf{exns}}[ea]\)
Push the value \(\href{../exec/runtime.html#syntax-ref}{\mathsf{ref{.}exn}}~\mathit{ea}\) to the stack.
Execute the instruction \(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{throw\_ref}}\).
\(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{throw\_ref}}\)¶
Assert: due to validation, a reference is on the top of the stack.
Pop the reference \(\href{../exec/runtime.html#syntax-ref}{\mathit{ref}}\) from the stack.
If \(\href{../exec/runtime.html#syntax-ref}{\mathit{ref}}\) is \(\href{../syntax/instructions.html#syntax-instr-ref}{\mathsf{ref.null}}~\mathit{ht}\), then:
Trap.
Assert: due to validation, \(\href{../exec/runtime.html#syntax-ref}{\mathit{ref}}\) is an exception reference.
Let \(\href{../exec/runtime.html#syntax-ref}{\mathsf{ref{.}exn}}~\mathit{ea}\) be \(\href{../exec/runtime.html#syntax-ref}{\mathit{ref}}\).
Assert: due to validation, \(S.\href{../exec/runtime.html#syntax-store}{\mathsf{exns}}[\mathit{ea}]\) exists.
Let \(\mathit{exn}\) be the exception instance \(S.\href{../exec/runtime.html#syntax-store}{\mathsf{exns}}[\mathit{ea}]\).
Let \(a\) be the tag address \(\mathit{exn}.\href{../exec/runtime.html#syntax-exninst}{\mathsf{tag}}\).
While the stack is not empty and the top of the stack is not an exception handler, do:
Pop the top element from the stack.
Assert: the stack is now either empty, or there is an exception handler on the top of the stack.
If the stack is empty, then:
Return the exception \((\href{../exec/runtime.html#syntax-ref}{\mathsf{ref{.}exn}}~a)\) as a result.
Assert: there is an exception handler on the top of the stack.
Pop the exception handler \(\href{../exec/runtime.html#syntax-handler}{\mathsf{handler}}_n\{\href{../syntax/instructions.html#syntax-catch}{\mathit{catch}}^\ast\}\) from the stack.
If \(\href{../syntax/instructions.html#syntax-catch}{\mathit{catch}}^\ast\) is empty, then:
Push the exception reference \(\href{../exec/runtime.html#syntax-ref}{\mathsf{ref{.}exn}}~\mathit{ea}\) back to the stack.
Execute the instruction \(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{throw\_ref}}\) again.
Else:
Let \(\href{../syntax/instructions.html#syntax-catch}{\mathit{catch}}_1\) be the first catch clause in \(\href{../syntax/instructions.html#syntax-catch}{\mathit{catch}}^\ast\) and \({\href{../syntax/instructions.html#syntax-catch}{\mathit{catch}}'}^\ast\) the remaining clauses.
If \(\href{../syntax/instructions.html#syntax-catch}{\mathit{catch}}_1\) is of the form \(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{catch}}~x~l\) and the tag address \(a\) equals \(F.\href{../exec/runtime.html#syntax-frame}{\mathsf{module}}.\href{../exec/runtime.html#syntax-moduleinst}{\mathsf{tagaddrs}}[x]\), then:
Push the values \(\mathit{exn}.\href{../exec/runtime.html#syntax-exninst}{\mathsf{fields}}\) to the stack.
Execute the instruction \(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{br}}~l\).
Else if \(\href{../syntax/instructions.html#syntax-catch}{\mathit{catch}}_1\) is of the form \(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{catch\_ref}}~x~l\) and the tag address \(a\) equals \(F.\href{../exec/runtime.html#syntax-frame}{\mathsf{module}}.\href{../exec/runtime.html#syntax-moduleinst}{\mathsf{tagaddrs}}[x]\), then:
Push the values \(\mathit{exn}.\href{../exec/runtime.html#syntax-exninst}{\mathsf{fields}}\) to the stack.
Push the exception reference \(\href{../exec/runtime.html#syntax-ref}{\mathsf{ref{.}exn}}~\mathit{ea}\) to the stack.
Execute the instruction \(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{br}}~l\).
Else if \(\href{../syntax/instructions.html#syntax-catch}{\mathit{catch}}_1\) is of the form \(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{catch\_all}}~l\), then:
Execute the instruction \(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{br}}~l\).
Else if \(\href{../syntax/instructions.html#syntax-catch}{\mathit{catch}}_1\) is of the form \(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{catch\_all\_ref}}~l\), then:
Push the exception reference \(\href{../exec/runtime.html#syntax-ref}{\mathsf{ref{.}exn}}~\mathit{ea}\) to the stack.
Execute the instruction \(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{br}}~l\).
Else:
Push the modified handler \(\href{../exec/runtime.html#syntax-handler}{\mathsf{handler}}_n\{{\href{../syntax/instructions.html#syntax-catch}{\mathit{catch}}'}^\ast\}\) back to the stack.
Push the exception reference \(\href{../exec/runtime.html#syntax-ref}{\mathsf{ref{.}exn}}~\mathit{ea}\) back to the stack.
Execute the instruction \(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{throw\_ref}}\) again.
\(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{try\_table}}~\href{../syntax/instructions.html#syntax-blocktype}{\mathit{blocktype}}~\href{../syntax/instructions.html#syntax-catch}{\mathit{catch}}^\ast~\href{../syntax/instructions.html#syntax-instr}{\mathit{instr}}^\ast~\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{end}}\)¶
Assert: due to validation, \(\href{../exec/runtime.html#aux-fblocktype}{\mathrm{instrtype}}_{S;F}(\href{../syntax/instructions.html#syntax-blocktype}{\mathit{blocktype}})\) is defined.
Let \([t_1^m] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [t_2^n]\) be the instruction type \(\href{../exec/runtime.html#aux-fblocktype}{\mathrm{instrtype}}_{S;F}(\href{../syntax/instructions.html#syntax-blocktype}{\mathit{blocktype}})\).
Assert: due to validation, there are at least \(m\) values on the top of the stack.
Pop the values \(\href{../exec/runtime.html#syntax-val}{\mathit{val}}^m\) from the stack.
Let \(L\) be the label whose arity is \(n\) and whose continuation is the end of the \(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{try\_table}}\) instruction.
Enter the block \(\href{../exec/runtime.html#syntax-val}{\mathit{val}}^m~\href{../syntax/instructions.html#syntax-instr}{\mathit{instr}}_1^\ast\) with label \(L\) and exception handler \(\href{../exec/runtime.html#syntax-handler}{\mathsf{handler}}_n\{\href{../syntax/instructions.html#syntax-catch}{\mathit{catch}}^\ast\}\).
\(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{br}}~l\)¶
Assert: due to validation, the stack contains at least \(l+1\) labels.
Let \(L\) be the \(l\)-th label appearing on the stack, starting from the top and counting from zero.
Let \(n\) be the arity of \(L\).
Assert: due to validation, there are at least \(n\) values on the top of the stack.
Pop the values \(\href{../exec/runtime.html#syntax-val}{\mathit{val}}^n\) from the stack.
Repeat \(l+1\) times:
While the top of the stack is a value or a handler, do:
Pop the value or handler from the stack.
Assert: due to validation, the top of the stack now is a label.
Pop the label from the stack.
Push the values \(\href{../exec/runtime.html#syntax-val}{\mathit{val}}^n\) to the stack.
Jump to the continuation of \(L\).
\(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{br\_if}}~l\)¶
Assert: due to validation, a value of value type \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}\) is on the top of the stack.
Pop the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~c\) from the stack.
If \(c\) is non-zero, then:
Execute the instruction \(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{br}}~l\).
Else:
Do nothing.
\(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{br\_table}}~l^\ast~l_N\)¶
Assert: due to validation, a value of value type \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}\) is on the top of the stack.
Pop the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~i\) from the stack.
If \(i\) is smaller than the length of \(l^\ast\), then:
Let \(l_i\) be the label \(l^\ast[i]\).
Execute the instruction \(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{br}}~l_i\).
Else:
Execute the instruction \(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{br}}~l_N\).
\(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{br\_on\_null}}~l\)¶
Assert: due to validation, a reference value is on the top of the stack.
Pop the value \(\href{../exec/runtime.html#syntax-ref}{\mathit{ref}}\) from the stack.
If \(\href{../exec/runtime.html#syntax-ref}{\mathit{ref}}\) is \(\href{../syntax/instructions.html#syntax-instr-ref}{\mathsf{ref.null}}~\mathit{ht}\), then:
Execute the instruction \((\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{br}}~l)\).
Else:
Push the value \(\href{../exec/runtime.html#syntax-ref}{\mathit{ref}}\) back to the stack.
\(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{br\_on\_non\_null}}~l\)¶
Assert: due to validation, a reference value is on the top of the stack.
Pop the value \(\href{../exec/runtime.html#syntax-ref}{\mathit{ref}}\) from the stack.
If \(\href{../exec/runtime.html#syntax-ref}{\mathit{ref}}\) is \(\href{../syntax/instructions.html#syntax-instr-ref}{\mathsf{ref.null}}~\mathit{ht}\), then:
Do nothing.
Else:
Push the value \(\href{../exec/runtime.html#syntax-ref}{\mathit{ref}}\) back to the stack.
Execute the instruction \((\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{br}}~l)\).
\(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{br\_on\_cast}}~l~\mathit{rt}_1~\mathit{rt}_2\)¶
Let \(\mathit{rt}'_2\) be the reference type \(\href{../exec/types.html#type-inst}{\mathrm{clos}}_{F.\href{../exec/runtime.html#syntax-frame}{\mathsf{module}}}(\mathit{rt}_2)\).
Assert: due to validation, \(\mathit{rt}'_2\) is closed.
Assert: due to validation, a reference value is on the top of the stack.
Pop the value \(\href{../exec/runtime.html#syntax-ref}{\mathit{ref}}\) from the stack.
Assert: due to validation, the reference value is valid with some reference type.
Let \(\mathit{rt}\) be the reference type of \(\href{../exec/runtime.html#syntax-ref}{\mathit{ref}}\).
Push the value \(\href{../exec/runtime.html#syntax-ref}{\mathit{ref}}\) back to the stack.
If the reference type \(\mathit{rt}\) matches \(\mathit{rt}'_2\), then:
Execute the instruction \((\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{br}}~l)\).
\(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{br\_on\_cast\_fail}}~l~\mathit{rt}_1~\mathit{rt}_2\)¶
Let \(\mathit{rt}'_2\) be the reference type \(\href{../exec/types.html#type-inst}{\mathrm{clos}}_{F.\href{../exec/runtime.html#syntax-frame}{\mathsf{module}}}(\mathit{rt}_2)\).
Assert: due to validation, \(\mathit{rt}'_2\) is closed.
Assert: due to validation, a reference value is on the top of the stack.
Pop the value \(\href{../exec/runtime.html#syntax-ref}{\mathit{ref}}\) from the stack.
Assert: due to validation, the reference value is valid with some reference type.
Let \(\mathit{rt}\) be the reference type of \(\href{../exec/runtime.html#syntax-ref}{\mathit{ref}}\).
Push the value \(\href{../exec/runtime.html#syntax-ref}{\mathit{ref}}\) back to the stack.
If the reference type \(\mathit{rt}\) does not match \(\mathit{rt}'_2\), then:
Execute the instruction \((\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{br}}~l)\).
\(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{return}}\)¶
Let \(n\) be the arity of \(F\).
Assert: due to validation, there are at least \(n\) values on the top of the stack.
Pop the results \(\href{../exec/runtime.html#syntax-val}{\mathit{val}}^n\) from the stack.
Assert: due to validation, the stack contains at least one frame.
While the top of the stack is not a frame, do:
Pop the top element from the stack.
Assert: the top of the stack is the frame \(F\).
Pop the frame from the stack.
Push \(\href{../exec/runtime.html#syntax-val}{\mathit{val}}^n\) to the stack.
Jump to the instruction after the original call that pushed the frame.
\(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{call}}~x\)¶
Assert: due to validation, \(F.\href{../exec/runtime.html#syntax-frame}{\mathsf{module}}.\href{../exec/runtime.html#syntax-moduleinst}{\mathsf{funcaddrs}}[x]\) exists.
Let \(a\) be the function address \(F.\href{../exec/runtime.html#syntax-frame}{\mathsf{module}}.\href{../exec/runtime.html#syntax-moduleinst}{\mathsf{funcaddrs}}[x]\).
Invoke the function instance at address \(a\).
\(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{call\_ref}}~x\)¶
Assert: due to validation, a null or function reference is on the top of the stack.
Pop the reference value \(r\) from the stack.
If \(r\) is \(\href{../syntax/instructions.html#syntax-instr-ref}{\mathsf{ref.null}}~\mathit{ht}\), then:
Trap.
Assert: due to validation, \(r\) is a function reference.
Let \(\href{../exec/runtime.html#syntax-ref}{\mathsf{ref{.}func}}~a\) be the reference \(r\).
Invoke the function instance at address \(a\).
\(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{call\_indirect}}~x~y\)¶
Assert: due to validation, \(F.\href{../exec/runtime.html#syntax-frame}{\mathsf{module}}.\href{../exec/runtime.html#syntax-moduleinst}{\mathsf{tableaddrs}}[x]\) exists.
Let \(\mathit{ta}\) be the table address \(F.\href{../exec/runtime.html#syntax-frame}{\mathsf{module}}.\href{../exec/runtime.html#syntax-moduleinst}{\mathsf{tableaddrs}}[x]\).
Assert: due to validation, \(S.\href{../exec/runtime.html#syntax-store}{\mathsf{tables}}[\mathit{ta}]\) exists.
Let \(\mathit{tab}\) be the table instance \(S.\href{../exec/runtime.html#syntax-store}{\mathsf{tables}}[\mathit{ta}]\).
Assert: due to validation, \(F.\href{../exec/runtime.html#syntax-frame}{\mathsf{module}}.\href{../exec/runtime.html#syntax-moduleinst}{\mathsf{types}}[y]\) is defined.
Let \(\mathit{dt}_{\mathrm{expect}}\) be the defined type \(F.\href{../exec/runtime.html#syntax-frame}{\mathsf{module}}.\href{../exec/runtime.html#syntax-moduleinst}{\mathsf{types}}[y]\).
Assert: due to validation, a value with value type \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}\) is on the top of the stack.
Pop the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~i\) from the stack.
If \(i\) is not smaller than the length of \(\mathit{tab}.\href{../exec/runtime.html#syntax-tableinst}{\mathsf{elem}}\), then:
Trap.
Let \(r\) be the reference \(\mathit{tab}.\href{../exec/runtime.html#syntax-tableinst}{\mathsf{elem}}[i]\).
If \(r\) is \(\href{../syntax/instructions.html#syntax-instr-ref}{\mathsf{ref.null}}~\mathit{ht}\), then:
Trap.
Assert: due to validation of table mutation, \(r\) is a function reference.
Let \(\href{../exec/runtime.html#syntax-ref}{\mathsf{ref{.}func}}~a\) be the function reference \(r\).
Assert: due to validation of table mutation, \(S.\href{../exec/runtime.html#syntax-store}{\mathsf{funcs}}[a]\) exists.
Let \(\mathit{f}\) be the function instance \(S.\href{../exec/runtime.html#syntax-store}{\mathsf{funcs}}[a]\).
Let \(\mathit{dt}_{\mathrm{actual}}\) be the defined type \(\mathit{f}.\href{../exec/runtime.html#syntax-funcinst}{\mathsf{type}}\).
If \(\mathit{dt}_{\mathrm{actual}}\) does not match \(\mathit{dt}_{\mathrm{expect}}\), then:
Trap.
Invoke the function instance at address \(a\).
\(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{return\_call}}~x\)¶
Assert: due to validation, \(F.\href{../exec/runtime.html#syntax-frame}{\mathsf{module}}.\href{../exec/runtime.html#syntax-moduleinst}{\mathsf{funcaddrs}}[x]\) exists.
Let \(a\) be the function address \(F.\href{../exec/runtime.html#syntax-frame}{\mathsf{module}}.\href{../exec/runtime.html#syntax-moduleinst}{\mathsf{funcaddrs}}[x]\).
Tail-invoke the function instance at address \(a\).
\(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{return\_call\_ref}}~x\)¶
Assert: due to validation, a function reference is on the top of the stack.
Pop the reference value \(r\) from the stack.
If \(r\) is \(\href{../syntax/instructions.html#syntax-instr-ref}{\mathsf{ref.null}}~\mathit{ht}\), then:
Trap.
Assert: due to validation, \(r\) is a function reference.
Let \(\href{../exec/runtime.html#syntax-ref}{\mathsf{ref{.}func}}~a\) be the reference \(r\).
Tail-invoke the function instance at address \(a\).
\(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{return\_call\_indirect}}~x~y\)¶
Assert: due to validation, \(F.\href{../exec/runtime.html#syntax-frame}{\mathsf{module}}.\href{../exec/runtime.html#syntax-moduleinst}{\mathsf{tableaddrs}}[x]\) exists.
Let \(\mathit{ta}\) be the table address \(F.\href{../exec/runtime.html#syntax-frame}{\mathsf{module}}.\href{../exec/runtime.html#syntax-moduleinst}{\mathsf{tableaddrs}}[x]\).
Assert: due to validation, \(S.\href{../exec/runtime.html#syntax-store}{\mathsf{tables}}[\mathit{ta}]\) exists.
Let \(\mathit{tab}\) be the table instance \(S.\href{../exec/runtime.html#syntax-store}{\mathsf{tables}}[\mathit{ta}]\).
Assert: due to validation, \(F.\href{../exec/runtime.html#syntax-frame}{\mathsf{module}}.\href{../exec/runtime.html#syntax-moduleinst}{\mathsf{types}}[y]\) exists.
Let \(\mathit{dt}_{\mathrm{expect}}\) be the defined type \(F.\href{../exec/runtime.html#syntax-frame}{\mathsf{module}}.\href{../exec/runtime.html#syntax-moduleinst}{\mathsf{types}}[y]\).
Assert: due to validation, a value with value type \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}\) is on the top of the stack.
Pop the value \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~i\) from the stack.
If \(i\) is not smaller than the length of \(\mathit{tab}.\href{../exec/runtime.html#syntax-tableinst}{\mathsf{elem}}\), then:
Trap.
If \(\mathit{tab}.\href{../exec/runtime.html#syntax-tableinst}{\mathsf{elem}}[i]\) is uninitialized, then:
Trap.
Let \(a\) be the function address \(\mathit{tab}.\href{../exec/runtime.html#syntax-tableinst}{\mathsf{elem}}[i]\).
Assert: due to validation, \(S.\href{../exec/runtime.html#syntax-store}{\mathsf{funcs}}[a]\) exists.
Let \(\mathit{f}\) be the function instance \(S.\href{../exec/runtime.html#syntax-store}{\mathsf{funcs}}[a]\).
Let \(\mathit{dt}_{\mathrm{actual}}\) be the defined type \(\mathit{f}.\href{../exec/runtime.html#syntax-funcinst}{\mathsf{type}}\).
If \(\mathit{dt}_{\mathrm{actual}}\) does not match \(\mathit{dt}_{\mathrm{expect}}\), then:
Trap.
Tail-invoke the function instance at address \(a\).
Blocks¶
The following auxiliary rules define the semantics of executing an instruction sequence that forms a block.
Entering \(\href{../syntax/instructions.html#syntax-instr}{\mathit{instr}}^\ast\) with label \(L\)¶
Push \(L\) to the stack.
Jump to the start of the instruction sequence \(\href{../syntax/instructions.html#syntax-instr}{\mathit{instr}}^\ast\).
Note
No formal reduction rule is needed for entering an instruction sequence, because the label \(L\) is embedded in the administrative instruction that structured control instructions reduce to directly.
Exiting \(\href{../syntax/instructions.html#syntax-instr}{\mathit{instr}}^\ast\) with label \(L\)¶
When the end of a block is reached without a jump, exception, or trap aborting it, then the following steps are performed.
Pop all values \(\href{../exec/runtime.html#syntax-val}{\mathit{val}}^\ast\) from the top of the stack.
Assert: due to validation, the label \(L\) is now on the top of the stack.
Pop the label from the stack.
Push \(\href{../exec/runtime.html#syntax-val}{\mathit{val}}^\ast\) back to the stack.
Jump to the position after the \(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{end}}\) of the structured control instruction associated with the label \(L\).
Note
This semantics also applies to the instruction sequence contained in a \(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{loop}}\) instruction. Therefore, execution of a loop falls off the end, unless a backwards branch is performed explicitly.
Exception Handling¶
The following auxiliary rules define the semantics of entering and exiting \(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{try\_table}}\) blocks.
Entering \(\href{../syntax/instructions.html#syntax-instr}{\mathit{instr}}^\ast\) with label \(L\) and exception handler \(H\)¶
Push \(L\) to the stack.
Push \(H\) onto the stack.
Jump to the start of the instruction sequence \(\href{../syntax/instructions.html#syntax-instr}{\mathit{instr}}^\ast\).
Note
No formal reduction rule is needed for entering an exception handler because it is an administrative instruction that the \(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{try\_table}}\) instruction reduces to directly.
Exiting an exception handler¶
When the end of a \(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{try\_table}}\) block is reached without a jump, exception, or trap, then the following steps are performed.
Let \(m\) be the number of values on the top of the stack.
Pop the values \(\href{../exec/runtime.html#syntax-val}{\mathit{val}}^m\) from the stack.
Assert: due to validation, a handler and a label are now on the top of the stack.
Pop the label from the stack.
Pop the handler \(H\) from the stack.
Push \(\href{../exec/runtime.html#syntax-val}{\mathit{val}}^m\) back to the stack.
Jump to the position after the \(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{end}}\) of the administrative instruction associated with the handler \(H\).
Function Calls¶
The following auxiliary rules define the semantics of invoking a function instance through one of the call instructions and returning from it.
Invocation of function address \(a\)¶
Assert: due to validation, \(S.\href{../exec/runtime.html#syntax-store}{\mathsf{funcs}}[a]\) exists.
Let \(f\) be the function instance, \(S.\href{../exec/runtime.html#syntax-store}{\mathsf{funcs}}[a]\).
Let \(\href{../syntax/types.html#syntax-comptype}{\mathsf{func}}~[t_1^n] \href{../syntax/types.html#syntax-functype}{\rightarrow} [t_2^m]\) be the composite type \(\href{../valid/conventions.html#aux-expand-deftype}{\mathrm{expand}}(\mathit{f}.\href{../exec/runtime.html#syntax-funcinst}{\mathsf{type}})\).
Let \(\href{../syntax/modules.html#syntax-local}{\mathit{local}}^\ast\) be the list of locals \(f.\href{../exec/runtime.html#syntax-funcinst}{\mathsf{code}}.\href{../syntax/modules.html#syntax-func}{\mathsf{locals}}\).
Let \(\href{../syntax/instructions.html#syntax-instr}{\mathit{instr}}^\ast~\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{end}}\) be the expression \(f.\href{../exec/runtime.html#syntax-funcinst}{\mathsf{code}}.\href{../syntax/modules.html#syntax-func}{\mathsf{body}}\).
Assert: due to validation, \(n\) values are on the top of the stack.
Pop the values \(\href{../exec/runtime.html#syntax-val}{\mathit{val}}^n\) from the stack.
Let \(F\) be the frame \(\{ \href{../exec/runtime.html#syntax-frame}{\mathsf{module}}~f.\href{../exec/runtime.html#syntax-funcinst}{\mathsf{module}}, \href{../exec/runtime.html#syntax-frame}{\mathsf{locals}}~\href{../exec/runtime.html#syntax-val}{\mathit{val}}^n~(\href{../exec/runtime.html#default-val}{\mathrm{default}}_t)^\ast \}\).
Push the activation of \(F\) with arity \(m\) to the stack.
Let \(L\) be the label whose arity is \(m\) and whose continuation is the end of the function.
Enter the instruction sequence \(\href{../syntax/instructions.html#syntax-instr}{\mathit{instr}}^\ast\) with label \(L\).
Note
For non-defaultable types, the respective local is left uninitialized by these rules.
Tail-invocation of function address \(a\)¶
Assert: due to validation, \(S.\href{../exec/runtime.html#syntax-store}{\mathsf{funcs}}[a]\) exists.
Let \(\href{../syntax/types.html#syntax-comptype}{\mathsf{func}}~[t_1^n] \href{../syntax/types.html#syntax-functype}{\rightarrow} [t_2^m]\) be the composite type \(\href{../valid/conventions.html#aux-expand-deftype}{\mathrm{expand}}(S.\href{../exec/runtime.html#syntax-store}{\mathsf{funcs}}[a].\href{../exec/runtime.html#syntax-funcinst}{\mathsf{type}})\).
Assert: due to validation, there are at least \(n\) values on the top of the stack.
Pop the results \(\href{../exec/runtime.html#syntax-val}{\mathit{val}}^n\) from the stack.
Assert: due to validation, the stack contains at least one frame.
While the top of the stack is not a frame, do:
Pop the top element from the stack.
Assert: the top of the stack is a frame.
Pop the frame from the stack.
Push \(\href{../exec/runtime.html#syntax-val}{\mathit{val}}^n\) to the stack.
Invoke the function instance at address \(a\).
Returning from a function¶
When the end of a function is reached without a jump (including through \(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{return}}\)), or an exception or trap aborting it, then the following steps are performed.
Let \(n\) be the arity of the activation of \(F\).
Assert: due to validation, there are \(n\) values on the top of the stack.
Pop the results \(\href{../exec/runtime.html#syntax-val}{\mathit{val}}^n\) from the stack.
Assert: due to validation, the frame \(F\) is now on the top of the stack.
Pop the frame from the stack.
Push \(\href{../exec/runtime.html#syntax-val}{\mathit{val}}^n\) back to the stack.
Jump to the instruction after the original call.
Host Functions¶
Invoking a host function has non-deterministic behavior. It may either terminate with a trap, an exception, or return regularly. However, in the latter case, it must consume and produce the right number and types of WebAssembly values on the stack, according to its function type.
A host function may also modify the store. However, all store modifications must result in an extension of the original store, i.e., they must only modify mutable contents and must not have instances removed. Furthermore, the resulting store must be valid, i.e., all data and code in it is well-typed.
Here, \(\mathit{hf}(S; \href{../exec/runtime.html#syntax-val}{\mathit{val}}^n)\) denotes the implementation-defined execution of host function \(\mathit{hf}\) in current store \(S\) with arguments \(\href{../exec/runtime.html#syntax-val}{\mathit{val}}^n\). It yields a set of possible outcomes, where each element is either a pair of a modified store \(S'\) and a result or the special value \(\bot\) indicating divergence. A host function is non-deterministic if there is at least one argument for which the set of outcomes is not singular.
For a WebAssembly implementation to be sound in the presence of host functions, every host function instance must be valid, which means that it adheres to suitable pre- and post-conditions: under a valid store \(S\), and given arguments \(\href{../exec/runtime.html#syntax-val}{\mathit{val}}^n\) matching the ascribed parameter types \(t_1^n\), executing the host function must yield a non-empty set of possible outcomes each of which is either divergence or consists of a valid store \(S'\) that is an extension of \(S\) and a result matching the ascribed return types \(t_2^m\). All these notions are made precise in the Appendix.
Expressions¶
An expression is evaluated relative to a current frame pointing to its containing module instance.
Jump to the start of the instruction sequence \(\href{../syntax/instructions.html#syntax-instr}{\mathit{instr}}^\ast\) of the expression.
Execute the instruction sequence.
Assert: due to validation, the top of the stack contains a value.
Pop the value \(\href{../exec/runtime.html#syntax-val}{\mathit{val}}\) from the stack.
The value \(\href{../exec/runtime.html#syntax-val}{\mathit{val}}\) is the result of the evaluation.
Note
Evaluation iterates this reduction rule until reaching a value. Expressions constituting function bodies are executed during function invocation.