-
-

WebAssembly Specification

-
-
Release 1.1
-
-
-
Editor: Andreas Rossberg
-
-
-
Latest Draft: |pagelink|
-
Issue Tracker: |issuelink|
-
-
- -
- -

1. Introduction

-
- -
-

1.1. Introduction

-

WebAssembly (abbreviated Wasm [1]) is a safe, portable, low-level code format designed for efficient execution and compact representation. +

+ +
+ +

1. Introduction

+
+ +
+

1.1. Introduction

+

WebAssembly (abbreviated Wasm [1]) is a safe, portable, low-level code format designed for efficient execution and compact representation. Its main goal is to enable high performance applications on the Web, but it does not make any Web-specific assumptions or provide Web-specific features, so it can be employed in other environments as well.

-

WebAssembly is an open standard developed by a W3C Community Group.

-

This document describes version 1.1 of the core WebAssembly standard. +

WebAssembly is an open standard developed by a W3C Community Group.

+

This document describes version 2.0 (Draft 2024-04-09) of the core WebAssembly standard. It is intended that it will be superseded by new incremental releases with additional features in the future.

-
- -

1.1.1. Design Goals

-

The design goals of WebAssembly are the following:

-
    -
  • -

    Fast, safe, and portable semantics:

    -
      -
    • -

      Fast: executes with near native code performance, taking advantage of capabilities common to all contemporary hardware.

      -
    • -

      Safe: code is validated and executes in a memory-safe [2], sandboxed environment preventing data corruption or security breaches.

      -
    • -

      Well-defined: fully and precisely defines valid programs and their behavior in a way that is easy to reason about informally and formally.

      -
    • -

      Hardware-independent: can be compiled on all modern architectures, desktop or mobile devices and embedded systems alike.

      -
    • -

      Language-independent: does not privilege any particular language, programming model, or object model.

      -
    • -

      Platform-independent: can be embedded in browsers, run as a stand-alone VM, or integrated in other environments.

      -
    • -

      Open: programs can interoperate with their environment in a simple and universal manner.

      -
    -
  • -

    Efficient and portable representation:

    -
      -
    • -

      Compact: has a binary format that is fast to transmit by being smaller than typical text or native code formats.

      -
    • -

      Modular: programs can be split up in smaller parts that can be transmitted, cached, and consumed separately.

      -
    • -

      Efficient: can be decoded, validated, and compiled in a fast single pass, equally with either just-in-time (JIT) or ahead-of-time (AOT) compilation.

      -
    • -

      Streamable: allows decoding, validation, and compilation to begin as soon as possible, before all data has been seen.

      -
    • -

      Parallelizable: allows decoding, validation, and compilation to be split into many independent parallel tasks.

      -
    • -

      Portable: makes no architectural assumptions that are not broadly supported across modern hardware.

      -
    -
-

WebAssembly code is also intended to be easy to inspect and debug, especially in environments like web browsers, but such features are beyond the scope of this specification.

- -
-
- -

1.1.2. Scope

-

At its core, WebAssembly is a virtual instruction set architecture (virtual ISA). +

+ +

1.1.1. Design Goals

+

The design goals of WebAssembly are the following:

+
    +
  • +

    Fast, safe, and portable semantics:

    +
      +
    • +

      Fast: executes with near native code performance, taking advantage of capabilities common to all contemporary hardware.

      +
    • +

      Safe: code is validated and executes in a memory-safe [2], sandboxed environment preventing data corruption or security breaches.

      +
    • +

      Well-defined: fully and precisely defines valid programs and their behavior in a way that is easy to reason about informally and formally.

      +
    • +

      Hardware-independent: can be compiled on all modern architectures, desktop or mobile devices and embedded systems alike.

      +
    • +

      Language-independent: does not privilege any particular language, programming model, or object model.

      +
    • +

      Platform-independent: can be embedded in browsers, run as a stand-alone VM, or integrated in other environments.

      +
    • +

      Open: programs can interoperate with their environment in a simple and universal manner.

      +
    +
  • +

    Efficient and portable representation:

    +
      +
    • +

      Compact: has a binary format that is fast to transmit by being smaller than typical text or native code formats.

      +
    • +

      Modular: programs can be split up in smaller parts that can be transmitted, cached, and consumed separately.

      +
    • +

      Efficient: can be decoded, validated, and compiled in a fast single pass, equally with either just-in-time (JIT) or ahead-of-time (AOT) compilation.

      +
    • +

      Streamable: allows decoding, validation, and compilation to begin as soon as possible, before all data has been seen.

      +
    • +

      Parallelizable: allows decoding, validation, and compilation to be split into many independent parallel tasks.

      +
    • +

      Portable: makes no architectural assumptions that are not broadly supported across modern hardware.

      +
    +
+

WebAssembly code is also intended to be easy to inspect and debug, especially in environments like web browsers, but such features are beyond the scope of this specification.

+ +
+
+ +

1.1.2. Scope

+

At its core, WebAssembly is a virtual instruction set architecture (virtual ISA). As such, it has many use cases and can be embedded in many different environments. To encompass their variety and enable maximum reuse, the WebAssembly specification is split and layered into several documents.

-

This document is concerned with the core ISA layer of WebAssembly. +

