Browse the docs

silk.simd.mask32.

Operations on mask<32>: thirty-two lanes that are each set or clear.

When to use#

A lane comparison in a vector module returns a mask. Use any or all to branch on it, firstSet to find the first matching lane, and toBits to process every set lane.

Details#

The operators &, |, ^, ~ and ! apply lane by lane. == is true only when every lane is equal. In toBits, lane i is bit i.

Examples#

Count and locate set lanes#

silk
import silk.simd.mask32

pub fn main() -> i32 {
  let flags = mask32.fromArray([false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true])
  if mask32.count(flags) != 16 || mask32.firstSet(flags) != 1 || mask32.toBits(flags) != 2863311530 {
    return 1
  }
  return 0
}

Import as mask32 with import silk.simd.mask32 as mask32.

Public declarations: 12.

LANES#

silk
pub const LANES: usize

The number of lanes in a mask.

splat#

silk
pub fn splat(set: bool) -> mask<32>

Returns a mask with every lane set when set is true, and every lane clear otherwise.

fromArray#

silk
pub fn fromArray(lanes: [bool; 32]) -> mask<32>

Returns a mask whose lane i is set when lanes[i] is true.

toArray#

silk
pub fn toArray(mask: mask<32>) -> [bool; 32]

Returns the lanes of mask as an array, in lane order.

extract#

silk
pub fn extract(mask: mask<32>, index: usize) -> bool

Returns whether lane index of mask is set. Traps when index is LANES or more.

insert#

silk
pub fn insert(mask: mask<32>, index: usize, set: bool) -> mask<32>

Returns mask with lane index set when set is true and clear otherwise. Traps when index is LANES or more.

any#

silk
pub fn any(mask: mask<32>) -> bool

Returns whether at least one lane is set.

all#

silk
pub fn all(mask: mask<32>) -> bool

Returns whether every lane is set.

count#

silk
pub fn count(mask: mask<32>) -> usize

Returns the number of set lanes.

firstSet#

silk
pub fn firstSet(mask: mask<32>) -> usize

Returns the index of the lowest set lane, or LANES when no lane is set.

toBits#

silk
pub fn toBits(mask: mask<32>) -> u64

Returns the lanes as bits: bit i is set when lane i is set. Bits from LANES up are zero.

fromBits#

silk
pub fn fromBits(bits: u64) -> mask<32>

Returns a mask whose lane i is set when bit i of bits is set. Bits from LANES up are ignored.

Category: SIMD.

Profiles: aarch64-apple-darwin, aarch64-unknown-linux-gnu, aarch64-unknown-linux-gnu-no-libc, x86_64-unknown-linux-gnu, x86_64-unknown-linux-gnu-no-libc, wasm32-unknown-unknown, wasm32-wasip1, wasm32-wasip2.

View the source of this page