SHFL

System registers, votes, shuffles and barriers

fixed bit field field the encoding fixes should be

SHFL

6362616059585756555453525150494847464544434241403938373635343332
1110111100010[50:48]mask
313029282726252423222120191817161514131211109876543210
modemaskindexindexpred.notpredRaRd

bits 63:48: 1110 1111 0001 0---

Runs execute_SHFL with Form() 0.

Fields

FieldBitsFrom
[50:48]50:48execute_SHFL
mask46:34execute_SHFL
mask46:39execute_SHFL
mode31:30execute_SHFL
mask29execute_SHFL
index28execute_SHFL
index24:20execute_SHFL
pred.not19the decoder
pred18:16the decoder
Ra15:8RegA()
Rd7:0Dst()

Operation Sail

SHFL: PTX's shfl.sync, the lane at 20 (an immediate with bit 28) and c (the mask) at 34 (an immediate with bit 29) or the register at 39: c's bits 8-12 split the lanes into segments, its bits 0-4 clamp the lane. Mode (30-31) 0 IDX, 1 UP, 2 DOWN, 3 BFLY. A quad's operation is the subgroup's own (QuadShfl), and a fragment's lone lane reads its quad through derivatives (ShflQuadLanes)

if QuadShfl() != 0 then {
    let value = SubgroupQuad(R_read(RegA()), if QuadShfl() == 2 then 1 else 0, QuadShflOperand());
    PredWrite(UInt(Field(48, 3)), true);
    R_write(Dst(), value)
} else if QuadShflLanes() then ShflQuadLanes() else {
    let index = if Field(28, 1) == 0b1 then ZeroExtend(Field(20, 5), 32) else R_read(RegB());
    let mask = if Field(29, 1) == 0b1 then ZeroExtend(Field(34, 13), 32) else R_read(UInt(Field(39, 8)));
    let lane_model = LaneModel();
    let lane_full = if lane_model then LoneLane() else SubgroupLane();
    let lane = lane_full & 0x0000001f;
    let seg = (mask >> 8) & 0x0000001f;
    let min_lane = lane & seg;
    let max_lane = min_lane | (mask & (not_vec(seg) & 0x0000001f));
    let mode = UInt(Field(30, 2));
    let source_lane : bits(32) = match mode {
        0 => min_lane | (index & not_vec(seg)),
        1 => lane - index,
        2 => lane + index,
        _ => EOR(lane, index)
    };
    let valid = if mode == 1 then not_bool(UInt(lane - min_lane) < UInt(index))
                else not_bool(UInt(max_lane) < UInt(source_lane));
    let value = R_read(RegA());
    PredWrite(UInt(Field(48, 3)), valid);
    /* the lane model's lane alone: its own value, from its lane or one that runs nothing */
    if lane_model then R_write(Dst(), value) else {
        let host_lane = (lane_full & 0xffffffe0) | (source_lane & 0x0000001f);
        let shuffled = SubgroupShuffle(value, host_lane);
        R_write(Dst(), if valid then shuffled else value)
    }
}

Made from ScarletNX's Sail at 166ad3910f80. The Sail and the encodings' file are ScarletNX's (GPL-3.0-or-later); its encodings are from Eden's maxwell.inc (GPL-2.0-or-later).