This document is concerned with the core ISA layer of WebAssembly. It defines the instruction set, binary encoding, validation, and execution semantics, as well as a textual representation. It does not, however, define how WebAssembly programs can interact with a specific environment they execute in, nor how they are invoked from such an environment.

-

Instead, this specification is complemented by additional documents defining interfaces to specific embedding environments such as the Web. +

Instead, this specification is complemented by additional documents defining interfaces to specific embedding environments such as the Web. These will each define a WebAssembly application programming interface (API) suitable for a given environment.

-
-
- -

1.1.3. Security Considerations

-

WebAssembly provides no ambient access to the computing environment in which code is executed. +

+
+ +

1.1.3. Security Considerations

+

WebAssembly provides no ambient access to the computing environment in which code is executed. Any interaction with the environment, such as I/O, access to resources, or operating system calls, can only be performed by invoking functions provided by the embedder and imported into a WebAssembly module. An embedder can establish security policies suitable for a respective environment by controlling or limiting which functional capabilities it makes available for import. Such considerations are an embedder’s responsibility and the subject of API definitions for a specific environment.

-

Because WebAssembly is designed to be translated into machine code running directly on the host’s hardware, it is potentially vulnerable to side channel attacks on the hardware level. +

Because WebAssembly is designed to be translated into machine code running directly on the host’s hardware, it is potentially vulnerable to side channel attacks on the hardware level. In environments where this is a concern, an embedder may have to put suitable mitigations into place to isolate WebAssembly computations.

-
-
- -

1.1.4. Dependencies

-

WebAssembly depends on two existing standards:

- -

However, to make this specification self-contained, relevant aspects of the aforementioned standards are defined and formalized as part of this specification, +

+
+ +

1.1.4. Dependencies

+

WebAssembly depends on two existing standards:

+ +

However, to make this specification self-contained, relevant aspects of the aforementioned standards are defined and formalized as part of this specification, such as the binary representation and rounding of floating-point values, and the value range and UTF-8 encoding of Unicode characters.

-
-

Note

-

The aforementioned standards are the authoritative source of all respective definitions. +

+

Note

+

The aforementioned standards are the authoritative source of all respective definitions. Formalizations given in this specification are intended to match these definitions. Any discrepancy in the syntax or semantics described is to be considered an error.

-
-
-
- -
-

1.2. Overview

-
- -

1.2.1. Concepts

-

WebAssembly encodes a low-level, assembly-like programming language. +

+
+
+ +
+

1.2. Overview

+
+ +

1.2.1. Concepts

+

WebAssembly encodes a low-level, assembly-like programming language. This language is structured around the following concepts.

-
-
Values -
-

WebAssembly provides only four basic value types. +

+
Values +
+

WebAssembly provides only four basic number types. These are integers and [IEEE-754-2019] numbers, each in 32 and 64 bit width. 32 bit integers also serve as Booleans and as memory addresses. @@ -1026,8059 +1008,9535 @@

-
Instructions -
-

The computational model of WebAssembly is based on a stack machine. +

In addition to these basic number types, there is a single 128 bit wide +vector type representing different types of packed data. +The supported representations are 4 32-bit, or 2 64-bit [IEEE-754-2019] numbers, or different widths of packed integer values, +specifically 2 64-bit integers, 4 32-bit integers, 8 +16-bit integers, or 16 8-bit integers.

+

Finally, values can consist of opaque references that represent pointers towards different sorts of entities. +Unlike with other types, their size or representation is not observable.

+

+
+
Instructions +
+

The computational model of WebAssembly is based on a stack machine. Code consists of sequences of instructions that are executed in order. -Instructions manipulate values on an implicit operand stack [1] and fall into two main categories. Simple instructions perform basic operations on data. +Instructions manipulate values on an implicit operand stack [1] and fall into two main categories. Simple instructions perform basic operations on data. They pop arguments from the operand stack and push results back to it. Control instructions alter control flow. Control flow is structured, meaning it is expressed with well-nested constructs such as blocks, loops, and conditionals. Branches can only target such constructs.

-
-
-
Traps -
-

Under some conditions, certain instructions may produce a trap, +

+
+
Traps +
+

Under some conditions, certain instructions may produce a trap, which immediately aborts execution. Traps cannot be handled by WebAssembly code, but are reported to the outside environment, where they typically can be caught.

-
-
-
Functions -
-

Code is organized into separate functions. +

+
+
Functions +
+

Code is organized into separate functions. Each function takes a sequence of values as parameters -and returns a sequence of values as results. [2] Functions can call each other, including recursively, +and returns a sequence of values as results. +Functions can call each other, including recursively, resulting in an implicit call stack that cannot be accessed directly. Functions may also declare mutable local variables that are usable as virtual registers.

-
-
-
Tables -
-

A table is an array of opaque values of a particular element type. +

+
+
Tables +
+

A table is an array of opaque values of a particular element type. It allows programs to select such values indirectly through a dynamic index operand. -Currently, the only available element type is an untyped function reference. +Currently, the only available element type is an untyped function reference or a reference to an external host value. Thereby, a program can call functions indirectly through a dynamic index into a table. For example, this allows emulating function pointers by way of table indices.

-
-
-
Linear Memory -
-

