subgroupShuffleXor
Within the same subgroup, returns the value v from a target invocation (lane) determined by the bitwise XOR (^) of mask and the current subgroup_invocation_id. Signature: subgroupShuffleXor(v, mask).
Core Advantages
Enables cross-invocation data exchange without shared memory or synchronization barriers. Naturally suited to parallel patterns such as butterfly communication, reduction, and scan. TSL wraps it as a 2-parameter function node for type safety and high readability.
Common Uses
Neighbor-thread exchange (mask=1u) for edge-to-edge interactions or paired computations.
Butterfly reduction / prefix-sum: use mask values 1u, 2u, 4u, … for logarithmic-stride communication.
Lane permutation within a subgroup or selective broadcasting of a subset of data.
Parallel communication phases that require XOR pairing, e.g., FFT / bit-reversal stages.
How to adjust
Select mask bit positions to choose the target invocation: 1u flips the least-significant bit (pairs with the adjacent lane), 2u flips the next bit, 4u flips the third bit, and so on. This constructs butterfly / logarithmic-stride parallel patterns. Note: only effective when subgroup features are enabled in the backend; unavailable on unsupported platforms.
Code Examples
1// 1) Neighbor exchange (mask=1u)
2const neighbor = subgroupShuffleXor( value, 1u );
3const pairSum = value.add( neighbor );
4
5// 2) Butterfly reduction (illustrative)
6let s = value;
7s = s.add( subgroupShuffleXor( s, 1u ) );
8s = s.add( subgroupShuffleXor( s, 2u ) );
9s = s.add( subgroupShuffleXor( s, 4u ) );