core
Injected into every compilation unit. Not imported, and not on disk.
Methods
| i32.clz | Counts leading zero bits. |
| i32.ctz | Counts trailing zero bits. |
| i32.popcnt | Counts set bits (population count). |
| i32.rotl | Rotates left, wrapping bits shifted off the top back into the bottom. |
| i32.rotr | Rotates right, wrapping bits shifted off the bottom back into the top. |
| i32.div_u | Unsigned division, treating both operands as unsigned. |
| i32.rem_u | Unsigned remainder, treating both operands as unsigned. |
| i32.lt_u | Unsigned less-than. |
| i32.le_u | Unsigned less-than-or-equal. |
| i32.gt_u | Unsigned greater-than. |
| i32.ge_u | Unsigned greater-than-or-equal. |
| i64.clz | Counts leading zero bits. |
| i64.ctz | Counts trailing zero bits. |
| i64.popcnt | Counts set bits (population count). |
| i64.rotl | Rotates left, wrapping bits shifted off the top back into the bottom. |
| i64.rotr | Rotates right, wrapping bits shifted off the bottom back into the top. |
| i64.div_u | Unsigned division, treating both operands as unsigned. |
| i64.rem_u | Unsigned remainder, treating both operands as unsigned. |
| i64.lt_u | Unsigned less-than. |
| i64.le_u | Unsigned less-than-or-equal. |
| i64.gt_u | Unsigned greater-than. |
| i64.ge_u | Unsigned greater-than-or-equal. |
| i64.mul_wide_s | Signed 64x64 multiply producing the full 128-bit product. |
| i64.mul_wide_u | Unsigned 64x64 multiply producing the full 128-bit product. |
| f32.abs | Absolute value. |
| f32.sqrt | Square root. |
| f32.ceil | Rounds up, toward positive infinity. |
| f32.floor | Rounds down, toward negative infinity. |
| f32.trunc | Rounds toward zero, discarding the fractional part. |
| f32.nearest | Rounds to the nearest integer, ties to even. |
| f32.min | The smaller of two values. |
| f32.max | The larger of two values. |
| f32.copysign | Returns self with the sign of rhs. |
| f64.abs | Absolute value. |
| f64.sqrt | Square root. |
| f64.ceil | Rounds up, toward positive infinity. |
| f64.floor | Rounds down, toward negative infinity. |
| f64.trunc | Rounds toward zero, discarding the fractional part. |
| f64.nearest | Rounds to the nearest integer, ties to even. |
| f64.min | The smaller of two values. |
| f64.max | The larger of two values. |
| f64.copysign | Returns self with the sign of rhs. |
@inline func i32.clz(self: i32) -> i32
Counts leading zero bits.
Returns 32 for an input of zero: every bit is a leading zero. This is the number of zeros above the most significant set bit, so (1).clz() is 31.
- Returns
- the number of leading zero bits,
0..=32
- See also
i32.ctz, i32.popcnt
Source
func i32.clz(self: i32) -> i32 { return wasm.i32.clz(self); }
@inline func i32.ctz(self: i32) -> i32
Counts trailing zero bits.
Returns 32 for an input of zero, mirroring clz. For any other value it is the index of the lowest set bit.
- Returns
- the number of trailing zero bits,
0..=32
- See also
i32.clz
Source
func i32.ctz(self: i32) -> i32 { return wasm.i32.ctz(self); }
@inline func i32.popcnt(self: i32) -> i32
Counts set bits (population count).
- Returns
- the number of one bits,
0..=32
Source
func i32.popcnt(self: i32) -> i32 { return wasm.i32.popcnt(self); }
@inline func i32.rotl(self: i32, rhs: i32) -> i32
Rotates left, wrapping bits shifted off the top back into the bottom.
Unlike <<, no bits are lost. The rotate amount is taken modulo 32.
- Parameters
- rhs — how many bits to rotate by
- See also
i32.rotr
Source
func i32.rotl(self: i32, rhs: i32) -> i32 { return wasm.i32.rotl(self, rhs); }
@inline func i32.rotr(self: i32, rhs: i32) -> i32
Rotates right, wrapping bits shifted off the bottom back into the top.
- Parameters
- rhs — how many bits to rotate by
- See also
i32.rotl
Source
func i32.rotr(self: i32, rhs: i32) -> i32 { return wasm.i32.rotr(self, rhs); }
@inline func i32.div_u(self: i32, rhs: i32) -> i32
Unsigned division, treating both operands as unsigned.
/ is signed, so this is the only way to divide unsigned. The difference is not subtle: a.div_u(2) where a is -1 gives 2147483647, because -1 read as unsigned is 4294967295.
Traps on division by zero, like /.
- Parameters
- rhs — the divisor
- See also
i32.rem_u
Source
func i32.div_u(self: i32, rhs: i32) -> i32 { return wasm.i32.div_u(self, rhs); }
@inline func i32.rem_u(self: i32, rhs: i32) -> i32
Unsigned remainder, treating both operands as unsigned.
Traps on division by zero.
- Parameters
- rhs — the divisor
- See also
i32.div_u
Source
func i32.rem_u(self: i32, rhs: i32) -> i32 { return wasm.i32.rem_u(self, rhs); }
@inline func i32.lt_u(self: i32, rhs: i32) -> i32
Unsigned less-than.
< is signed. a.lt_u(1) where a is -1 is 0, because -1 read as unsigned is the largest value there is.
- Returns
1 if self < rhs as unsigned, 0 otherwise
- See also
i32.le_u, i32.gt_u, i32.ge_u
Source
func i32.lt_u(self: i32, rhs: i32) -> i32 { return wasm.i32.lt_u(self, rhs); }
@inline func i32.le_u(self: i32, rhs: i32) -> i32
Unsigned less-than-or-equal.
- Returns
1 if self <= rhs as unsigned, 0 otherwise
- See also
i32.lt_u
Source
func i32.le_u(self: i32, rhs: i32) -> i32 { return wasm.i32.le_u(self, rhs); }
@inline func i32.gt_u(self: i32, rhs: i32) -> i32
- Returns
1 if self > rhs as unsigned, 0 otherwise
- See also
i32.ge_u
Source
func i32.gt_u(self: i32, rhs: i32) -> i32 { return wasm.i32.gt_u(self, rhs); }
@inline func i32.ge_u(self: i32, rhs: i32) -> i32
Unsigned greater-than-or-equal.
- Returns
1 if self >= rhs as unsigned, 0 otherwise
- See also
i32.gt_u
Source
func i32.ge_u(self: i32, rhs: i32) -> i32 { return wasm.i32.ge_u(self, rhs); }
@inline func i64.clz(self: i64) -> i64
Counts leading zero bits.
Returns 64 for an input of zero.
- Returns
- the number of leading zero bits,
0..=64
- See also
i64.ctz
Source
func i64.clz(self: i64) -> i64 { return wasm.i64.clz(self); }
@inline func i64.ctz(self: i64) -> i64
Counts trailing zero bits.
Returns 64 for an input of zero.
- Returns
- the number of trailing zero bits,
0..=64
- See also
i64.clz
Source
func i64.ctz(self: i64) -> i64 { return wasm.i64.ctz(self); }
@inline func i64.popcnt(self: i64) -> i64
Counts set bits (population count).
- Returns
- the number of one bits,
0..=64
Source
func i64.popcnt(self: i64) -> i64 { return wasm.i64.popcnt(self); }
@inline func i64.rotl(self: i64, rhs: i64) -> i64
Rotates left, wrapping bits shifted off the top back into the bottom.
The rotate amount is taken modulo 64.
- Parameters
- rhs — how many bits to rotate by
- See also
i64.rotr
Source
func i64.rotl(self: i64, rhs: i64) -> i64 { return wasm.i64.rotl(self, rhs); }
@inline func i64.rotr(self: i64, rhs: i64) -> i64
Rotates right, wrapping bits shifted off the bottom back into the top.
- Parameters
- rhs — how many bits to rotate by
- See also
i64.rotl
Source
func i64.rotr(self: i64, rhs: i64) -> i64 { return wasm.i64.rotr(self, rhs); }
@inline func i64.div_u(self: i64, rhs: i64) -> i64
Unsigned division, treating both operands as unsigned.
Traps on division by zero.
- Parameters
- rhs — the divisor
- See also
i64.rem_u
Source
func i64.div_u(self: i64, rhs: i64) -> i64 { return wasm.i64.div_u(self, rhs); }
@inline func i64.rem_u(self: i64, rhs: i64) -> i64
Unsigned remainder, treating both operands as unsigned.
Traps on division by zero.
- Parameters
- rhs — the divisor
- See also
i64.div_u
Source
func i64.rem_u(self: i64, rhs: i64) -> i64 { return wasm.i64.rem_u(self, rhs); }
@inline func i64.lt_u(self: i64, rhs: i64) -> i32
Unsigned less-than.
Note the result type: a comparison on i64 operands still yields i32, since WebAssembly has no boolean type and Reed's bool is i32.
- Returns
1 if self < rhs as unsigned, 0 otherwise
- See also
i64.le_u
Source
func i64.lt_u(self: i64, rhs: i64) -> i32 { return wasm.i64.lt_u(self, rhs); }
@inline func i64.le_u(self: i64, rhs: i64) -> i32
Unsigned less-than-or-equal.
- Returns
1 if self <= rhs as unsigned, 0 otherwise
- See also
i64.lt_u
Source
func i64.le_u(self: i64, rhs: i64) -> i32 { return wasm.i64.le_u(self, rhs); }
@inline func i64.gt_u(self: i64, rhs: i64) -> i32
- Returns
1 if self > rhs as unsigned, 0 otherwise
- See also
i64.ge_u
Source
func i64.gt_u(self: i64, rhs: i64) -> i32 { return wasm.i64.gt_u(self, rhs); }
@inline func i64.ge_u(self: i64, rhs: i64) -> i32
Unsigned greater-than-or-equal.
- Returns
1 if self >= rhs as unsigned, 0 otherwise
- See also
i64.gt_u
Source
func i64.ge_u(self: i64, rhs: i64) -> i32 { return wasm.i64.ge_u(self, rhs); }
@inline func i64.mul_wide_s(self: i64, rhs: i64) -> (i64, i64)
Signed 64x64 multiply producing the full 128-bit product.
Ordinary * on i64 discards the top half on overflow. This keeps it, as two i64 values destructured together:
let (low, high): (i64, i64) = a.mul_wide_s(b);
The low half comes first. Multiplying 2^32 by 2^32 gives low == 0 and high == 1, since the product is exactly 2^64.
Requires the wide-arithmetic proposal in the engine.
- Parameters
- rhs — the right operand
- Returns
- the
(low, high) halves of the 128-bit product
- See also
i64.mul_wide_u
Source
func i64.mul_wide_s(self: i64, rhs: i64) -> (i64, i64) {
return wasm.i64.mul_wide_s(self, rhs);
}
@inline func i64.mul_wide_u(self: i64, rhs: i64) -> (i64, i64)
Unsigned 64x64 multiply producing the full 128-bit product.
As mul_wide_s, but both operands are read as unsigned. The low half comes first.
- Parameters
- rhs — the right operand
- Returns
- the
(low, high) halves of the 128-bit product
- See also
i64.mul_wide_s
Source
func i64.mul_wide_u(self: i64, rhs: i64) -> (i64, i64) {
return wasm.i64.mul_wide_u(self, rhs);
}
@inline func f32.abs(self: f32) -> f32
Absolute value.
Clears the sign bit, so abs of -0.0 is +0.0 and abs of NaN is a NaN with the sign cleared rather than a trap.
Source
func f32.abs(self: f32) -> f32 { return wasm.f32.abs(self); }
@inline func f32.sqrt(self: f32) -> f32
Square root.
Returns NaN for a negative operand rather than trapping.
Source
func f32.sqrt(self: f32) -> f32 { return wasm.f32.sqrt(self); }
@inline func f32.ceil(self: f32) -> f32
Rounds up, toward positive infinity.
- See also
f32.floor, f32.trunc, f32.nearest
Source
func f32.ceil(self: f32) -> f32 { return wasm.f32.ceil(self); }
@inline func f32.floor(self: f32) -> f32
Rounds down, toward negative infinity.
For a negative operand this rounds away from zero: floor of -1.7 is -2.0.
- See also
f32.ceil, f32.trunc
Source
func f32.floor(self: f32) -> f32 { return wasm.f32.floor(self); }
@inline func f32.trunc(self: f32) -> f32
Rounds toward zero, discarding the fractional part.
Unlike floor, this rounds a negative operand toward zero: trunc of -1.7 is -1.0.
- See also
f32.floor, f32.nearest
Source
func f32.trunc(self: f32) -> f32 { return wasm.f32.trunc(self); }
@inline func f32.nearest(self: f32) -> f32
Rounds to the nearest integer, ties to even.
Not the "round half away from zero" most languages use: 2.5 rounds to 2.0 and 3.5 rounds to 4.0, because each picks the even neighbour.
- See also
f32.trunc, f32.floor, f32.ceil
Source
func f32.nearest(self: f32) -> f32 { return wasm.f32.nearest(self); }
@inline func f32.min(self: f32, rhs: f32) -> f32
The smaller of two values.
Returns NaN if either operand is NaN, which differs from a <-based comparison, and distinguishes -0.0 from +0.0.
- Parameters
- rhs — the other value
- See also
f32.max
Source
func f32.min(self: f32, rhs: f32) -> f32 { return wasm.f32.min(self, rhs); }
@inline func f32.max(self: f32, rhs: f32) -> f32
The larger of two values.
Returns NaN if either operand is NaN.
- Parameters
- rhs — the other value
- See also
f32.min
Source
func f32.max(self: f32, rhs: f32) -> f32 { return wasm.f32.max(self, rhs); }
@inline func f32.copysign(self: f32, rhs: f32) -> f32
Returns self with the sign of rhs.
The magnitude is always this value's; only the sign bit is taken from rhs. So (3.0).copysign(-1.0) is -3.0. Works on NaN and on zero, which is what makes it distinct from a multiply.
- Parameters
- rhs — the value to take the sign from
Source
func f32.copysign(self: f32, rhs: f32) -> f32 { return wasm.f32.copysign(self, rhs); }
@inline func f64.abs(self: f64) -> f64
Absolute value.
Clears the sign bit, so abs of -0.0 is +0.0.
Source
func f64.abs(self: f64) -> f64 { return wasm.f64.abs(self); }
@inline func f64.sqrt(self: f64) -> f64
Square root.
Returns NaN for a negative operand rather than trapping.
Source
func f64.sqrt(self: f64) -> f64 { return wasm.f64.sqrt(self); }
@inline func f64.ceil(self: f64) -> f64
Rounds up, toward positive infinity.
- See also
f64.floor, f64.trunc, f64.nearest
Source
func f64.ceil(self: f64) -> f64 { return wasm.f64.ceil(self); }
@inline func f64.floor(self: f64) -> f64
Rounds down, toward negative infinity.
For a negative operand this rounds away from zero: floor of -1.7 is -2.0.
- See also
f64.ceil, f64.trunc
Source
func f64.floor(self: f64) -> f64 { return wasm.f64.floor(self); }
@inline func f64.trunc(self: f64) -> f64
Rounds toward zero, discarding the fractional part.
trunc of -1.7 is -1.0, where floor gives -2.0.
- See also
f64.floor, f64.nearest
Source
func f64.trunc(self: f64) -> f64 { return wasm.f64.trunc(self); }
@inline func f64.nearest(self: f64) -> f64
Rounds to the nearest integer, ties to even.
2.5 rounds to 2.0 and 3.5 rounds to 4.0.
- See also
f64.trunc, f64.floor, f64.ceil
Source
func f64.nearest(self: f64) -> f64 { return wasm.f64.nearest(self); }
@inline func f64.min(self: f64, rhs: f64) -> f64
The smaller of two values.
Returns NaN if either operand is NaN, and distinguishes -0.0 from +0.0.
- Parameters
- rhs — the other value
- See also
f64.max
Source
func f64.min(self: f64, rhs: f64) -> f64 { return wasm.f64.min(self, rhs); }
@inline func f64.max(self: f64, rhs: f64) -> f64
The larger of two values.
Returns NaN if either operand is NaN.
- Parameters
- rhs — the other value
- See also
f64.min
Source
func f64.max(self: f64, rhs: f64) -> f64 { return wasm.f64.max(self, rhs); }
@inline func f64.copysign(self: f64, rhs: f64) -> f64
Returns self with the sign of rhs.
(3.0).copysign(-1.0) is -3.0. Only the sign bit is taken from rhs.
- Parameters
- rhs — the value to take the sign from
Source
func f64.copysign(self: f64, rhs: f64) -> f64 { return wasm.f64.copysign(self, rhs); }