A linear memory is a contiguous, mutable array of raw bytes. +

+
+
Linear Memory +
+

A linear memory is a contiguous, mutable array of raw bytes. Such a memory is created with an initial size but can be grown dynamically. A program can load and store values from/to a linear memory at any byte address (including unaligned). Integer loads and stores can specify a storage size which is smaller than the size of the respective value type. A trap occurs if an access is not within the bounds of the current memory size.

-
-
-
Modules -
-

A WebAssembly binary takes the form of a module that contains definitions for functions, tables, and linear memories, +

+
+
Modules +
+

A WebAssembly binary takes the form of a module that contains definitions for functions, tables, and linear memories, as well as mutable or immutable global variables. Definitions can also be imported, specifying a module/name pair and a suitable type. Each definition can optionally be exported under one or more names. In addition to definitions, modules can define initialization data for their memories or tables that takes the form of segments copied to given offsets. They can also define a start function that is automatically executed.

-
-
-
Embedder -
-

A WebAssembly implementation will typically be embedded into a host environment. +

+
+
Embedder +
+

A WebAssembly implementation will typically be embedded into a host environment. This environment defines how loading of modules is initiated, how imports are provided (including host-side definitions), and how exports can be accessed. However, the details of any particular embedding are beyond the scope of this specification, and will instead be provided by complementary, environment-specific API definitions.

-
- -
-
- -

1.2.2. Semantic Phases

-

Conceptually, the semantics of WebAssembly is divided into three phases. + +

+
+
+ +

1.2.2. Semantic Phases

+

Conceptually, the semantics of WebAssembly is divided into three phases. For each part of the language, the specification specifies each of them.

-
-
Decoding -
-

WebAssembly modules are distributed in a binary format. Decoding processes that format and converts it into an internal representation of a module. +

+
Decoding +
+

WebAssembly modules are distributed in a binary format. Decoding processes that format and converts it into an internal representation of a module. In this specification, this representation is modelled by abstract syntax, but a real implementation could compile directly to machine code instead.

-
-
-
Validation -
-

A decoded module has to be valid. +

+
+
Validation +
+

A decoded module has to be valid. Validation checks a number of well-formedness conditions to guarantee that the module is meaningful and safe. In particular, it performs type checking of functions and the instruction sequences in their bodies, ensuring for example that the operand stack is used consistently.

-
- -
-
Execution -
-

Finally, a valid module can be executed. +

+ +
+
Execution +
+

Finally, a valid module can be executed. Execution can be further divided into two phases:

-

Instantiation. +

Instantiation. A module instance is the dynamic representation of a module, complete with its own state and execution stack. Instantiation executes the module body itself, given definitions for all its imports. It initializes globals, memories and tables and invokes the module’s start function if defined. It returns the instances of the module’s exports.

-

Invocation. +

Invocation. Once instantiated, further WebAssembly computations can be initiated by invoking an exported function on a module instance. Given the required arguments, that executes the respective function and returns its results.

-

Instantiation and invocation are operations within the embedding environment.

-
-
-
-
-
- -
- -

2. Structure

-
- -
- -

2.1. Conventions

-

WebAssembly is a programming language that has multiple concrete representations +

Instantiation and invocation are operations within the embedding environment.

+ +
+
+
+
+ +
+ +

2. Structure

+
+ +
+ +

2.1. Conventions

+

WebAssembly is a programming language that has multiple concrete representations (its binary format and the text format). Both map to a common structure. For conciseness, this structure is described in the form of an abstract syntax. All parts of this specification are defined in terms of this abstract syntax.

-
- -

2.1.1. Grammar Notation

-

The following conventions are adopted in defining grammar rules for abstract syntax.

