SOP2

Integer and 8-bit color instructions

fixed bit field field the encoding fixes should be

Encoding

6362616059585756555453525150494847464544434241403938373635343332
10000predcmod1skipinvnoschedasel1dest_extendsrc1_extsrc2_extcmod2countamod1asel2csel1csel2amod2dest_bank
313029282726252423222120191817161514131211109876543210
src1_banksrc2_bankdest_nsrc1_modcopaopasrc1_moddest_modsrc1_nsrc2_n

bits 63:0: 1000 0xxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx

Runs execute_SOP2 with Form() 0.

Fields

FieldBitsThe Sail reads it in
pred58:57
cmod156Bit(56)
skipinv55
nosched54
asel153:52execute_SOP2
dest_ext51Bit(51)
end50
src1_ext49Bit(49)
src2_ext48Bit(48)
cmod247Bit(47)
count46:44execute_SOP2
amod143Bit(43)
asel242:41execute_SOP2
csel140:38execute_SOP2
csel237:35execute_SOP2
amod234Bit(34)
dest_bank33:32execute_SOP2
src1_bank31:30execute_SOP2
src2_bank29:28execute_SOP2
dest_n27:21execute_SOP2
src1_mod20Bit(20)
cop19:18execute_SOP2
aop17:16execute_SOP2
asrc1_mod15
dest_mod14
src1_n13:7execute_SOP2
src2_n6:0execute_SOP2

Operation Sail

SOP2: each source's color (xyz) and alpha (w) as unsigned bytes, each scaled by the factor its selector names (0, src1's color, src2's color, src1's alpha, src2's alpha; complemented by its modifier), then added, subtracted or the min or max (cop for the color, aop for the alpha). A repeat at a time

let csel1 = UInt(Field(38, 3));
let csel2 = UInt(Field(35, 3));
let asel1 = UInt(Field(52, 2));
let asel2 = UInt(Field(41, 2));
if csel1 > 4 | csel2 > 4 | asel1 > 2 | asel2 > 2 then
    throw(Refuse("SOP2 selectors %u %u %u %u", csel1, csel2, asel1, asel2));
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);
Dest(DEST, UInt(Field(21, 7)), UInt(Field(32, 2)), Bit(51), 0, 7);
SetType(SRC1, T_U8);
SetType(SRC2, T_U8);
SetType(DEST, T_U8);
let mod1 = Bit(20);
foreach (r from 0 to UInt(Field(44, 3))) {
    if not_bool(Failed()) then {
        let o1 = Rep(SRC1, r, O_SRC1, R_SLMSI);
        let o2 = Rep(SRC2, r, O_SRC2, R_SLMSI);
        Load(C1, SRC1, 7, o1);
        ToFloat(C1, T_U8, 1);
        Load(C2, SRC2, 7, o2);
        ToFloat(C2, T_U8, 1);
        Load(A1, SRC1, 8, o1);
        ToFloat(A1, T_U8, 1);
        Load(A2, SRC2, 8, o2);
        ToFloat(A2, T_U8, 1);
        if not_bool(Failed()) then {
            foreach (i from 0 to 2) Put(C1, i, Complement(At(C1, i), mod1));
            Put(A1, 0, Complement(At(A1, 0), mod1));
            Reset(COLOR, 3, K_FLOAT);
            foreach (i from 0 to 2) {
                let zero = Zero();
                let c1 = At(C1, i);
                let c2 = At(C2, i);
                let pick1 = match csel1 { 0 => zero, 1 => c1, 2 => c2, 3 => At(A1, 0), _ => At(A2, 0) };
                let pick2 = match csel2 { 0 => zero, 1 => c1, 2 => c2, 3 => At(A1, 0), _ => At(A2, 0) };
                let lhs = FMul(Complement(pick1, Bit(56)), c1);
                let rhs = FMul(Complement(pick2, Bit(47)), c2);
                Put(COLOR, i, SopApply(UInt(Field(18, 2)), lhs, rhs))
            };
            let zero = Zero();
            let a1 = At(A1, 0);
            let a2 = At(A2, 0);
            let pick1 = match asel1 { 0 => zero, 1 => a1, _ => a2 };
            let pick2 = match asel2 { 0 => zero, 1 => a1, _ => a2 };
            let lhs = FMul(Complement(pick1, Bit(43)), a1);
            let rhs = FMul(Complement(pick2, Bit(34)), a2);
            Reset(ALPHA, 1, K_FLOAT);
            Put(ALPHA, 0, SopApply(UInt(Field(16, 2)), lhs, rhs));
            let od = Rep(DEST, r, O_DEST, R_SLMSI);
            ToInt(COLOR, T_U8, 1);
            Store(DEST, COLOR, 7, od);
            ToInt(ALPHA, T_U8, 1);
            Store(DEST, ALPHA, 8, od)
        }
    }
}

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