SIMD module

horizontal_add

procedure · 1 overloadSource

Adds neighbouring lane pairs of a and of b and interleaves the sums: the result is [a0 + a1, b0 + b1, a2 + a3, b2 + b3, ...]. The lane count must be even (checked at compile time).

ExampleOpen in playground ↗
a := set(4, cast(s32) 0);
b := set(4, cast(s32) 0);
a.data = .[1, 2, 3, 4];
b.data = .[10, 20, 30, 40];
r := horizontal_add(a, b);
assert(r.data[0] == 3 && r.data[1] == 30 && r.data[2] == 7 && r.data[3] == 70);
horizontal_add :: (a: $T/SIMD_Array, b: T) -> interleaved_result: T

Adds neighbouring lane pairs of a and of b and interleaves the sums: the result is [a0 + a1, b0 + b1, a2 + a3, b2 + b3, ...]. The lane count must be even (checked at compile time).

Parameters

b: T

Returns

interleaved_result: T
ExampleOpen in playground ↗
a := set(4, cast(s32) 0);
b := set(4, cast(s32) 0);
a.data = .[1, 2, 3, 4];
b.data = .[10, 20, 30, 40];
r := horizontal_add(a, b);
assert(r.data[0] == 3 && r.data[1] == 30 && r.data[2] == 7 && r.data[3] == 70);

See also