-
    -
  • -

    Terminal symbols (atoms) are written in sans-serif font: .

    -
  • -

    Nonterminal symbols are written in italic font: .

    -
  • -

    is a sequence of iterations of .

    -
  • -

    is a possibly empty sequence of iterations of . -(This is a shorthand for used where is not relevant.)

    -
  • -

    is a non-empty sequence of iterations of . -(This is a shorthand for where .)

    -
  • -

    is an optional occurrence of . -(This is a shorthand for where .)

    -
  • -

    Productions are written .

    -
  • -

    Large productions may be split into multiple definitions, indicated by ending the first one with explicit ellipses, , and starting continuations with ellipses, .

    -
  • -

    Some productions are augmented with side conditions in parentheses, “”, that provide a shorthand for a combinatorial expansion of the production into many separate cases.

    -
  • -

    If the same meta variable or non-terminal symbol appears multiple times in a production, then all those occurrences must have the same instantiation. +

    + +

    2.1.1. Grammar Notation

    +

    The following conventions are adopted in defining grammar rules for abstract syntax.

    +
      +
    • +

      Terminal symbols (atoms) are written in sans-serif font or in symbolic form: .

      +
    • +

      Nonterminal symbols are written in italic font: .

      +
    • +

      is a sequence of iterations of .

      +
    • +

      is a possibly empty sequence of iterations of . +(This is a shorthand for used where is not relevant.)

      +
    • +

      is a non-empty sequence of iterations of . +(This is a shorthand for where .)

      +
    • +

      is an optional occurrence of . +(This is a shorthand for where .)

      +
    • +

      Productions are written .

      +
    • +

      Large productions may be split into multiple definitions, indicated by ending the first one with explicit ellipses, , and starting continuations with ellipses, .

      +
    • +

      Some productions are augmented with side conditions in parentheses, “”, that provide a shorthand for a combinatorial expansion of the production into many separate cases.

      +
    • +

      If the same meta variable or non-terminal symbol appears multiple times in a production, then all those occurrences must have the same instantiation. (This is a shorthand for a side condition requiring multiple different variables to be equal.)

      -
    -
    -
    - -

    2.1.2. Auxiliary Notation

    -

    When dealing with syntactic constructs the following notation is also used:

    -
      -
    • -

      denotes the empty sequence.

      -
    • -

      denotes the length of a sequence .

      -
    • -

      denotes the -th element of a sequence , starting from .

      -
    • -

      denotes the sub-sequence of a sequence .

      -
    • -

      denotes the same sequence as , -except that the -th element is replaced with .

      -
    • -

      denotes the same sequence as , -except that the sub-sequence is replaced with .

      -
    • -

      denotes the flat sequence formed by concatenating all sequences in .

      -
    -

    Moreover, the following conventions are employed:

    -
      -
    • -

      The notation , where is a non-terminal symbol, is treated as a meta variable ranging over respective sequences of (similarly for , , ).

      -
    • -

      When given a sequence , -then the occurrences of in a sequence written are assumed to be in point-wise correspondence with (similarly for , , ). +

    +
    +
    + +

    2.1.2. Auxiliary Notation

    +

    When dealing with syntactic constructs the following notation is also used:

    +
      +
    • +

      denotes the empty sequence.

      +
    • +

      denotes the length of a sequence .

      +
    • +

      denotes the -th element of a sequence , starting from .

      +
    • +

      denotes the sub-sequence of a sequence .

      +
    • +

      denotes the same sequence as , +except that the -th element is replaced with .

      +
    • +

      denotes the same sequence as , +except that the sub-sequence is replaced with .

      +
    • +

      denotes the flat sequence formed by concatenating all sequences in .

      +
    +

    Moreover, the following conventions are employed:

    +
      +
    • +

      The notation , where is a non-terminal symbol, is treated as a meta variable ranging over respective sequences of (similarly for , , ).

      +
    • +

      When given a sequence , +then the occurrences of in a sequence written are assumed to be in point-wise correspondence with (similarly for , , ). This implicitly expresses a form of mapping syntactic constructions over a sequence.

      -
    -

    Productions of the following form are interpreted as records that map a fixed set of fields to “values” , respectively:

    -
    -

    The following notation is adopted for manipulating such records:

    -
      -
    • -

      denotes the contents of the component of .

      -
    • -

      denotes the same record as , -except that the contents of the component is replaced with .

      -
    • -

      denotes the composition of two records with the same fields of sequences by appending each sequence point-wise:

      -
      -
    • -

      denotes the composition of a sequence of records, respectively; if the sequence is empty, then all fields of the resulting record are empty.

      -
    -

    The update notation for sequences and records generalizes recursively to nested components accessed by “paths” :

    -
      -
    • -

      is short for .

      -
    • -

      is short for .

      -
    -

    where is shortened to .

    -
    -
    - -

    2.1.3. Vectors

    -

    Vectors are bounded sequences of the form (or ), -where the can either be values or complex constructions. -A vector can have at most elements.

    -
    -
    -
- -
- -

2.2. Values

-

WebAssembly programs operate on primitive numeric values. + +

Productions of the following form are interpreted as records that map a fixed set of fields to “values” , respectively:

+
+

The following notation is adopted for manipulating such records:

+
    +
  • +

    denotes the contents of the component of .

    +
  • +

    denotes the same record as , +except that the contents of the component is replaced with .

    +
  • +

    denotes the composition of two records with the same fields of sequences by appending each sequence point-wise:

    +
    +
  • +

    denotes the composition of a sequence of records, respectively; if the sequence is empty, then all fields of the resulting record are empty.

    +
+

The update notation for sequences and records generalizes recursively to nested components accessed by “paths” :

+
    +
  • +

    is short for ,

    +
  • +

    is short for ,

    +
+

where is shortened to .

+
+
+ +

2.1.3. Vectors

+

Vectors are bounded sequences of the form (or ), +where the can either be values or complex constructions. +A vector can have at most elements.

+
+
+
+ +
+ +

2.2. Values

+

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

-
- -

2.2.1. Bytes

-

The simplest form of value are raw uninterpreted bytes. +

+ +

2.2.1. Bytes

+

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

-
-
-
2.2.1.1. Conventions
-
    -
  • -

    The meta variable ranges over bytes.

    -
  • -

    Bytes are sometimes interpreted as natural numbers .

    -
-
-
-
- -

2.2.2. Integers

-

Different classes of integers with different value ranges are distinguished by their bit width and by whether they are unsigned or signed.

-
-

The latter class defines uninterpreted integers, whose signedness interpretation can vary depending on context. +

+
+
2.2.1.1. Conventions
+
    +
  • +

    The meta variable ranges over bytes.

    +
  • +

    Bytes are sometimes interpreted as natural numbers .

    +
