Skip to content

Shuffle primitive

Shuffle reads a register value from another lane in the same wave. It supports reductions, scans, broadcasts, and sorting without a local-memory round trip.

wave_shuffle r0, r1, r2

Each active lane reads r1 from the lane selected by its own r2, then writes the result to its own r0.

InstructionSource lane
wave_shuffleLane index in the operand register
wave_shuffle_upCurrent lane minus the offset
wave_shuffle_downCurrent lane plus the offset
wave_shuffle_xorCurrent lane XOR the mask
wave_broadcastShared source lane

The specification defines active-lane and source-lane requirements. Shuffle is a mandatory wave operation.

BackendOperations
Metalsimd_shuffle, simd_shuffle_up, simd_shuffle_down, simd_shuffle_xor
PTXshfl.sync variants
HIP__shfl, __shfl_up, __shfl_down, __shfl_xor
SYCLselect_from_group, group shifts, permute_group_by_xor

The emulator gathers source values before writing destinations. This preserves cross-lane reads when source and destination registers overlap. A 64-element stack buffer holds the results for the supported wave widths.