Value Types, Numeric Instructions and Locals
5.1 Value Types
32-bit integer (sign-agnostic) 32-bit IEEE 754 float 64-bit IEEE 754 float 128-bit SIMD vector Not exposed to JS (TypeError) Wasm exported function or null Opaque host reference
GC types (anyref, eqref, i31ref, structref, arrayref, typed refs) Opaque objects in JS
Integers have no signedness. Operations specify it (i32.div_s vs i32.div_u, i32.lt_s vs i32.lt_u).
5.2 Numeric Instructions
Instructions (i32 shown; i64/f32/f64 are analogous) i32.const, i64.const, f32.const, f64.const
add, sub, mul, div_s, div_u, rem_s, rem_u and, or, xor, shl, shr_s, shr_u, rotl, rotr, clz, ctz, popcnt
eq, ne, lt_s, lt_u, gt_s, gt_u, le_s, le_u, ge_s, ge_u, eqz
f64.abs, neg, sqrt, ceil, floor, trunc, nearest, min, max, copysign, div
i32.wrap_i64, i64.extend_i32_s/u, i32.trunc_f64_s, i32.trunc_sat_f64_s (saturating, no trap), f64.convert_i32_s, f32.demote_f64, f64.promote_f32, i32.reinterpret_f32
i32.extend8_s, i32.extend16_s, i64.extend32_s drop, select (ternary without branching)
(func $abs (param $x i32) (result i32)
(select
(i32.sub (i32.const 0) (local.get $x)) ;; value if condition is true
(local.get $x) ;; value if condition is false
(i32.lt_s (local.get $x) (i32.const 0)))) ;; condition5.3 Locals
local.get, local.set, local.tee (set and keep the value on the stack). Parameters are the first locals.
(func $sum_to (param $n i32) (result i32)
(local $i i32)
(local $acc i32) ;; locals are zero-initialized
(local.set $i (i32.const 1))
(block $done
(loop $continue
(br_if $done (i32.gt_s (local.get $i) (local.get $n)))
(local.set $acc (i32.add (local.get $acc) (local.get $i)))
(local.set $i (i32.add (local.get $i) (i32.const 1)))
(br $continue)))
(local.get $acc))