+
+
+
+ +

2.2.2. Integers

+

Different classes of integers with different value ranges are distinguished by their bit width and by whether they are unsigned or signed.

+
+

The class defines uninterpreted integers, whose signedness interpretation can vary depending on context. In the abstract syntax, they are represented as unsigned values. However, some operations convert them to signed based on a two’s complement interpretation.

-
-

Note

-

The main integer types occurring in this specification are , , , , , , , . +

+

Note

+

The main integer types occurring in this specification are , , , , , , , . However, other sizes occur as auxiliary constructions, e.g., in the definition of floating-point numbers.

-
-
-
2.2.2.1. Conventions
-
    -
  • -

    The meta variables range over integers.

    -
  • -

    Numbers may be denoted by simple arithmetics, as in the grammar above. -In order to distinguish arithmetics like from sequences like , the latter is distinguished with parentheses.

    -
-
-
-
- -

2.2.3. Floating-Point

-

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

-

Every value has a sign and a magnitude. -Magnitudes can either be expressed as normal numbers of the form , where is the exponent and is the significand whose most signifcant bit is , -or as a subnormal number where the exponent is fixed to the smallest possible value and is ; among the subnormals are positive and negative zero values. -Since the significands are binary values, normals are represented in the form , where is the bit width of ; similarly for subnormals.

-

Possible magnitudes also include the special values (infinity) and (NaN, not a number). +

+
+
2.2.2.1. Conventions
+
    +
  • +

    The meta variables range over integers.

    +
  • +

    Numbers may be denoted by simple arithmetics, as in the grammar above. +In order to distinguish arithmetics like from sequences like , the latter is distinguished with parentheses.

    +
+
+
+
+ +

2.2.3. Floating-Point

+

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

+

Every value has a sign and a magnitude. +Magnitudes can either be expressed as normal numbers of the form , where is the exponent and is the significand whose most significant bit is , +or as a subnormal number where the exponent is fixed to the smallest possible value and is ; among the subnormals are positive and negative zero values. +Since the significands are binary values, normals are represented in the form , where is the bit width of ; similarly for subnormals.

+

Possible magnitudes also include the special values (infinity) and (NaN, not a number). NaN values have a payload that describes the mantissa bits in the underlying binary representation. No distinction is made between signalling and quiet NaNs.

-
-

where and with

-
-

A canonical NaN is a floating-point value where is a payload whose most significant bit is while all others are :

-
-

An arithmetic NaN is a floating-point value with , such that the most significant bit is 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 the binary representation the exponent of a subnormal is encoded differently than the exponent of any normal number.

-
-
-
2.2.3.1. Conventions
-
    -
  • -

    The meta variable ranges over floating-point values where clear from context.

    -
-
-
-
- -

2.2.4. Names

-

Names are sequences of characters, which are scalar values as defined by [UNICODE] (Section 2.4).

-
-

Due to the limitations of the binary format, +

+

where and with

+
+

A canonical NaN is a floating-point value where is a payload whose most significant bit is while all others are :

+
+

An arithmetic NaN is a floating-point value with , such that the most significant bit is 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 the binary 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 the [IEEE-754-2019] standard (Section 3.5.2) defines for decimal interchange formats.

+
+
+
2.2.3.1. Conventions
+
    +
  • +

    The meta variable ranges over floating-point values where clear from context.

    +
+
+
+
+ +

2.2.4. Vectors

+

Numeric vectors are 128-bit values that are processed by vector instructions (also known as SIMD instructions, single instruction multiple data). +They are represented in the abstract syntax using . The interpretation of lane types (integer or floating-point numbers) and lane sizes are determined by the specific instruction operating on them.

+
+
+ +

2.2.5. Names

+

Names are sequences of characters, which are scalar values as defined by [UNICODE] (Section 2.4).

+
+

Due to the limitations of the binary format, the length of a name is bounded by the length of its UTF-8 encoding.

-
-
2.2.4.1. Convention
-
    -
  • -

    Characters (Unicode scalar values) are sometimes used interchangeably with natural numbers .

    -
-
-
- - -
- -

2.3. Types

-

Various entities in WebAssembly are classified by types. +

+
2.2.5.1. Convention
+
    +
  • +

    Characters (Unicode scalar values) are sometimes used interchangeably with natural numbers .

    +
+
+
+ + +
+ +

2.3. Types

+

Various entities in WebAssembly are classified by types. Types are checked during validation, instantiation, and possibly execution.

-
- -

2.3.1. Number Types

-

Number types classify numeric values.

-
-

The types and classify 32 and 64 bit integers, respectively. +

+ +

2.3.1. Number Types

+

Number types classify numeric values.

+
+

The types and classify 32 and 64 bit integers, respectively. Integers are not inherently signed or unsigned, their interpretation is determined by individual operations.

-

The types and classify 32 and 64 bit floating-point data, respectively. +

The types and classify 32 and 64 bit floating-point data, respectively. They correspond to the respective binary floating-point representations, also known as single and double precision, as defined by the [IEEE-754-2019] standard (Section 3.3).

-

Number types are transparent, meaning that their bit patterns can be observed. +

Number types are transparent, meaning that their bit patterns can be observed. Values of number type can be stored in memories.

