e01.org

add128: Wasm numeric instruction

The add128 numeric instruction adds two 128-bit integers, represented by four 64-bit integers, to produce a 128-bit result represented by two 64-bit integers.

The **`add128`** [numeric instruction](/docs/WebAssembly/Reference/Numeric) adds two 128-bit integers, represented by four 64-bit integers, to produce a 128-bit result represented by two 64-bit integers.

tabbed-taller

```wat interactive-example
(module
(import "console" "log" (func $log (param i64)))
(func $main

i64.const 123456789012345
i64.const 123456789070
i64.const 98765432101
i64.const 9876543210123
i64.add128
call $log ;; log high 64 bits
call $log ;; log low 64 bits
)
(start $main)
)
```

```js interactive-example
const url = "{%wasm-url%}";
await WebAssembly.instantiateStreaming(fetch(url), { console });
```

## WAT syntax

```plain
i64.add128
```

- `i64.add128`
- : The `i64.add128` instruction.

### Immediates

None.

### Operand stack

```plain
[low_left_input:i64 high_left_input:i64 low_right_input:i64 high_right_input:i64] -> [low_output:i64 high_output:i64]
```

- `low_left_input`
- : An [`i64`](/docs/WebAssembly/Reference/Value_types/i64) representing the low 64 bits of the left-hand-side 128-bit integer.
- `high_left_input`
- : An `i64` representing the high 64 bits of the left-hand-side 128-bit integer.
- `low_right_input`
- : An `i64` representing the low 64 bits of the right-hand-side 128-bit integer.
- `high_right_input`
- : An `i64` representing the high 64 bits of the right-hand-side 128-bit integer.
- `low_output`
- : An `i64` representing the low 64 bits of the result.
- `high_output`
- : An `i64` representing the high 64 bits of the result.

### Binary encoding

| Instruction | Binary format | Example text => binary |
| ------------ | ------------- | --------------------------- |
| `i64.add128` | `0xfc 19:u32` | `i64.add128` => `0xfc 0x13` |

## Description

The `add128` instruction adds two 128-bit integers — represented by four `i64` values — together to produce a 128-bit result represented by two `i64` values.

This is one of the **wide arithmetic** operations, which are useful in situations where larger-than-64-bit numbers are being used in source languages with Wasm as a compile target. One such example is cryptographic algorithms.

These methods allow engines to generate more performant machine code for these operations than is possible with `i64` arithmetic operations.

## Specifications

## Browser compatibility

## See also

- [`mul_wide_s`](/docs/WebAssembly/Reference/Numeric/mul_wide_s)
- [`mul_wide_u`](/docs/WebAssembly/Reference/Numeric/mul_wide_u)
- [`sub128`](/docs/WebAssembly/Reference/Numeric/sub128)

source: MDN Web Docs mirror · page

Cite this

"add128: Wasm numeric instruction". MDN Web Docs. CC BY-SA 2.5 (MDN). https://developer.mozilla.org/en-US/docs/WebAssembly/Reference/Numeric/add128

JSON record · API collection · citation policy