silk.simd.mask4.
Operations on mask<4>: four 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#
import silk.simd.mask4
pub fn main() -> i32 {
let flags = mask4.fromArray([false, true, false, true])
if mask4.count(flags) != 2 || mask4.firstSet(flags) != 1 || mask4.toBits(flags) != 10 {
return 1
}
return 0
}Import as mask4 with import silk.simd.mask4 as mask4.
Public declarations: 12.
LANES#
pub const LANES: usizeThe number of lanes in a mask.
splat#
pub fn splat(set: bool) -> mask<4>Returns a mask with every lane set when set is true, and every lane clear otherwise.
fromArray#
pub fn fromArray(lanes: [bool; 4]) -> mask<4>Returns a mask whose lane i is set when lanes[i] is true.
toArray#
pub fn toArray(mask: mask<4>) -> [bool; 4]Returns the lanes of mask as an array, in lane order.
extract#
pub fn extract(mask: mask<4>, index: usize) -> boolReturns whether lane index of mask is set. Traps when index is LANES or more.
insert#
pub fn insert(mask: mask<4>, index: usize, set: bool) -> mask<4>Returns mask with lane index set when set is true and clear otherwise. Traps when index is
LANES or more.
any#
pub fn any(mask: mask<4>) -> boolReturns whether at least one lane is set.
all#
pub fn all(mask: mask<4>) -> boolReturns whether every lane is set.
count#
pub fn count(mask: mask<4>) -> usizeReturns the number of set lanes.
firstSet#
pub fn firstSet(mask: mask<4>) -> usizeReturns the index of the lowest set lane, or LANES when no lane is set.
toBits#
pub fn toBits(mask: mask<4>) -> u64Returns the lanes as bits: bit i is set when lane i is set. Bits from LANES up are zero.
fromBits#
pub fn fromBits(bits: u64) -> mask<4>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.