-
-
2.3.1.1. Conventions
-
    -
  • -

    The notation denotes the bit width of a number type . -That is, and .

    -
-
-
-
- -

2.3.2. Reference Types

-

Reference types classify first-class references to objects in the runtime store.

-
-

The type denotes the infinite union of all references to functions, regardless of their function types.

-

The type denotes the infinite union of all references to objects owned by the embedder and that can be passed into WebAssembly under this type.

-

Reference types are opaque, meaning that neither their size nor their bit pattern can be observed. +

+ +
2.3.1.1. Conventions
+
    +
  • +

    The notation denotes the bit width of a number type . +That is, and .

    +
+
+
+
+ +

2.3.2. Vector Types

+

Vector types classify vectors of numeric values processed by vector instructions (also known as SIMD instructions, single instruction multiple data).

+
+

The type corresponds to a 128 bit vector of packed integer or floating-point data. The packed data +can be interpreted as signed or unsigned integers, single or double precision floating-point +values, or a single 128 bit type. The interpretation is determined by individual operations.

+

Vector types, like number types are transparent, meaning that their bit patterns can be observed. +Values of vector type can be stored in memories.

+
+
2.3.2.1. Conventions
+
    +
  • +

    The notation for bit width extends to vector types as well, that is, .

    +
+
+
+
+ +

2.3.3. Reference Types

+

Reference types classify first-class references to objects in the runtime store.

+
+

The type denotes the infinite union of all references to functions, regardless of their function types.

+

The type denotes the infinite union of all references to objects owned by the embedder and that can be passed into WebAssembly under this type.

+

Reference types are opaque, meaning that neither their size nor their bit pattern can be observed. Values of reference type can be stored in tables.

-
-
- -

2.3.3. Value Types

-

Value types classify the individual values that WebAssembly code can compute with and the values that a variable accepts. -They are either number types or reference types.

-
-
-
2.3.3.1. Conventions
-
    -
  • -

    The meta variable ranges over value types or subclasses thereof where clear from context.

    -
-
-
-
- -

2.3.4. Result Types

-

Result types classify the result of executing instructions or functions, +

+
+ +

2.3.4. Value Types

+

Value types classify the individual values that WebAssembly code can compute with and the values that a variable accepts. +They are either number types, vector types, or reference types.

+
+
+
2.3.4.1. Conventions
+
    +
  • +

    The meta variable ranges over value types or subclasses thereof where clear from context.

    +
+
+
+
+ +

2.3.5. Result Types

+

Result types classify the result of executing instructions or functions, which is a sequence of values, written with brackets.

-
-
-
- -

2.3.5. Function Types

-

Function types classify the signature of functions, +

+
+
+ +

2.3.6. Function Types

+

Function types classify the signature of functions, mapping a vector of parameters to a vector of results. They are also used to classify the inputs and outputs of instructions.

- -
-
- -

2.3.6. Limits

-

Limits classify the size range of resizeable storage associated with memory types and table types.

-
-

If no maximum is given, the respective storage can grow to any size.

-
-
- -

2.3.7. Memory Types

-

Memory types classify linear memories and their size range.

-
-

The limits constrain the minimum and optionally the maximum size of a memory. +

+
+
+ +

2.3.7. Limits

+

Limits classify the size range of resizeable storage associated with memory types and table types.

+
+

If no maximum is given, the respective storage can grow to any size.

+
+
+ +

2.3.8. Memory Types

+

Memory types classify linear memories and their size range.

+
+

The limits constrain the minimum and optionally the maximum size of a memory. The limits are given in units of page size.

-
-
- -

2.3.8. Table Types

-

Table types classify tables over elements of reference type within a size range.

-
-

Like memories, tables are constrained by limits for their minimum and optionally maximum size. +

+
+ +

2.3.9. Table Types

+

Table types classify tables over elements of reference type within a size range.

+
+

Like memories, tables are constrained by limits for their minimum and optionally maximum size. The limits are given in numbers of entries.

-
-

Note

-

In future versions of WebAssembly, additional element types may be introduced.

-
-
-
- -

2.3.9. Global Types

-

Global types classify global variables, which hold a value and can either be mutable or immutable.

-
-
-
- -

2.3.10. External Types

-

External types classify imports and external values with their respective types.

-
-
-
2.3.10.1. Conventions
-

The following auxiliary notation is defined for sequences of external types. +

+

Note

+

In future versions of WebAssembly, additional element types may be introduced.

+
+
+
+ +

2.3.10. Global Types

+

Global types classify global variables, which hold a value and can either be mutable or immutable.

+
+
+
+ +

2.3.11. External Types

+

External types classify imports and external values with their respective types.

+
+
+
2.3.11.1. Conventions
+

The following auxiliary notation is defined for sequences of external types. It filters out entries of a specific kind in an order-preserving fashion:

- -
-
-
- -
- -

2.4. Instructions

-

WebAssembly code consists of sequences of instructions. +

+
+
+
+ +
+ +

2.4. Instructions

+

WebAssembly code consists of sequences of instructions. Its computational model is based on a stack machine in that instructions manipulate values on an implicit operand stack, consuming (popping) argument values and producing or returning (pushing) result values.

-

