Values

WebAssembly programs operate on primitive numericvalues.Moreover, in the definition of programs, immutable sequences of values occur to represent more complex data, such as text strings or other vectors.

Bytes

The simplest form of value are raw uninterpretedbytes.In the abstract syntax they are represented as hexadecimal literals.

\[\begin{split}\begin{array}[t]{@{}l@{}rrl@{}l@{}}& {\href{../syntax/values.html#syntax-byte}{\mathit{byte}}} & ::= & \mathtt{0x00} ~~|~~ \ldots ~~|~~ \mathtt{0xFF} \\\end{array}\end{split}\]

Conventions

  • The meta variable\(b\) ranges over bytes.

  • Bytes are sometimes interpreted as natural numbers\(n < 256\).

Integers

Different classes ofintegers with different value ranges are distinguished by theirbit width\(N\) and by whether they areunsigned orsigned.

\[\begin{split}\begin{array}[t]{@{}l@{}rrl@{}l@{}}& {{\href{../syntax/values.html#syntax-int}{\mathit{u}\kern-0.1em}}}{N} & ::= & 0 ~~|~~ \ldots ~~|~~ {2^{N}} - 1 \\& {{\href{../syntax/values.html#syntax-int}{\mathit{s}\kern-0.1em}}}{N} & ::= & {-{2^{N - 1}}} ~~|~~ \ldots ~~|~~ {-1} ~~|~~ 0 ~~|~~ {+1} ~~|~~ \ldots ~~|~~ {+{2^{N - 1}}} - 1 \\& {{\href{../syntax/values.html#syntax-int}{\mathit{i}\kern-0.1em}}}{N} & ::= & {{\href{../syntax/values.html#syntax-int}{\mathit{u}\kern-0.1em}}}{N} \\\end{array}\end{split}\]

The class\({\href{../syntax/values.html#syntax-int}{\mathit{i}\kern-0.1em}}\) definesuninterpreted integers, whose signedness interpretation can vary depending on context.In the abstract syntax, they are represented as unsigned values.However, some operationsconvert them to signed based on a two’s complement interpretation.

Note

The main integer types occurring in this specification are\({\href{../syntax/values.html#syntax-int}{\mathit{u\scriptstyle\kern-0.1em8}}}\),\({\href{../syntax/values.html#syntax-int}{\mathit{u\scriptstyle\kern-0.1em32}}}\),\({\href{../syntax/values.html#syntax-int}{\mathit{u\scriptstyle\kern-0.1em64}}}\), and\({\href{../syntax/values.html#syntax-int}{\mathit{u\scriptstyle\kern-0.1em128}}}\).However, other sizes occur as auxiliary constructions, e.g., in the definition offloating-point numbers.

Conventions

  • The meta variables\(m\),\(n\),\(i\),\(j\) range over integers.

  • Numbers may be denoted by simple arithmetics, as in the grammar above.In order to distinguish arithmetics like\({2^{N}}\) from sequences like\({(1)^{N}}\), the latter is distinguished with parentheses.

Floating-Point

Floating-point data represents 32 or 64 bit values that correspond to the respective binary formats of theIEEE 754 standard (Section 3.3).

Every value has asign and amagnitude.Magnitudes can either be expressed asnormal numbers of the form\(m_0~{.}~m_1~m_2~\ldots~m_{\mathsf{m}} \cdot {2^{e}}\), where\(e\) is the exponent and\(m\) is thesignificand whose most significant bit\(m_0\) is\(1\),or as asubnormal number where the exponent is fixed to the smallest possible value and\(m_0\) is\(0\); among the subnormals are positive and negative zero values.Since the significands are binary values, normals are represented in the form\((1 + m \cdot {2^{{-M}}}) \cdot {2^{e}}\) in the abstract syntax, where\(M\) is the bit width of\(m\); similarly for subnormals.

Possible magnitudes also include the special values\(\infty\) (infinity) and\(\mathsf{nan}\) (NaN, not a number).NaN values have apayload that describes the mantissa bits in the underlyingbinary representation.No distinction is made between signalling and quiet NaNs.

\[\begin{split}\begin{array}[t]{@{}l@{}rrl@{}l@{}}& {{\href{../syntax/values.html#syntax-float}{\mathit{f}\kern-0.15em}}}{N} & ::= & {+{{\href{../syntax/values.html#syntax-float}{\mathit{fmag}\scriptstyle\kern-0.1emN}}}} ~~|~~ {-{{\href{../syntax/values.html#syntax-float}{\mathit{fmag}\scriptstyle\kern-0.1emN}}}} \\& {{\href{../syntax/values.html#syntax-float}{\mathit{fmag}\scriptstyle\kern-0.1emN}}} & ::= & (1 + m \cdot {2^{{-M}}}) \cdot {2^{e}} & \quad \mbox{if}~ m < {2^{M}} \land 2 - {2^{E - 1}} \leq e \leq {2^{E - 1}} - 1 \\& & | & (0 + m \cdot {2^{{-M}}}) \cdot {2^{e}} & \quad \mbox{if}~ m < {2^{M}} \land 2 - {2^{E - 1}} = e \\& & | & \infty \\& & | & {\href{../syntax/values.html#syntax-float}{\mathsf{nan}}}{(m)} & \quad \mbox{if}~ 1 \leq m < {2^{M}} \\\end{array}\end{split}\]

where\(\begin{array}[t]{@{}l@{~}c@{~}l@{}l@{}} M & = & {\href{../syntax/values.html#aux-signif}{\mathrm{signif}}}(N) \\ \end{array}\) and\(\begin{array}[t]{@{}l@{~}c@{~}l@{}l@{}} E & = & {\href{../syntax/values.html#aux-expon}{\mathrm{expon}}}(N) \\ \end{array}\) with

\[\begin{split}\begin{array}[t]{@{}lcl@{}l@{}}{\href{../syntax/values.html#aux-signif}{\mathrm{signif}}}(32) & = & 23 \\{\href{../syntax/values.html#aux-signif}{\mathrm{signif}}}(64) & = & 52 \\[0.8ex]{\href{../syntax/values.html#aux-expon}{\mathrm{expon}}}(32) & = & 8 \\{\href{../syntax/values.html#aux-expon}{\mathrm{expon}}}(64) & = & 11 \\\end{array}\end{split}\]

Acanonical NaN is a floating-point value\({\pm{\mathsf{nan}}{({{\href{../syntax/values.html#aux-canon}{\mathrm{canon}}}}_{N})}}\) where\({{\href{../syntax/values.html#aux-canon}{\mathrm{canon}}}}_{N}\) is a payload whose most significant bit is\(1\) while all others are\(0\):

\[\begin{split}\begin{array}[t]{@{}lcl@{}l@{}}{{\href{../syntax/values.html#aux-canon}{\mathrm{canon}}}}_{N} & = & {2^{{\href{../syntax/values.html#aux-signif}{\mathrm{signif}}}(N) - 1}} \\\end{array}\end{split}\]

Anarithmetic NaN is a floating-point value\({\pm{\mathsf{nan}}{(m)}}\) with\(m \geq {{\href{../syntax/values.html#aux-canon}{\mathrm{canon}}}}_{N}\), such that the most significant bit is\(1\) while all others are arbitrary.

Note

In the abstract syntax, subnormals are distinguished by the leading\(0\) of the significand. The exponent of subnormals has the same value as the smallest possible exponent of a normal number. Only in thebinary representation the exponent of a subnormal is encoded differently than the exponent of any normal number.

The notion of canonical NaN defined here is unrelated to the notion of canonical NaN that theIEEE 754 standard (Section 3.5.2) defines for decimal interchange formats.

Conventions

  • The meta variable\(z\) ranges over floating-point values where clear from context.

  • Where clear from context, shorthands like\({+1}\) denote floating point values like\({+(1 + 0 \cdot {2^{{-M}}}) \cdot {2^{0}}}\).

Vectors

Numeric vectors are 128-bit values that are processed by vector instructions (also known asSIMD instructions, single instruction multiple data).They are represented in the abstract syntax using\({\href{../syntax/values.html#syntax-int}{\mathit{u\scriptstyle\kern-0.1em128}}}\). The interpretation of lane types (integer orfloating-point numbers) and lane sizes are determined by the specific instruction operating on them.

Names

Names are sequences ofcharacters, which arescalar values as defined byUnicode (Section 2.4).

\[\begin{split}\begin{array}[t]{@{}l@{}rrl@{}l@{}}& {\href{../syntax/values.html#syntax-name}{\mathit{name}}} & ::= & {{\href{../syntax/values.html#syntax-name}{\mathit{char}}}^\ast} & \quad \mbox{if}~ {|{\href{../binary/values.html#binary-utf8}{\mathrm{utf\scriptstyle8}}}({{\href{../syntax/values.html#syntax-name}{\mathit{char}}}^\ast})|} < {2^{32}} \\& {\href{../syntax/values.html#syntax-name}{\mathit{char}}} & ::= & \mathrm{U{+}00} ~~|~~ \ldots ~~|~~ \mathrm{U{+}D7FF} ~~|~~ \mathrm{U{+}E000} ~~|~~ \ldots ~~|~~ \mathrm{U{+}10FFFF} \\\end{array}\end{split}\]

Due to the limitations of thebinary format,the length of a name is bounded by the length of itsUTF-8 encoding.

Convention

  • Characters (Unicode scalar values) are sometimes used interchangeably with natural numbers\(n < 1114112\).