mul_wide_u: Wasm numeric instruction

The mul_wide_u numeric instruction multiplies two unsigned 64-bit integers to produce an unsigned 128-bit result represented by two 64-bit integers.

Try it

(module
  (import "console" "log" (func $log (param i64)))
  (func $main

    i64.const 123456789012345
    i64.const 123456789070
    i64.mul_wide_u
    call $log ;; log high 64 bits
    call $log ;; log low 64 bits
  )
  (start $main)
)
const url = "{%wasm-url%}";
await WebAssembly.instantiateStreaming(fetch(url), { console });

WAT syntax

i64.mul_wide_u
i64.mul_wide_u

The i64.mul_wide_u instruction.

Immediates

None.

Operand stack

[low_input:i64 high_input:i64] -> [low_output:i64 high_output:i64]
low_input

The first i64 input.

high_input

The second i64 input.

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.mul_wide_u 0xfc 22:u32 i64.mul_wide_u => 0xfc 0x16

Description

The mul_wide_u instruction multiplies two unsigned i64 values to produce an unsigned 128-bit result represented by a pair of i64 values. Such operations are termed wide arithmetic, which is useful in any situation where larger-than-64-bit numbers are being used in source languages with Wasm as a compile target, for example cryptographic algorithms.

More importantly, it also allows engines to generate more efficient machine code for these operations than is possible with i64 arithmetic operations.

Specifications

This feature does not appear to be defined in any specification.

Browser compatibility

See also