std/math/bits
Index
Variables
fn LeadingZeros(x: uint): int
fn LeadingZeros8(x: u8): int
fn LeadingZeros16(x: u16): int
fn LeadingZeros32(x: u32): int
fn LeadingZeros64(x: u64): int
fn TrailingZeros(x: uint): int
fn TrailingZeros8(x: u8): int
fn TrailingZeros16(x: u16): int
fn TrailingZeros32(x: u32): int
fn TrailingZeros64(x: u64): int
fn OnesCount(x: uint): int
fn OnesCount8(x: u8): int
fn OnesCount16(x: u16): int
fn OnesCount32(x: u32): int
fn OnesCount64(mut x: u64): int
fn RotateLeft(x: uint, k: int): uint
fn RotateLeft8(x: u8, k: int): u8
fn RotateLeft16(x: u16, k: int): u16
fn RotateLeft32(x: u32, k: int): u32
fn RotateLeft64(x: u64, k: int): u64
fn Reverse(x: uint): uint
fn Reverse8(x: u8): u8
fn Reverse16(x: u16): u16
fn Reverse32(mut x: u32): u32
fn Reverse64(mut x: u64): u64
fn ReverseBytes(x: uint): uint
fn ReverseBytes16(x: u16): u16
fn ReverseBytes32(mut x: u32): u32
fn ReverseBytes64(mut x: u64): u64
fn Len(x: uint): int
fn Len8(x: u8): int
fn Len16(mut x: u16): (n: int)
fn Len32(mut x: u32): (n: int)
fn Len64(mut x: u64): (n: int)
fn Add(x: uint, y: uint, carry: uint): (sum: uint, carryOut: uint)
fn Add32(x: u32, y: u32, carry: u32): (sum: u32, carryOut: u32)
fn Add64(x: u64, y: u64, carry: u64): (sum: u64, carryOut: u64)
fn Sub(x: uint, y: uint, borrow: uint): (diff: uint, borrowOut: uint)
fn Sub32(x: u32, y: u32, borrow: u32): (diff: u32, borrowOut: u32)
fn Sub64(x: u64, y: u64, borrow: u64): (diff: u64, borrowOut: u64)
fn Mul(x: uint, y: uint): (hi: uint, lo: uint)
fn Mul32(x: u32, y: u32): (hi: u32, lo: u32)
fn Mul64(x: u64, y: u64): (hi: u64, lo: u64)
fn Div(hi: uint, lo: uint, y: uint): (quo: uint, rem: uint)
fn Div32(hi: u32, lo: u32, y: u32): (quo: u32, rem: u32)
fn Div64(hi: u64, lo: u64, mut y: u64): (quo: u64, rem: u64)
fn Rem(hi: uint, lo: uint, y: uint): uint
fn Rem32(hi: u32, lo: u32, y: u32): u32
fn Rem64(hi: u64, lo: u64, y: u64): u64
Variables
const UintSize = 32 << (^uint(0) >> 63) // 32 or 64
Is the size of a uint in bits.
LeadingZeros
fn LeadingZeros(x: uint): int
Returns the number of leading zero bits in x; the result is UintSize for x == 0.
LeadingZeros8
fn LeadingZeros8(x: u8): int
Returns the number of leading zero bits in x; the result is 8 for x == 0.
LeadingZeros16
fn LeadingZeros16(x: u16): int
Returns the number of leading zero bits in x; the result is 16 for x == 0.
LeadingZeros32
fn LeadingZeros32(x: u32): int
Returns the number of leading zero bits in x; the result is 32 for x == 0.
LeadingZeros64
fn LeadingZeros64(x: u64): int
Returns the number of leading zero bits in x; the result is 64 for x == 0.
TrailingZeros
fn TrailingZeros(x: uint): int
Returns the number of trailing zero bits in x; the result is UintSize for x == 0.
TrailingZeros8
fn TrailingZeros8(x: u8): int
Returns the number of trailing zero bits in x; the result is 8 for x == 0.
TrailingZeros16
fn TrailingZeros16(x: u16): int
Returns the number of trailing zero bits in x; the result is 16 for x == 0.
TrailingZeros32
fn TrailingZeros32(x: u32): int
Returns the number of trailing zero bits in x; the result is 32 for x == 0.
TrailingZeros64
fn TrailingZeros64(x: u64): int
Returns the number of trailing zero bits in x; the result is 64 for x == 0.
OnesCount
fn OnesCount(x: uint): int
Returns the number of one bits ("population count") in x.
OnesCount8
fn OnesCount8(x: u8): int
Returns the number of one bits ("population count") in x.
OnesCount16
fn OnesCount16(x: u16): int
Returns the number of one bits ("population count") in x.
OnesCount32
fn OnesCount32(x: u32): int
Returns the number of one bits ("population count") in x.
OnesCount64
fn OnesCount64(mut x: u64): int
Returns the number of one bits ("population count") in x.
RotateLeft
fn RotateLeft(x: uint, k: int): uint
Returns the value of x rotated left by (k mod UintSize) bits. To rotate x right by k bits, call rotate_left(x, -k).
This function's execution time does not depend on the inputs.
RotateLeft8
fn RotateLeft8(x: u8, k: int): u8
Returns the value of x rotated left by (k mod 8) bits. To rotate x right by k bits, call rotate_left8(x, -k).
This function's execution time does not depend on the inputs.
RotateLeft16
fn RotateLeft16(x: u16, k: int): u16
Returns the value of x rotated left by (k mod 16) bits. To rotate x right by k bits, call rotate_left16(x, -k).
This function's execution time does not depend on the inputs.
RotateLeft32
fn RotateLeft32(x: u32, k: int): u32
Returns the value of x rotated left by (k mod 32) bits. To rotate x right by k bits, call rotate_left32(x, -k).
This function's execution time does not depend on the inputs.
RotateLeft64
fn RotateLeft64(x: u64, k: int): u64
Returns the value of x rotated left by (k mod 64) bits. To rotate x right by k bits, call rotate_left64(x, -k).
This function's execution time does not depend on the inputs.
Reverse
fn Reverse(x: uint): uint
Returns the value of x with its bits in reversed order.
Reverse8
fn Reverse8(x: u8): u8
Returns the value of x with its bits in reversed order.
Reverse16
fn Reverse16(x: u16): u16
Returns the value of x with its bits in reversed order.
Reverse32
fn Reverse32(mut x: u32): u32
Returns the value of x with its bits in reversed order.
Reverse64
fn Reverse64(mut x: u64): u64
Returns the value of x with its bits in reversed order.
ReverseBytes
fn ReverseBytes(x: uint): uint
Returns the value of x with its bytes in reversed order.
This function's execution time does not depend on the inputs.
ReverseBytes16
fn ReverseBytes16(x: u16): u16
Returns the value of x with its bytes in reversed order.
This function's execution time does not depend on the inputs.
ReverseBytes32
fn ReverseBytes32(mut x: u32): u32
Returns the value of x with its bytes in reversed order.
This function's execution time does not depend on the inputs.
ReverseBytes64
fn ReverseBytes64(mut x: u64): u64
Returns the value of x with its bytes in reversed order.
This function's execution time does not depend on the inputs.
Len
fn Len(x: uint): int
Returns the minimum number of bits required to represent x; the result is 0 for x == 0.
Len8
fn Len8(x: u8): int
Returns the minimum number of bits required to represent x; the result is 0 for x == 0.
Len16
fn Len16(mut x: u16): (n: int)
Returns the minimum number of bits required to represent x; the result is 0 for x == 0.
Len32
fn Len32(mut x: u32): (n: int)
Returns the minimum number of bits required to represent x; the result is 0 for x == 0.
Len64
fn Len64(mut x: u64): (n: int)
Returns the minimum number of bits required to represent x; the result is 0 for x == 0.
Add
fn Add(x: uint, y: uint, carry: uint): (sum: uint, carryOut: uint)
Add returns the sum with carry of x, y and carry: sum = x + y + carry. The carry input must be 0 or 1; otherwise the behavior is undefined. The carryOut output is guaranteed to be 0 or 1.
This function's execution time does not depend on the inputs.
Add32
fn Add32(x: u32, y: u32, carry: u32): (sum: u32, carryOut: u32)
Returns the sum with carry of x, y and carry: sum = x + y + carry. The carry input must be 0 or 1; otherwise the behavior is undefined. The carryOut output is guaranteed to be 0 or 1.
This function's execution time does not depend on the inputs.
Add64
fn Add64(x: u64, y: u64, carry: u64): (sum: u64, carryOut: u64)
Returns the sum with carry of x, y and carry: sum = x + y + carry. The carry input must be 0 or 1; otherwise the behavior is undefined. The carryOut output is guaranteed to be 0 or 1.
This function's execution time does not depend on the inputs.
Sub
fn Sub(x: uint, y: uint, borrow: uint): (diff: uint, borrowOut: uint)
Returns the difference of x, y and borrow: diff = x - y - borrow. The borrow input must be 0 or 1; otherwise the behavior is undefined. The borrowOut output is guaranteed to be 0 or 1.
This function's execution time does not depend on the inputs.
Sub32
fn Sub32(x: u32, y: u32, borrow: u32): (diff: u32, borrowOut: u32)
Returns the difference of x, y and borrow, diff = x - y - borrow. The borrow input must be 0 or 1; otherwise the behavior is undefined. The borrowOut output is guaranteed to be 0 or 1.
This function's execution time does not depend on the inputs.
Sub64
fn Sub64(x: u64, y: u64, borrow: u64): (diff: u64, borrowOut: u64)
Returns the difference of x, y and borrow: diff = x - y - borrow. The borrow input must be 0 or 1; otherwise the behavior is undefined. The borrowOut output is guaranteed to be 0 or 1.
This function's execution time does not depend on the inputs.
Mul
fn Mul(x: uint, y: uint): (hi: uint, lo: uint)
Returns the full-width product of x and y: (hi, lo) = x * y with the product bits' upper half returned in hi and the lower half returned in lo.
This function's execution time does not depend on the inputs.
Mul32
fn Mul32(x: u32, y: u32): (hi: u32, lo: u32)
Returns the 64-bit product of x and y: (hi, lo) = x * y with the product bits' upper half returned in hi and the lower half returned in lo.
This function's execution time does not depend on the inputs.
Mul64
fn Mul64(x: u64, y: u64): (hi: u64, lo: u64)
Returns the 128-bit product of x and y: (hi, lo) = x * y with the product bits' upper half returned in hi and the lower half returned in lo.
This function's execution time does not depend on the inputs.
Div
fn Div(hi: uint, lo: uint, y: uint): (quo: uint, rem: uint)
Returns the quotient and remainder of (hi, lo) divided by y: quo = (hi, lo)/y, rem = (hi, lo)%y with the dividend bits' upper half in parameter hi and the lower half in parameter lo. div panics for y == 0 (division by zero) or y <= hi (quotient overflow).
Div32
fn Div32(hi: u32, lo: u32, y: u32): (quo: u32, rem: u32)
Returns the quotient and remainder of (hi, lo) divided by y: quo = (hi, lo)/y, rem = (hi, lo)%y with the dividend bits' upper half in parameter hi and the lower half in parameter lo. div32 panics for y == 0 (division by zero) or y <= hi (quotient overflow).
Div64
fn Div64(hi: u64, lo: u64, mut y: u64): (quo: u64, rem: u64)
Returns the quotient and remainder of (hi, lo) divided by y: quo = (hi, lo)/y, rem = (hi, lo)%y with the dividend bits' upper half in parameter hi and the lower half in parameter lo. div64 panics for y == 0 (division by zero) or y <= hi (quotient overflow).
Rem
fn Rem(hi: uint, lo: uint, y: uint): uint
Returns the remainder of (hi, lo) divided by y. rem panics for y == 0 (division by zero) but, unlike div, it doesn't panic on a quotient overflow.
Rem32
fn Rem32(hi: u32, lo: u32, y: u32): u32
Returns the remainder of (hi, lo) divided by y. rem32 panics for y == 0 (division by zero) but, unlike div32, it doesn't panic on a quotient overflow.
Rem64
fn Rem64(hi: u64, lo: u64, y: u64): u64
Returns the remainder of (hi, lo) divided by y. rem64 panics for y == 0 (division by zero) but, unlike div64, it doesn't panic on a quotient overflow.