SIMD module

load_from_offsets

procedure · 1 overloadSource

Gathers one F per lane from base + offsets.data[i], where each offset is a signed byte displacement (not an element index), and returns them in lane order. The result has as many lanes as offsets, whose lane type can be any integer type.

Equal offsets repeat a value; negative ones reach below base. Nothing is bounds-checked; a null base fails an assert.

ExampleOpen in playground ↗
numbers: [4] s32 = .[10, 20, 30, 40];
offsets := set(3, cast(s64) 0);
offsets.data = .[12, 0, 4]; // byte offsets: 3 * size_of(s32), 0, 1 * size_of(s32)
v := load_from_offsets(numbers.data, offsets, s32);
assert(v.data[0] == 40 && v.data[1] == 10 && v.data[2] == 20);
load_from_offsets :: (
    base: *void,
    offsets: $O/SIMD_Array,
    $F: Type
) -> SIMD_Array(offsets.count, F)

Gathers one F per lane from base + offsets.data[i], where each offset is a signed byte displacement (not an element index), and returns them in lane order. The result has as many lanes as offsets, whose lane type can be any integer type.

Equal offsets repeat a value; negative ones reach below base. Nothing is bounds-checked; a null base fails an assert.

Parameters

base: *void
offsets: $O/SIMD_Array
$F: Type

Returns

SIMD_Array(offsets.count, F)
ExampleOpen in playground ↗
numbers: [4] s32 = .[10, 20, 30, 40];
offsets := set(3, cast(s64) 0);
offsets.data = .[12, 0, 4]; // byte offsets: 3 * size_of(s32), 0, 1 * size_of(s32)
v := load_from_offsets(numbers.data, offsets, s32);
assert(v.data[0] == 40 && v.data[1] == 10 && v.data[2] == 20);

See also