VPCK

Moves

fixed bit field field the encoding fixes should be

Encoding

6362616059585756555453525150494847464544434241403938373635343332
01000predskipinvnoschedunknownsyncstartdest_extendsrc1_extsrc2_extrepeat_countsrc_fmtdest_fmtmaskdest_bank
313029282726252423222120191817161514131211109876543210
src1_banksrc2_bankdest_nsel3scalesel1sel2src1_nsel0_bit1src2_nsel0_bit0

bits 63:0: 0100 0xxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx

It is in a group of patterns that may match the same word: the decoder tries them in this order, and the first that matches decodes it: VPCK, VTST, VTSTMSK, VBW.

Runs execute_VPCK with Form() 0.

Fields

FieldBitsThe Sail reads it in
pred58:56
skipinv55
nosched54
unknown53
syncstart52
dest_ext51Bit(51)
end50
src1_ext49Bit(49)
src2_ext48Bit(48)
repeat_count47:44execute_VPCK
src_fmt43:41execute_VPCK
dest_fmt40:38execute_VPCK
mask37:34execute_VPCK
dest_bank33:32execute_VPCK
src1_bank31:30execute_VPCK
src2_bank29:28execute_VPCK
dest_n27:21execute_VPCK
sel320:19execute_VPCK
scale18Bit(18)
sel117:16execute_VPCK
sel215:14execute_VPCK
src1_n13:8execute_VPCK
sel0_bit17Bit(7)
src2_n6:1execute_VPCK
sel0_bit00Bit(0)

Operation Sail

VPCK: src1's components (its swizzle the four selectors) converted from the source format to the destination's, scaled to the formats' ranges with scale; an F32 source reads src1's x and y, then src2's, as one range of four where the selectors or the registers ask it. A repeat at a time

let dest_type = PackType(UInt(Field(38, 3)));
let src_type = PackType(UInt(Field(41, 3)));
let mask = UInt(Field(34, 4));
let scale = Bit(18) == 1;
let src2_n = UInt(Field(1, 6));
Dest(DEST, UInt(Field(21, 7)), UInt(Field(32, 2)), Bit(51), false, 7);
SetType(DEST, dest_type);
let float_src = IsFloatType(src_type);
let float_dest = IsFloatType(dest_type);
let src1_n = if float_src then UInt(Field(8, 6)) else Bit(7) + 2 * UInt(Field(8, 6));
Src12(SRC1, src1_n, UInt(Field(30, 2)), Bit(49), float_src, 7);
Src12(SRC2, src2_n, UInt(Field(28, 2)), Bit(48), true, 7);
SetType(SRC1, src_type);
let sel0 = Bit(0) + 2 * (if src_type == T_F32 then Bit(7) else MOD(src2_n, 2));
let sel1 = UInt(Field(16, 2));
let sel2 = UInt(Field(14, 2));
let sel3 = UInt(Field(19, 2));
SetSwizzle(SRC1, sel0, sel1, sel2, sel3);
let no_cycle = (float_src & float_dest) | (scale & (src_type == T_U8 | dest_type == T_U8));
let use_src2 = if src_type == T_F32 & BankOf(SRC2) != B_IMM then {
    let same = NumOf(SRC1) == NumOf(SRC2) & BankOf(SRC1) == BankOf(SRC2);
    let contiguous = mask == 1 | mask == 3 | mask == 7 | mask == 15;
    let n = Popcount4(mask);
    let defaulted = (n < 1 | sel0 == 0) & (n < 2 | sel1 == 1) & (n < 3 | sel2 == 2) & (n < 4 | sel3 == 3);
    not_bool(defaulted) | not_bool(same) | not_bool(contiguous)
} else false;
/* the selectors cycled over the components the mask enables (two of them, for bytes, when it enables all) */
if not_bool(no_cycle) then {
    let two = (src_type == T_U8 | dest_type == T_U8) & mask == 15;
    let m0 = MOD(mask, 2);
    let m1 = MOD(DIV(mask, 2), 2);
    let m2 = MOD(DIV(mask, 4), 2);
    let n1 = m0;
    let n2 = m0 + m1;
    let n3 = m0 + m1 + m2;
    SetSwizzle(SRC1, if two then sel0 else if m0 == 1 then sel0 else sel0,
               if two then sel1 else if m1 == 1 then (if n1 == 0 then sel0 else sel1) else sel1,
               if two then sel0 else if m2 == 1 then (if n2 == 0 then sel0 else if n2 == 1 then sel1 else sel2)
               else sel2,
               if two then sel1 else if DIV(mask, 8) == 1 then
                   (if n3 == 0 then sel0 else if n3 == 1 then sel1 else if n3 == 2 then sel2 else sel3)
               else sel3)
};
Multiplier(1, if float_src then 2 else 1, if float_src then 2 else 1, 1);
foreach (r from 0 to UInt(Field(44, 4))) {
    if not_bool(Failed()) then {
        let o1 = Rep(SRC1, r, O_SRC1, R_SLMSI);
        let o2 = Rep(SRC2, r, O_SRC2, R_SLMSI);
        if use_src2 then {
            /* the two sources as one range of four: src1's x and y, then src2's */
            CopyOperand(LO, SRC1);
            CopyOperand(HI, SRC2);
            SetSwizzle(LO, SW_X, SW_Y, SW_Z, SW_W);
            SetSwizzle(HI, SW_X, SW_Y, SW_Z, SW_W);
            SetType(HI, src_type);
            Load(LO, LO, 3, o1);
            Load(HI, HI, 3, o2);
            Reset(R, 0, K_FLOAT);
            foreach (i from 0 to 3) {
                if MOD(DIV(mask, 2 ^ i), 2) == 1 then {
                    let ch = ChannelOf(SRC1, i);
                    Push(R, if ch == SW_X then At(LO, 0) else if ch == SW_Y then At(LO, 1)
                            else if ch == SW_Z then At(HI, 0) else if ch == SW_W then At(HI, 1)
                            else ChannelConstant(ch))
                }
            }
        } else Load(R, SRC1, mask, o1);
        if float_dest & not_bool(float_src) then ToFloat(R, src_type, scale);
        if not_bool(float_dest) & float_src then ToInt(R, dest_type, scale);
        if not_bool(float_dest) & not_bool(float_src) & IsSignedType(dest_type) != IsSignedType(src_type) then {
            CopyValue(OLD, R);
            SetKind(R, if IsSignedType(dest_type) then K_INT else K_UINT);
            foreach (i from 0 to Count(OLD) - 1) Put(R, i, At(OLD, i))
        };
        Store(DEST, R, mask, Rep(DEST, r, O_DEST, R_SLMSI))
    }
};
ResetMultiplier()

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 Vita3K's usse_translator_entry.cpp (GPL-2.0-or-later).