SIMD module

get_mask

procedure · 1 overloadSource

Packs which lanes are nonzero into the bits of a number: bit i is set when lane i is not zero (-0.0 counts as zero). Pair it with a comparison to test many lanes at once.

At most 64 lanes are allowed (checked at compile time); with exactly 64 lanes bit 63 is the sign bit, so a full set of lanes reads as -1.

ExampleOpen in playground ↗
v := set(4, cast(s32) 0);
v.data = .[0, 5, 0, 7];
assert(get_mask(v) == 0b1010);
assert(get_mask(v > cast(s32) 6) == 0b1000);
assert(get_mask(set(64, cast(u8) 1)) == -1);
get_mask :: (a: $T/SIMD_Array) -> s64

Packs which lanes are nonzero into the bits of a number: bit i is set when lane i is not zero (-0.0 counts as zero). Pair it with a comparison to test many lanes at once.

At most 64 lanes are allowed (checked at compile time); with exactly 64 lanes bit 63 is the sign bit, so a full set of lanes reads as -1.

Parameters

Returns

s64
ExampleOpen in playground ↗
v := set(4, cast(s32) 0);
v.data = .[0, 5, 0, 7];
assert(get_mask(v) == 0b1010);
assert(get_mask(v > cast(s32) 6) == 0b1000);
assert(get_mask(set(64, cast(u8) 1)) == -1);

See also