VLDST

Loads, texture reads and special instructions

fixed bit field field the encoding fixes should be

Encoding

6362616059585756555453525150494847464544434241403938373635343332
111oppredskipinvnoschedmoe_expandsyncstartcache_extsrc0_extsrc1_extsrc2_extmask_countaddr_modemodeprimattrrange_enabledata_typeinc_or_decsrc0_bankcache_bypassdrc_sel
313029282726252423222120191817161514131211109876543210
src1_banksrc2_bankdest_nsrc0_nsrc1_nsrc2_n

bits 63:0: 111x xxxx 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: SMP, PHAS, NOP, BR, SMLSI, SMBO, KILL, LIMM, DEPTHF, SPEC, VLDST.

Runs execute_VLDST with Form() 0.

Fields

FieldBitsThe Sail reads it in
op60:59execute_VLDST
pred58:56
skipinv55
nosched54
moe_expand53Bit(53)
syncstart52
cache_ext51
src0_ext50Bit(50)
src1_ext49Bit(49)
src2_ext48Bit(48)
mask_count47:44execute_VLDST
addr_mode43:42
mode41:40
primattr39Bit(39)
range_enable38
data_type37:36execute_VLDST
inc_or_dec35
src0_bank34Bit(34)
cache_bypass33
drc_sel32
src1_bank31:30execute_VLDST
src2_bank29:28execute_VLDST
dest_n27:21execute_VLDST
src0_n20:14execute_VLDST
src1_n13:7execute_VLDST
src2_n6:0execute_VLDST

Operation Sail

VLDST: words loaded from a uniform buffer read from memory, at src0 + src1 (+ 4 without moe expansion) + src2 bytes, src0 a register the program's uniform buffer table filled; or from the literal buffer, at a register's offset from its array, else (constant offsets, one word) from the program's bytes

let op = UInt(Field(59, 2));
if op == 2 then throw(Refuse("VLDST stores"));
if op != 1 then throw(Refuse("VLDST operation %u", op));
let data_type = UInt(Field(36, 2));
if data_type > 2 then throw(Refuse("VLDST of data type %u", data_type));
let size = if data_type == 0 then 4 else if data_type == 1 then 2 else 1;
let bytes = size * (UInt(Field(44, 4)) + 1);
Src0(SRC0, UInt(Field(14, 7)), Bit(34), Bit(50), 0, 7);
Src12(SRC1, UInt(Field(7, 7)), UInt(Field(30, 2)), Bit(49), 0, 7);
Src12(SRC2, UInt(Field(0, 7)), UInt(Field(28, 2)), Bit(48), 0, 7);
SetType(SRC0, T_I32);
SetType(SRC1, T_I32);
SetType(SRC2, T_I32);
let bank = if Secondary() then B_SA else if Bit(39) == 1 then B_PA else B_TEMP;
if BankOf(SRC1) == B_IMM then SetNum(SRC1, NumOf(SRC1) * size);
let dest = UInt(Field(21, 7));
if BankOf(SRC0) == B_SA & NumOf(SRC0) == LiteralRegister() then {
    if UInt(Field(44, 4)) != 0 | BankOf(SRC1) != B_IMM | BankOf(SRC2) != B_IMM then {
        /* at a register's offset: from the array */
        if not_bool(HasLiterals()) then throw(Refuse("a literal buffer read past the program"));
        Load(A, SRC1, 1, 0);
        Load(B, SRC2, 1, 0);
        if Failed() then throw(Stop());
        let b1 = if BankOf(SRC1) != B_IMM then ISubT(At(A, 0), SConst(65536)) else At(A, 0);
        let offset = IAddT(SConst(LiteralBase()), IAddT(b1, At(B, 0)));
        let first = ShrT(AsU32(offset), UConst(2));
        LiteralsBegin();
        foreach (i from 0 to DIV(bytes, 4) - 1) WordStore(bank, dest + i, LiteralRead(IAddT(first, UConst(i))))
    } else {
        let offset = LiteralBase() + NumOf(SRC1) + NumOf(SRC2);
        if not_bool(LiteralFits(offset)) then throw(Refuse("a literal past the program"));
        WordStore(bank, dest, UConst(LiteralData(offset)))
    }
} else {
    if not_bool(HasBuffer()) then throw(Refuse("a VLDST with no uniform buffer"));
    Load(A, SRC0, 1, 0);
    Load(B, SRC1, 1, 0);
    Load(C, SRC2, 1, 0);
    if Failed() then throw(Stop());
    let a1 = if BankOf(SRC1) != B_IMM then ISubT(At(B, 0), SConst(65536)) else At(B, 0);
    let a2 = if Bit(53) == 0 then IAddT(a1, SConst(4)) else a1;
    let address = AsU32(IAddT(At(A, 0), IAddT(a2, At(C, 0))));
    let index = ShrT(address, UConst(2));
    BufferBegin();
    foreach (i from 0 to DIV(bytes, 4) - 1) WordStore(bank, dest + i, BufferRead(IAddT(index, UConst(i))))
}

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