MDN self-hosted library · e01.org

WebAssembly numeric instructions

WebAssembly numeric instructions.

no runnable cells landing-page upstream source

WebAssembly numeric instructions.

Constants

  • const
  • : Declare a constant number.

Comparison

  • eq
  • : Check if two numbers are equal.
  • eqz
  • : Check if a number is equal to 0.
  • ne
  • : Check if two numbers are not equal.
  • gt
  • : Check if a floating point number is greater than another floating point number.
  • gt_s
  • : Check if a signed integer is greater than another signed integer.
  • gt_u
  • : Check if an unsigned integer is greater than another unsigned integer.
  • lt
  • : Check if a floating point number is less than another floating point number.
  • lt_s
  • : Check if a signed integer is less than another signed integer.
  • lt_u
  • : Check if an unsigned integer is less than another unsigned integer.
  • ge
  • : Check if a floating point number is greater than or equal to another floating point number.
  • ge_s
  • : Check if a signed integer is greater than or equal to another signed integer.
  • ge_u
  • : Check if an unsigned integer is greater than or equal to another unsigned integer.
  • le
  • : Check if a floating point number is less than or equal to another floating point number.
  • le_s
  • : Check if a signed integer is less than or equal to another signed integer.
  • le_u
  • : Check if an unsigned integer is less than or equal to another unsigned integer.

Arithmetic

  • add
  • : Add two numbers.
  • sub
  • : Subtract one number from another number.
  • mul
  • : Multiply one number by another number.
  • div
  • : Divide one number by another number.
  • rem
  • : Calculate the remainder left over when one integer is divided by another integer.

Wide arithmetic

  • add128
  • : Add two 128-bit integers, represented by four 64-bit integers, to produce a 128-bit result represented by two 64-bit integers.
  • mul_wide_s
  • : Multiply two signed 64-bit integers to produce a signed 128-bit result represented by two 64-bit integers.
  • mul_wide_u
  • : Multiply two unsigned 64-bit integers to produce an unsigned 128-bit result represented by two 64-bit integers.
  • sub128
  • : Subtract one 128-bit integer, represented by two 64-bit integers, from another to produce a 128-bit result represented by two 64-bit integers.

Conversion

  • extend
  • : Convert (extend) i32 to i64.
  • wrap_i64
  • : Convert (wrap) i64 to i32.
  • promote_32
  • : Convert (promote) f32 to f64.
  • demote
  • : Convert (demote) f64 to f32.
  • convert
  • : Convert integers to floating points.
  • trunc
  • : Gets the value of a floating point number without its fractional part.
  • trunc_f32_s
  • : Removes the fractional part of an f32 value and outputs it as a signed integer.
  • trunc_f32_u
  • : Removes the fractional part of an f32 value and outputs it as an unsigned integer.
  • trunc_f64_s
  • : Removes the fractional part of an f64 value and outputs it as a signed integer.
  • trunc_f64_u
  • : Removes the fractional part of an f64 value and outputs it as an unsigned integer.
  • reinterpret
  • : Reinterpret the bytes of integers as floating points and vice versa.

Floating point specific instructions

  • min
  • : Get the lower of two numbers.
  • max
  • : Get the higher of two floating point numbers.
  • nearest
  • : Round a number to the nearest integer.
  • ceil
  • : Round up a number.
  • floor
  • : Round down a number.
  • trunc
  • : Discard the fractional part of a number.
  • abs
  • : Get the absolute value of a number.
  • neg
  • : Negate a number.
  • sqrt
  • : Get the square root of a number.
  • copysign
  • : Copy just the sign bit from one number to another.

Bitwise

  • and
  • : Used for performing a bitwise AND.
  • or
  • : Used for performing a bitwise OR.
  • xor
  • : Used for performing a bitwise XOR.
  • shl
  • : Used for performing a bitwise left-shift.
  • shr_s
  • : Used for performing a bitwise right-shift on signed integers.
  • shr_u
  • : Used for performing a bitwise right-shift on unsigned integers.
  • rotl
  • : Used for performing a bitwise left-rotate.
  • rotr
  • : Used for performing a bitwise right-rotate.
  • clz
  • : Count the number of leading zeros in a number's binary representation.
  • ctz
  • : Count the number of trailing zeros in a number's binary representation.
  • popcnt
  • : Count the total amount of 1s in a number's binary representation.

Sign extension operations

  • extend8_s
  • : Sign-extend the low 8 bits of an integer to propagate its sign throughout the entire value.
  • extend16_s
  • : Sign-extend the low 16 bits of an integer to propagate its sign throughout the entire value.
  • extend32_s
  • : Sign-extend the low 32 bits of a 64-bit integer to propagate its sign throughout the entire value.