In addition to dynamic operands from the stack, some instructions also have static immediate arguments, +

In addition to dynamic operands from the stack, some instructions also have static immediate arguments, typically indices or type annotations, which are part of the instruction itself.

-

Some instructions are structured in that they bracket nested sequences of instructions.

-

The following sections group instructions into a number of different categories.

-
- -

2.4.1. Numeric Instructions

-

Numeric instructions provide basic operations over numeric values of specific type. +

Some instructions are structured in that they bracket nested sequences of instructions.

+

The following sections group instructions into a number of different categories.

+
+ +

2.4.1. Numeric Instructions

+

Numeric instructions provide basic operations over numeric values of specific type. These operations closely match respective operations available in hardware.

-
-

Numeric instructions are divided by number type. +

+

Numeric instructions are divided by number type. For each type, several subcategories can be distinguished:

-
    -
  • -

    Constants: return a static constant.

    -
  • -

    Unary Operations: consume one operand and produce one result of the respective type.

    -
  • -

    Binary Operations: consume two operands and produce one result of the respective type.

    -
  • -

    Tests: consume one operand of the respective type and produce a Boolean integer result.

    -
  • -

    Comparisons: consume two operands of the respective type and produce a Boolean integer result.

    -
  • -

    Conversions: consume a value of one type and produce a result of another -(the source type of the conversion is the one after the “”).

    -
-

Some integer instructions come in two flavors, -where a signedness annotation distinguishes whether the operands are to be interpreted as unsigned or signed integers. +

    +
  • +

    Constants: return a static constant.

    +
  • +

    Unary Operations: consume one operand and produce one result of the respective type.

    +
  • +

    Binary Operations: consume two operands and produce one result of the respective type.

    +
  • +

    Tests: consume one operand of the respective type and produce a Boolean integer result.

    +
  • +

    Comparisons: consume two operands of the respective type and produce a Boolean integer result.

    +
  • +

    Conversions: consume a value of one type and produce a result of another +(the source type of the conversion is the one after the “”).

    +
+

Some integer instructions come in two flavors, +where a signedness annotation distinguishes whether the operands are to be interpreted as unsigned or signed integers. For the other integer instructions, the use of two’s complement for the signed interpretation means that they behave the same regardless of signedness.

-
- -
2.4.1.1. Conventions
-

Occasionally, it is convenient to group operators together according to the following grammar shorthands:

-
-
-
-
- -

2.4.2. Reference Instructions

-

Instructions in this group are concerned with accessing references.

-
-

These instruction produce a null value, check for a null value, or produce a reference to a given function, respectively.

-
-
- -

2.4.3. Parametric Instructions

-

Instructions in this group can operate on operands of any value type.

-
-

The instruction simply throws away a single operand.

-

The instruction selects one of its first two operands based on whether its third operand is zero or not. +

+ +
2.4.1.1. Conventions
+

Occasionally, it is convenient to group operators together according to the following grammar shorthands:

+
+
+
+
+ +

2.4.2. Vector Instructions

+

Vector instructions (also known as SIMD instructions, single instruction multiple data) provide basic operations over values of vector type.

+
+
+
+

Vector instructions have a naming convention involving a prefix that +determines how their operands will be interpreted. +This prefix describes the shape of the operand, +written , and consisting of a packed numeric type and the number of lanes of that type. +Operations are performed point-wise on the values of each lane.

+
+

Note

+

For example, the shape interprets the operand +as four values, packed into an . +The bitwidth of the numeric type times always is 128.

+
+

Instructions prefixed with do not involve a specific interpretation, and treat the as an value or a vector of 128 individual bits.

+

Vector instructions can be grouped into several subcategories:

+
    +
  • +

    Constants: return a static constant.

    +
  • +

    Unary Operations: consume one operand and produce one result.

    +
  • +

    Binary Operations: consume two operands and produce one result.

    +
  • +

    Ternary Operations: consume three operands and produce one result.

    +
  • +

    Tests: consume one operand and produce a Boolean integer result.

    +
  • +

    Shifts: consume a operand and a operand, producing one result.

    +
  • +

    Splats: consume a value of numeric type and produce a result of a specified shape.

    +
  • +

    Extract lanes: consume a operand and return the numeric value in a given lane.

    +
  • +

    Replace lanes: consume a operand and a numeric value for a given lane, and produce a result.

    +
+

Some vector instructions have a signedness annotation which distinguishes whether the elements in the operands are to be interpreted as unsigned or signed integers. +For the other vector instructions, the use of two’s complement for the signed interpretation means that they behave the same regardless of signedness.

+
+ +
2.4.2.1. Conventions
+

Occasionally, it is convenient to group operators together according to the following grammar shorthands:

+
+
+
+
+ +

2.4.3. Reference Instructions

+

Instructions in this group are concerned with accessing references.

+
+

These instructions produce a null value, check for a null value, or produce a reference to a given function, respectively.

+
+
+ +

2.4.4. Parametric Instructions

+

Instructions in this group can operate on operands of any value type.

+
+

The instruction simply throws away a single operand.

+

The instruction selects one of its first two operands based on whether its third operand is zero or not. It may include a value type determining the type of these operands. If missing, the operands must be of numeric type.

-
-

Note

-

