VSHR

Integer, logic, video and predicate instructions

fixed bit field field the encoding fixes should be

VSHR

6362616059585756555453525150494847464544434241403938373635343332
01010110
313029282726252423222120191817161514131211109876543210
pred.notpredRaRd

bits 63:48: 0101 0110 ---- ----

Runs execute_VIDEO with Form() 4.

Fields

The operation reads some of these fields in some forms alone (it chooses by Form()), so the diagrams show only the decoder's.

FieldBitsFrom
mode57:56execute_VIDEO
compare56:54execute_VIDEO
[55]55execute_VIDEO
[54]54execute_VIDEO
[53:51]53:51execute_VIDEO
right50execute_VIDEO
bsel49execute_VIDEO
asel48execute_VIDEO
[46:39]46:39execute_VIDEO
asel38:36execute_VIDEO
[35:20]35:20execute_VIDEO
bsel30:28execute_VIDEO
pred.not19the decoder
pred18:16the decoder
Ra15:8RegA()
Rd7:0Dst()

Operation Sail

VADD, VABSDIFF, VSET, VSHL and VSHR: Ryujinx's decoding and PTX's semantics: A's and B's selects at 36 and 28 with their signs at 48 and 49 (the shifts' B is unsigned, and bit 49 wraps their count), B a 16-bit immediate when bit 50 is clear, a signed destination at 54 and saturate at 55 (VSET's comparison is there instead), the secondary operation at 51-53, and VADD's negation/plus-one mode at 56-57

let op = Form(); /* 0 VADD, 1 VABSDIFF, 2 VSET, 3 VSHL, 4 VSHR */
let shift = op >= 3;
let asel = UInt(Field(36, 3)) + 8 * UInt(Field(48, 1));
let bsel = UInt(Field(28, 3)) + (if shift then 0 else 8 * UInt(Field(49, 1)));
let left = VideoOperand(R_read(RegA()), asel);
let right = if Field(50, 1) == 0b1 then VideoOperand(R_read(RegB()), bsel)
            else VideoOperand(Bits32(ZeroExtend(Field(20, 16), 32)), 4 + 8 * DIV(bsel, 8));
let zero64 = I64Const(0);
let one64 = I64Const(1);
let result : i64 = if op == 0 then {
    let mode = UInt(Field(56, 2));
    let r = if mode == 1 then I64Sub(left, right) else if mode == 2 then I64Sub(right, left) else I64Add(left, right);
    if mode == 3 then I64Add(r, one64) else r
} else if op == 1 then {
    let difference = I64Sub(left, right);
    I64Select(I64Greater(zero64, difference), I64Sub(zero64, difference), difference)
} else if op == 2 then {
    let compare = UInt(Field(54, 3));
    let less = I64Greater(right, left);
    let greater = I64Greater(left, right);
    let equal = I64Equal(left, right);
    let test = match compare {
        0 => false, 1 => less, 2 => equal, 3 => not_bool(greater), 4 => greater, 5 => not_bool(equal),
        6 => not_bool(less), _ => true
    };
    I64Select(test, one64, zero64)
} else {
    /* the count wraps to 5 bits (bit 49) or clamps at 32; VSHR fills with A's sign when A is signed */
    let count = if Field(49, 1) == 0b1 then I64And(right, I64Const(31))
                else I64Select(I64Greater(right, I64Const(32)), I64Const(32), right);
    if op == 3 then I64Shl(left, count) else if Field(48, 1) == 0b1 then I64Sar(left, count) else I64Shr(left, count)
};
R_write(Dst(), VideoFinish(result, R_read(UInt(Field(39, 8))), UInt(Field(51, 3)),
                           if op != 2 then UInt(Field(55, 1)) else 0, if op != 2 then UInt(Field(54, 1)) else 0,
                           if op == 3 & Field(48, 1) == 0b0 then 1 else 0))

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).