Skip to main content
Log in

Mojo function

scatter

scatter[type: DType, size: Int, //](value: SIMD[type, size], owned base: SIMD[index, size], mask: SIMD[bool, size], alignment: Int = 0)

Takes scalar values from a SIMD vector and scatters them into a vector of pointers.

The scatter operation stores scalar values from a SIMD vector of memory locations and scatters them into a vector of pointers. The memory locations are provided in the vector of pointers base as addresses. The memory is stored 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 value operand is a vector value to be written to memory. The base operand is a vector of pointers, pointing to where the value elements should be stored. It has the same underlying type as the value operand. The mask operand, mask, is a vector of boolean values. The types of the mask and the value operand must have the same number of vector elements.

Scatter with overlapping addresses is guaranteed to be ordered from least-significant to most-significant element.

In general, for some vector %value, vector of pointers %base, and mask %mask instructions of the form:

%0 = pop.simd.scatter %value, %base[%mask] : !pop.simd<N, type>
%0 = pop.simd.scatter %value, %base[%mask] : !pop.simd<N, type>

is equivalent to the following sequence of scalar loads in C++:

for (int i = 0; i < N; i++)
if (mask[i])
base[i] = value[i];
for (int i = 0; i < N; i++)
if (mask[i])
base[i] = value[i];

Parameters:

  • type (DType): DType of value, the result SIMD buffer.
  • size (Int): Size of value, the result SIMD buffer.

Args:

  • value (SIMD[type, size]): The vector that will contain the result of the scatter operation.
  • base (SIMD[index, size]): The vector containing memory addresses that scatter will access.
  • mask (SIMD[bool, size]): A binary vector which prevents memory access to certain lanes of the base vector.
  • alignment (Int): The alignment of the source addresses. Must be 0 or a power of two constant integer value.