In future versions of WebAssembly, the type annotation on may allow for more than a single value being selected at the same time.

-
-
-
- -

2.4.4. Variable Instructions

-

Variable instructions are concerned with access to local or global variables.

- -

These instructions get or set the values of variables, respectively. -The instruction is like but also returns its argument.

-
-
- -

2.4.5. Table Instructions

-

Instructions in this group are concerned with tables table.

- -

The and instructions load or store an element in a table, respectively.

-

The instruction returns the current size of a table. -The instruction grows table by a given delta and returns the previous size, or if enough space cannot be allocated. +

+

Note

+

In future versions of WebAssembly, the type annotation on may allow for more than a single value being selected at the same time.

+
+
+
+ +

2.4.5. Variable Instructions

+

Variable instructions are concerned with access to local or global variables.

+ +

These instructions get or set the values of variables, respectively. +The instruction is like but also returns its argument.

+
+
+ +

2.4.6. Table Instructions

+

Instructions in this group are concerned with tables table.

+ +

The and instructions load or store an element in a table, respectively.

+

The instruction returns the current size of a table. +The instruction grows table by a given delta and returns the previous size, or if enough space cannot be allocated. It also takes an initialization value for the newly allocated entries.

-

The instruction sets all entries in a range to a given value.

-

The instruction copies elements from a source table region to a possibly overlapping destination region; the first index denotes the destination. -The instruction copies elements from a passive element segment into a table. -The instruction prevents further use of a passive element segment. This instruction is intended to be used as an optimization hint. After an element segment is dropped its elements can no longer be retrieved, so the memory used by this segment may be freed.

-

An additional instruction that accesses a table is the control instruction .

-
-
- -

2.4.6. Memory Instructions

-

Instructions in this group are concerned with linear memory.

-
-

Memory is accessed with and instructions for the different number types. -They all take a memory immediate that contains an address offset and the expected alignment (expressed as the exponent of a power of 2). +

The instruction sets all entries in a range to a given value.

+

The instruction copies elements from a source table region to a possibly overlapping destination region; the first index denotes the destination. +The instruction copies elements from a passive element segment into a table. +The instruction prevents further use of a passive element segment. This instruction is intended to be used as an optimization hint. After an element segment is dropped its elements can no longer be retrieved, so the memory used by this segment may be freed.

+

An additional instruction that accesses a table is the control instruction .

+
+
+ +

2.4.7. Memory Instructions

+

Instructions in this group are concerned with linear memory.

+
+

Memory is accessed with and instructions for the different number types. +They all take a memory immediate that contains an address offset and the expected alignment (expressed as the exponent of a power of 2). Integer loads and stores can optionally specify a storage size that is smaller than the bit width of the respective value type. -In the case of loads, a sign extension mode is then required to select appropriate behavior.

-

The static address offset is added to the dynamic address operand, yielding a 33 bit effective address that is the zero-based index at which the memory is accessed. +In the case of loads, a sign extension mode is then required to select appropriate behavior.

+

Vector loads can specify a shape that is half the bit width of . Each lane is half its usual size, and the sign extension mode then specifies how the smaller lane is extended to the larger lane. +Alternatively, vector loads can perform a splat, such that only a single lane of the specified storage size is loaded, and the result is duplicated to all lanes.

+

The static address offset is added to the dynamic address operand, yielding a 33 bit effective address that is the zero-based index at which the memory is accessed. All values are read and written in little endian byte order. A trap results if any of the accessed memory bytes lies outside the address range implied by the memory’s current size.

-
-

Note

-

Future version of WebAssembly might provide memory instructions with 64 bit address ranges.

-
-

The instruction returns the current size of a memory. -The instruction grows memory by a given delta and returns the previous size, or if enough memory cannot be allocated. +

+

Note

+

Future versions of WebAssembly might provide memory instructions with 64 bit address ranges.

+
+

The instruction returns the current size of a memory. +The instruction grows memory by a given delta and returns the previous size, or if enough memory cannot be allocated. Both instructions operate in units of page size.

-

The instruction sets all values in a region to a given byte. -The instruction copies data from a source memory region to a possibly overlapping destination region. -The instruction copies data from a passive data segment into a memory. -The instruction prevents further use of a passive data segment. This instruction is intended to be used as an optimization hint. After a data segment is dropped its data can no longer be retrieved, so the memory used by this segment may be freed.

-
-

Note

-

In the current version of WebAssembly, -all memory instructions implicitly operate on memory index . +

The instruction sets all values in a region to a given byte. +The instruction copies data from a source memory region to a possibly overlapping destination region. +The instruction copies data from a passive data segment into a memory. +The instruction prevents further use of a passive data segment. This instruction is intended to be used as an optimization hint. After a data segment is dropped its data can no longer be retrieved, so the memory used by this segment may be freed.

+
+

Note

+

In the current version of WebAssembly, +all memory instructions implicitly operate on memory index . This restriction may be lifted in future versions.

-
-
-
- -

2.4.7. Control Instructions

-

Instructions in this group affect the flow of control.

- -

The instruction does nothing.

-

The instruction causes an unconditional trap.

-

The , and instructions are structured instructions. -They bracket nested sequences of instructions, called blocks, terminated with, or separated by, or pseudo-instructions. +