Mojo function
gather
gather[type: DType, size: Int, //](owned base: SIMD[index, size], mask: SIMD[bool, size], passthrough: SIMD[type, size], alignment: Int = 0) -> SIMD[$0, $1]
Reads scalar values from a SIMD vector, and gathers them into one vector.
The gather function reads scalar values from a SIMD vector of memory
locations and gathers them into one vector. The memory locations are
provided in the vector of pointers base
as addresses. The memory is
accessed according to the provided mask. The mask holds a bit for each
vector lane, and is used to prevent memory accesses to the masked-off
lanes. The masked-off lanes in the result vector are taken from the
corresponding lanes of the passthrough
operand.
In general, for some vector of pointers base
, mask mask
, and passthrough
pass
a call of the form:
gather(base, mask, pass)
gather(base, mask, pass)
is equivalent to the following sequence of scalar loads in C++:
for (int i = 0; i < N; i++)
result[i] = mask[i] ? *base[i] : passthrough[i];
for (int i = 0; i < N; i++)
result[i] = mask[i] ? *base[i] : passthrough[i];
Parameters:
- type (
DType
): DType of the return SIMD buffer. - size (
Int
): Size of the return SIMD buffer.
Args:
- base (
SIMD[index, size]
): The vector containing memory addresses that gather will access. - mask (
SIMD[bool, size]
): A binary vector which prevents memory access to certain lanes of the base vector. - passthrough (
SIMD[type, size]
): In the result vector, the masked-off lanes are replaced with the passthrough vector. - alignment (
Int
): The alignment of the source addresses. Must be 0 or a power of two constant integer value.
Returns:
A SIMD[type, size] containing the result of the gather operation.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!
😔 What went wrong?