diff --git a/CHANGELOG.md b/CHANGELOG.md index 992036a..7db429f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ Guest execution uses original, purpose-built test programs. Commercial Xbox game remains unsupported. ### Changed +- Moved gfx1030 `s_mov_b32` (SOP1) into the semantic registry, preserving its existing decode domain and shader output. The move operand rule retains explicit VCC and EXEC half destinations. Part of #215. - Moved the six hand-written gfx1030 VOP2 logical and shift forms (`v_and_b32`, `v_or_b32`, `v_xor_b32`, `v_lshlrev_b32`, `v_lshrrev_b32`, `v_ashrrev_i32`, AMD guide section 12.7) into the semantic registry under a new VGPR-only operand rule `vop2_vgpr2`, with no behaviour change: a sweep of 132,608 VOP2, VOP1 and SOP1 words decodes to the same text, length and error before and after, the MSL goldens are unchanged, and the runtime-region allowlist admits exactly the same six forms. The per-lane `VectorBinary` gained `And`, `Or`, `Xor` and the three shifts (count masked to S0[4:0]); 6 hand-written instruction variants and their decoder and lowering arms are gone (17 hand-written forms remain). Part of #215. - Added non-blocking Metal compute submission through `submit_words` and `wait`, with completion-aware resource retirement and a sixteen-dispatch in-flight limit. Synchronous calls keep their existing behavior. The benchmark reports the host submission split and compares synchronous and pipelined batches. - Extended the read-only RDNA2 planning CLI (`python3 -m qa rdna2`) with family/status filters, compact summaries, Codex-ready manifests under `artifacts/`, active-claim exclusion (family claims exclude those families; path-only claims block overlapping permitted files), coverage reconcile against `semantic_coverage` without inflating counts, and inventory diffs. Covered by `tests/qa/test_rdna2_plan.py`; planning only, no GPU production edits. diff --git a/crates/decoder/src/lib.rs b/crates/decoder/src/lib.rs index 16ce957..cc16295 100644 --- a/crates/decoder/src/lib.rs +++ b/crates/decoder/src/lib.rs @@ -9,7 +9,7 @@ pub use xenora_isa::{ }; use xenora_isa::{ BUFFER_LOAD_DWORD, BUFFER_STORE_DWORD, EXP, IMAGE_SAMPLE_LZ, S_BRANCH, S_CBRANCH_EXECZ, - S_CBRANCH_SCC0, S_CBRANCH_VCCZ, S_ENDPGM, S_MOV_B32, S_WAITCNT, S_WAITCNT_VSCNT, V_ADD_F32, + S_CBRANCH_SCC0, S_CBRANCH_VCCZ, S_ENDPGM, S_WAITCNT, S_WAITCNT_VSCNT, V_ADD_F32, V_INTERP_P1_F32, V_INTERP_P2_F32, V_MOV_B32, V_MUL_F32, VCC_LO, }; @@ -40,7 +40,7 @@ const fn concat_forms() -> [(&'static str, EncodingFamily); N] { } /// Decoded forms not yet described by the semantic registry. -const HANDWRITTEN_FORMS: [(&str, EncodingFamily); 17] = [ +const HANDWRITTEN_FORMS: [(&str, EncodingFamily); 16] = [ ("BUFFER_LOAD_DWORD", EncodingFamily::Mubuf), ("BUFFER_STORE_DWORD", EncodingFamily::Mubuf), ("EXP", EncodingFamily::Exp), @@ -50,7 +50,6 @@ const HANDWRITTEN_FORMS: [(&str, EncodingFamily); 17] = [ ("S_CBRANCH_SCC0", EncodingFamily::Sopp), ("S_CBRANCH_VCCZ", EncodingFamily::Sopp), ("S_ENDPGM", EncodingFamily::Sopp), - ("S_MOV_B32", EncodingFamily::Sop1), ("S_WAITCNT", EncodingFamily::Sopp), ("S_WAITCNT_VSCNT", EncodingFamily::Sopk), ("V_ADD_F32", EncodingFamily::Vop2), @@ -324,23 +323,21 @@ fn decode_gfx1030(bytes: &[u8], offset: usize) -> Result<(Instruction, u8), Deco let second = word(bytes, 8)?; return Ok((vop3_vgpr2(op, first, second)?, 8)); } - if S_MOV_B32.matches(first) { - let dst = ((first >> 16) & 0x7f) as u8; - if !matches!(dst, 0..=107 | 126..=127) { - return Err(unsupported( - "s_mov_b32", - "expected a normal SGPR or EXEC/VCC destination", - )); - } - let (src, len) = scalar_source(first as u8, bytes, "s_mov_b32")?; - return Ok((Instruction::ScalarMoveB32 { dst, src }, len)); - } if let Some(op) = ScalarUnaryOp::from_word(first) { // SOP1: SSRC0 in bits 0-7, SDST in bits 16-22. let mnemonic = op.mnemonic(); let dst = ((first >> 16) & 0x7f) as u8; - if dst > 105 { - return Err(unsupported(mnemonic, "expected a normal SGPR destination")); + match op.semantics().operands { + OperandRule::Sop1Move if !matches!(dst, 0..=107 | 126..=127) => { + return Err(unsupported( + mnemonic, + "expected a normal SGPR or EXEC/VCC destination", + )); + } + OperandRule::Sop1Sgpr if dst > 105 => { + return Err(unsupported(mnemonic, "expected a normal SGPR destination")); + } + _ => {} } let (src, len) = scalar_source(first as u8, bytes, mnemonic)?; return Ok((Instruction::ScalarUnary { op, dst, src }, len)); diff --git a/crates/decoder/tests/gfx1030.rs b/crates/decoder/tests/gfx1030.rs index 1c9ee88..a101cac 100644 --- a/crates/decoder/tests/gfx1030.rs +++ b/crates/decoder/tests/gfx1030.rs @@ -382,9 +382,10 @@ fn reference_op(instruction: Instruction) -> Op { src0, src1, } => Op::Add(dst, src0, src1), - Instruction::ScalarMoveB32 { dst, src } => Op::ScalarMove(dst, reference_scalar(src)), - Instruction::ScalarUnary { op, dst, src } => Op::ScalarUnary( - match op { + Instruction::ScalarUnary { op, dst, src } => { + let src = reference_scalar(src); + let unary = match op { + ScalarUnaryOp::MovB32 => return Op::ScalarMove(dst, src), ScalarUnaryOp::NotB32 => ScalarUnary::Not, ScalarUnaryOp::BrevB32 => ScalarUnary::ReverseBits, ScalarUnaryOp::Bcnt0I32B32 => ScalarUnary::CountZeros, @@ -396,10 +397,9 @@ fn reference_op(instruction: Instruction) -> Op { ScalarUnaryOp::SextI32I8 => ScalarUnary::SignExtendByte, ScalarUnaryOp::SextI32I16 => ScalarUnary::SignExtendShort, ScalarUnaryOp::AbsI32 => ScalarUnary::Absolute, - }, - dst, - reference_scalar(src), - ), + }; + Op::ScalarUnary(unary, dst, src) + } Instruction::ScalarCompare { op, src0, src1 } => { let (src0, src1) = (reference_scalar(src0), reference_scalar(src1)); // The reference keeps CompareEqual for EQ and uses its VOPC relation @@ -991,14 +991,16 @@ fn decodes_inline_negative_and_register_sources() { let decoded = decode(Architecture::Gfx1030, &bytes).unwrap(); assert_eq!( decoded[0].instruction, - Instruction::ScalarMoveB32 { + Instruction::ScalarUnary { + op: ScalarUnaryOp::MovB32, dst: 10, src: ScalarSource::Immediate(5) } ); assert_eq!( decoded[1].instruction, - Instruction::ScalarMoveB32 { + Instruction::ScalarUnary { + op: ScalarUnaryOp::MovB32, dst: 11, src: ScalarSource::Immediate(0xffff_fffd) } @@ -1032,7 +1034,8 @@ fn accepts_scalar_destination_105_and_vgpr_zero_add_sources() { let valid = 0xbee9_0380u32.to_le_bytes(); assert_eq!( decode(Architecture::Gfx1030, &valid).unwrap()[0].instruction, - Instruction::ScalarMoveB32 { + Instruction::ScalarUnary { + op: ScalarUnaryOp::MovB32, dst: 105, src: ScalarSource::Immediate(0) } diff --git a/crates/isa/generate_semantics.py b/crates/isa/generate_semantics.py index 1e32c6c..926543c 100755 --- a/crates/isa/generate_semantics.py +++ b/crates/isa/generate_semantics.py @@ -184,6 +184,7 @@ PRIMITIVES = { ("lshl", "bitwise"): ("nonzero", "lshl_nonzero_b32", False), ("lshr", "unsigned"): ("nonzero", "lshr_nonzero_b32", False), ("ashr", "signed"): ("nonzero", "ashr_nonzero_i32", False), + ("mov", "bitwise"): ("unchanged", "mov_b32", False), ("not", "bitwise"): ("nonzero", "not_nonzero_b32", False), ("brev", "bitwise"): ("unchanged", "brev_b32", False), ("bcnt0", "bitwise"): ("nonzero", "bcnt0_nonzero_b32", False), @@ -303,6 +304,18 @@ OPERAND_RULES = { "unsupported": {combo for combo in UNSUPPORTED_COMBOS if combo != "two_literals"}, "kind": "unary", }, + "sop1_move": { + "rust": "Sop1Move", + "enum": "ScalarUnaryOp", + "shape": { + "family": "SOP1", + "dst": {"field": "SDST", "class": "sgpr_or_vcc_exec"}, + "src": [{"field": "SSRC0", "class": "scalar_source"}], + "max_literals": 1, + }, + "unsupported": UNSUPPORTED_COMBOS - {"two_literals", "dst_vcc", "dst_exec"}, + "kind": "unary", + }, "sopk_sgpr": { "rust": "SopkSgpr", "enum": "ScalarImmediateOp", @@ -839,7 +852,9 @@ def validate(registry, snapshot): elif form["operands"] in OPERAND_RULES and OPERAND_RULES[form["operands"]]["kind"] != ( (_rule_kind(form) if _rule_kind(form) in ("vector_compare", "immediate_compare") else "compare") if form["operation"] == "compare" - else "unary" if form["operation"] in UNARY + else "unary" if form["operation"] in UNARY or ( + form["operation"] == "mov" and form["family"] == "SOP1" + ) else "vector" if _rule_kind(form) == "vector" and form["operation"] not in UNARY else "immediate" if _rule_kind(form) == "immediate" else "alu" diff --git a/crates/isa/semantics/rdna2/sop1.toml b/crates/isa/semantics/rdna2/sop1.toml index ec7b75a..64f93a7 100644 --- a/crates/isa/semantics/rdna2/sop1.toml +++ b/crates/isa/semantics/rdna2/sop1.toml @@ -15,6 +15,38 @@ unsupported = [ "src_vcc", "src_exec", "src_m0", "src_ttmp", "src_float_inline", "src_special", ] +# Guide sections 5.3 and 12.3. VCC and EXEC halves can be explicit +# destinations; the move has no implicit mask or SCC effects. +[operand_rules.sop1_move] +family = "SOP1" +dst = { field = "SDST", class = "sgpr_or_vcc_exec" } +src = [{ field = "SSRC0", class = "scalar_source" }] +max_literals = 1 +unsupported = [ + "dst_ttmp", "dst_m0", "dst_null", + "src_vcc", "src_exec", "src_m0", "src_ttmp", "src_float_inline", "src_special", +] + +[[form]] +name = "S_MOV_B32" +family = "SOP1" +opcode = 3 +variant = "MovB32" +operation = "mov" +signedness = "bitwise" +carry_in = "none" +width = 32 +scc = "unchanged" +vcc = "unchanged" +exec = "unchanged" +wave = "any" +operands = "sop1_move" +spec = [ + { document = "guide", section = "12.3", page = 0 }, + { document = "guide", section = "5.3", page = 33 }, +] +verify = ["reference", "independent", "metal", "llvm_encoding"] + [[form]] name = "S_NOT_B32" family = "SOP1" diff --git a/crates/isa/src/lib.rs b/crates/isa/src/lib.rs index a7b9f3b..ccc26fa 100644 --- a/crates/isa/src/lib.rs +++ b/crates/isa/src/lib.rs @@ -163,10 +163,8 @@ pub enum Instruction { src0: u8, src1: u8, }, - /// SOP1 32-bit move to a normal SGPR or an EXEC/VCC half. - ScalarMoveB32 { dst: u8, src: ScalarSource }, - /// SOP1 32-bit unary integer operation writing a normal SGPR (s0-s105) and, - /// for some operations, SCC. + /// SOP1 32-bit unary integer operation. The move also allows an explicit + /// VCC or EXEC half destination. Some unary operations write SCC. ScalarUnary { op: ScalarUnaryOp, dst: u8, @@ -282,7 +280,6 @@ impl Instruction { Self::WaitStore => "s_waitcnt_vscnt", Self::MoveB32 { .. } => "v_mov_b32_e32", Self::VectorAluVop3 { op, .. } => op.assembly_name(), - Self::ScalarMoveB32 { .. } => "s_mov_b32", Self::ScalarUnary { op, .. } => op.mnemonic(), Self::ScalarAlu { op, .. } => op.mnemonic(), Self::ScalarCompare { op, .. } => op.mnemonic(), @@ -341,7 +338,7 @@ impl fmt::Display for Instruction { | Self::VectorMulF32 { dst, src0, src1 } => { write!(formatter, " v{dst}, v{src0}, v{src1}") } - Self::ScalarMoveB32 { dst, src } | Self::ScalarUnary { dst, src, .. } => { + Self::ScalarUnary { dst, src, .. } => { write!(formatter, " {}, {src}", ScalarDestination(dst)) } Self::ScalarAlu { diff --git a/crates/isa/src/primitive.rs b/crates/isa/src/primitive.rs index 198b2df..4a80c88 100644 --- a/crates/isa/src/primitive.rs +++ b/crates/isa/src/primitive.rs @@ -331,3 +331,8 @@ pub const fn lshl_add_carry_u32(a: u32, b: u32, shift: u32) -> (u32, bool) { let sum = ((a as u64) << shift) + b as u64; (sum as u32, sum >> 32 != 0) } + +/// A bitwise copy of the source (RDNA 2 guide section 12.3). +pub(crate) const fn mov_b32(src: u32) -> u32 { + src +} diff --git a/crates/isa/src/semantics.rs b/crates/isa/src/semantics.rs index a987466..c588a91 100644 --- a/crates/isa/src/semantics.rs +++ b/crates/isa/src/semantics.rs @@ -208,6 +208,9 @@ pub enum OperandRule { /// SOP1 unary: SDST is s0-s105; SSRC0 is s0-s105, an inline integer -16..64 or /// a literal word. Everything else is rejected as unsupported. Sop1Sgpr, + /// SOP1 move: the same sources as Sop1Sgpr, with VCC and EXEC halves + /// also allowed as explicit destinations. + Sop1Move, /// SOPK integer: SDST is s0-s105 and, except for compares, written (never s0-s7, /// which hold resource descriptors); SIMM16 is the 16-bit immediate. The word /// never takes a literal. Everything else is rejected as unsupported. diff --git a/crates/isa/src/semantics_gen.rs b/crates/isa/src/semantics_gen.rs index 42aee2b..8a72f6c 100644 --- a/crates/isa/src/semantics_gen.rs +++ b/crates/isa/src/semantics_gen.rs @@ -12,9 +12,11 @@ use crate::CompareRelation; /// Registry schema of the generated tables. pub const GENERATED_SCHEMA: u32 = 1; -/// SOP1 operations declared in the semantic registry (operand rule `sop1_sgpr`). +/// SOP1 operations declared in the semantic registry (operand rules `sop1_move`, `sop1_sgpr`). #[derive(Clone, Copy, Debug, Eq, PartialEq)] pub enum ScalarUnaryOp { + /// `s_mov_b32` (SOP1 opcode 3): bitwise mov, SCC = unchanged. + MovB32, /// `s_not_b32` (SOP1 opcode 7): bitwise not, SCC = nonzero. NotB32, /// `s_brev_b32` (SOP1 opcode 11): bitwise brev, SCC = unchanged. @@ -44,7 +46,7 @@ const SCALAR_UNARY_OP_BY_OPCODE: [Option; 256] = [ None, None, None, - None, + Some(ScalarUnaryOp::MovB32), None, None, None, @@ -301,7 +303,8 @@ const SCALAR_UNARY_OP_BY_OPCODE: [Option; 256] = [ impl ScalarUnaryOp { /// Every operation, in registry order. - pub const ALL: [Self; 11] = [ + pub const ALL: [Self; 12] = [ + Self::MovB32, Self::NotB32, Self::BrevB32, Self::Bcnt0I32B32, @@ -327,6 +330,7 @@ impl ScalarUnaryOp { /// Lower-case mnemonic. pub const fn mnemonic(self) -> &'static str { match self { + Self::MovB32 => "s_mov_b32", Self::NotB32 => "s_not_b32", Self::BrevB32 => "s_brev_b32", Self::Bcnt0I32B32 => "s_bcnt0_i32_b32", @@ -344,23 +348,25 @@ impl ScalarUnaryOp { /// The validated registry row. pub fn semantics(self) -> &'static FormSemantics { &FORMS[match self { - Self::NotB32 => 61, - Self::BrevB32 => 62, - Self::Bcnt0I32B32 => 63, - Self::Bcnt1I32B32 => 64, - Self::Ff0I32B32 => 65, - Self::Ff1I32B32 => 66, - Self::FlbitI32B32 => 67, - Self::FlbitI32 => 68, - Self::SextI32I8 => 69, - Self::SextI32I16 => 70, - Self::AbsI32 => 71, + Self::MovB32 => 61, + Self::NotB32 => 62, + Self::BrevB32 => 63, + Self::Bcnt0I32B32 => 64, + Self::Bcnt1I32B32 => 65, + Self::Ff0I32B32 => 66, + Self::Ff1I32B32 => 67, + Self::FlbitI32B32 => 68, + Self::FlbitI32 => 69, + Self::SextI32I8 => 70, + Self::SextI32I16 => 71, + Self::AbsI32 => 72, }] } /// Whether the operation writes SCC. pub const fn writes_scc(self) -> bool { match self { + Self::MovB32 => false, Self::NotB32 => true, Self::BrevB32 => false, Self::Bcnt0I32B32 => true, @@ -379,6 +385,7 @@ impl ScalarUnaryOp { /// unchanged). pub const fn evaluate(self, src: u32) -> (u32, Option) { match self { + Self::MovB32 => (primitive::mov_b32(src), None), Self::NotB32 => { let (value, scc) = primitive::not_nonzero_b32(src); (value, Some(scc)) @@ -1664,24 +1671,24 @@ impl VectorAluOp { /// The validated registry row. pub fn semantics(self) -> &'static FormSemantics { &FORMS[match self { - Self::MulI32I24 => 72, - Self::MulHiI32I24 => 73, - Self::MulU32U24 => 74, - Self::MulHiU32U24 => 75, - Self::MinI32 => 76, - Self::MaxI32 => 77, - Self::MinU32 => 78, - Self::MaxU32 => 79, - Self::XnorB32 => 80, - Self::AddNcU32 => 81, - Self::SubNcU32 => 82, - Self::SubrevNcU32 => 83, - Self::LshrrevB32 => 84, - Self::AshrrevI32 => 85, - Self::LshlrevB32 => 86, - Self::AndB32 => 87, - Self::OrB32 => 88, - Self::XorB32 => 89, + Self::MulI32I24 => 73, + Self::MulHiI32I24 => 74, + Self::MulU32U24 => 75, + Self::MulHiU32U24 => 76, + Self::MinI32 => 77, + Self::MaxI32 => 78, + Self::MinU32 => 79, + Self::MaxU32 => 80, + Self::XnorB32 => 81, + Self::AddNcU32 => 82, + Self::SubNcU32 => 83, + Self::SubrevNcU32 => 84, + Self::LshrrevB32 => 85, + Self::AshrrevI32 => 86, + Self::LshlrevB32 => 87, + Self::AndB32 => 88, + Self::OrB32 => 89, + Self::XorB32 => 90, }] } @@ -2134,22 +2141,22 @@ impl VectorCompareOp { /// The validated registry row. pub fn semantics(self) -> &'static FormSemantics { &FORMS[match self { - Self::CmpLtI32 => 90, - Self::CmpEqI32 => 91, - Self::CmpLeI32 => 92, - Self::CmpGtI32 => 93, - Self::CmpNeI32 => 94, - Self::CmpGeI32 => 95, - Self::CmpLtU32 => 96, - Self::CmpEqU32 => 97, - Self::CmpLeU32 => 98, - Self::CmpGtU32 => 99, - Self::CmpNeU32 => 100, - Self::CmpGeU32 => 101, - Self::CmpFI32 => 102, - Self::CmpTI32 => 103, - Self::CmpFU32 => 104, - Self::CmpTU32 => 105, + Self::CmpLtI32 => 91, + Self::CmpEqI32 => 92, + Self::CmpLeI32 => 93, + Self::CmpGtI32 => 94, + Self::CmpNeI32 => 95, + Self::CmpGeI32 => 96, + Self::CmpLtU32 => 97, + Self::CmpEqU32 => 98, + Self::CmpLeU32 => 99, + Self::CmpGtU32 => 100, + Self::CmpNeU32 => 101, + Self::CmpGeU32 => 102, + Self::CmpFI32 => 103, + Self::CmpTI32 => 104, + Self::CmpFU32 => 105, + Self::CmpTU32 => 106, }] } @@ -2285,13 +2292,13 @@ impl VectorAluVop3Op { /// The validated registry row of this encoding. pub fn semantics(self) -> &'static FormSemantics { &FORMS[match self { - Self::AddNcU32 => 106, + Self::AddNcU32 => 107, }] } } /// Identity of every registry form and encoding variant, in registry order. -pub const FORM_IDS: [(&str, EncodingFamily); 107] = [ +pub const FORM_IDS: [(&str, EncodingFamily); 108] = [ ("S_ADD_U32", EncodingFamily::Sop2), ("S_SUB_U32", EncodingFamily::Sop2), ("S_ADD_I32", EncodingFamily::Sop2), @@ -2353,6 +2360,7 @@ pub const FORM_IDS: [(&str, EncodingFamily); 107] = [ ("S_CMPK_LE_U32", EncodingFamily::Sopk), ("S_ADDK_I32", EncodingFamily::Sopk), ("S_MULK_I32", EncodingFamily::Sopk), + ("S_MOV_B32", EncodingFamily::Sop1), ("S_NOT_B32", EncodingFamily::Sop1), ("S_BREV_B32", EncodingFamily::Sop1), ("S_BCNT0_I32_B32", EncodingFamily::Sop1), @@ -2402,7 +2410,7 @@ pub const FORM_IDS: [(&str, EncodingFamily); 107] = [ ]; /// One validated row per registry form, in registry order. -pub static FORMS: [FormSemantics; 107] = [ +pub static FORMS: [FormSemantics; 108] = [ FormSemantics { name: "S_ADD_U32", family: EncodingFamily::Sop2, @@ -3684,6 +3692,27 @@ pub static FORMS: [FormSemantics; 107] = [ spec: &[SpecRef { document: Document::Guide, section: "12.2", page: 106 }, SpecRef { document: Document::Guide, section: "13.1.2", page: 240 }], verify: &[Evidence::Reference, Evidence::Independent, Evidence::Metal, Evidence::LlvmEncoding], }, + FormSemantics { + name: "S_MOV_B32", + family: EncodingFamily::Sop1, + opcode: 3, + operation: Operation::Move, + signedness: Signedness::Bitwise, + carry_in: CarryIn::None, + width: 32, + shift_count_bits: 0, + shift_amount: 0, + swap_sources: false, + source_bits: 32, + relation: None, + scc: SccEffect::Unchanged, + vcc: MaskEffect::Unchanged, + exec: MaskEffect::Unchanged, + wave: Wave::Any, + operands: OperandRule::Sop1Move, + spec: &[SpecRef { document: Document::Guide, section: "12.3", page: 0 }, SpecRef { document: Document::Guide, section: "5.3", page: 33 }], + verify: &[Evidence::Reference, Evidence::Independent, Evidence::Metal, Evidence::LlvmEncoding], + }, FormSemantics { name: "S_NOT_B32", family: EncodingFamily::Sop1, diff --git a/crates/isa/tests/semantics.rs b/crates/isa/tests/semantics.rs index b1b4655..1bb721f 100644 --- a/crates/isa/tests/semantics.rs +++ b/crates/isa/tests/semantics.rs @@ -144,7 +144,6 @@ fn scalar_unary_dispatch_selects_exactly_the_registry_sop1_forms() { assert_eq!(row.name.to_ascii_lowercase(), op.mnemonic()); assert_eq!(op.writes_scc(), row.scc != SccEffect::Unchanged); } - // s_mov_b32 (opcode 3) stays hand-written, so it must not be dispatched here. dispatch_selects_exactly(EncodingFamily::Sop1, |word| { ScalarUnaryOp::from_word(word).map(|op| op.semantics().name) }); diff --git a/crates/shader/src/lib.rs b/crates/shader/src/lib.rs index 26c3e58..9bd42a6 100644 --- a/crates/shader/src/lib.rs +++ b/crates/shader/src/lib.rs @@ -9,8 +9,8 @@ pub use graphics::{PIXEL_ENTRY_POINT, VERTEX_ENTRY_POINT, compile_graphics}; pub use xenora_decoder::Architecture; use xenora_decoder::{ - DecodeError, DecodedInstruction, Instruction, ScalarSource, VectorAluOp, VectorAluVop3Op, - VectorBinary, VectorCompareOp, VectorSource, + DecodeError, DecodedInstruction, Instruction, ScalarSource, ScalarUnaryOp, VectorAluOp, + VectorAluVop3Op, VectorBinary, VectorCompareOp, VectorSource, }; /// SGPR index of `vcc_lo`. @@ -848,8 +848,12 @@ fn lift(decoded: &[DecodedInstruction], code_len: usize) -> Result { - let value = read_scalar(src)?; + Instruction::ScalarUnary { + op: op @ ScalarUnaryOp::MovB32, + dst, + src, + } => { + let (value, _) = op.evaluate(read_scalar(src)?); if dst < 8 { return Err(error("scalar move would modify a resource descriptor")); } diff --git a/docs/shaders/semantic-coverage.md b/docs/shaders/semantic-coverage.md index ae178d5..10223f9 100644 --- a/docs/shaders/semantic-coverage.md +++ b/docs/shaders/semantic-coverage.md @@ -24,7 +24,7 @@ acceptance remain outside the verified count. All results concern synthetic fixt | MUBUF | 75 | 2 | 0 | 2 | 2 | 2 | 2 | 2 | 0 | | SCRATCH | 22 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | | SMEM | 14 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | -| SOP1 | 65 | 12 | 11 | 12 | 12 | 12 | 1 | 1 | 11 | +| SOP1 | 65 | 12 | 12 | 12 | 12 | 12 | 1 | 1 | 11 | | SOP2 | 51 | 33 | 33 | 33 | 33 | 33 | 0 | 0 | 12 | | SOPC | 18 | 12 | 12 | 12 | 12 | 12 | 1 | 1 | 7 | | SOPK | 27 | 17 | 16 | 17 | 17 | 17 | 1 | 1 | 5 | @@ -36,7 +36,7 @@ acceptance remain outside the verified count. All results concern synthetic fixt | VOP3P | 29 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | | VOP3SDST | 10 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | | VOPC | 190 | 16 | 16 | 16 | 16 | 16 | 0 | 0 | 7 | -| **Total** | 1465 | 120 | 107 | 124 | 120 | 120 | 18 | 18 | 65 | +| **Total** | 1465 | 120 | 108 | 124 | 120 | 120 | 18 | 18 | 65 | ## Unsupported operand variants @@ -44,6 +44,7 @@ The table counts distinct variant names per family across registry operand rules | Family | Operand rule | Unsupported variants | | --- | --- | --- | +| SOP1 | `sop1_move` | `dst_m0`, `dst_null`, `dst_ttmp`, `src_exec`, `src_float_inline`, `src_m0`, `src_special`, `src_ttmp`, `src_vcc` | | SOP1 | `sop1_sgpr` | `dst_exec`, `dst_m0`, `dst_null`, `dst_ttmp`, `dst_vcc`, `src_exec`, `src_float_inline`, `src_m0`, `src_special`, `src_ttmp`, `src_vcc` | | SOP2 | `sop2_sgpr` | `dst_exec`, `dst_m0`, `dst_null`, `dst_ttmp`, `dst_vcc`, `src_exec`, `src_float_inline`, `src_m0`, `src_special`, `src_ttmp`, `src_vcc`, `two_literals` | | SOPC | `sopc_scalar` | `src_exec`, `src_float_inline`, `src_m0`, `src_special`, `src_ttmp`, `src_vcc`, `two_literals` | diff --git a/docs/shaders/semantic-registry.md b/docs/shaders/semantic-registry.md index 38c4f34..238c76a 100644 --- a/docs/shaders/semantic-registry.md +++ b/docs/shaders/semantic-registry.md @@ -109,7 +109,7 @@ error. | `family` | Encoding family; must match the XML base encoding | e.g. `SOP2` | | `opcode` | Opcode; must match the XML | non-negative integer | | `variant` | Rust enum variant of the typed operation | CamelCase, e.g. `AddU32` | -| `operation` | The primitive the form uses | `add`, `sub`, `and`, `or`, `xor`, `andn2`, `orn2`, `nand`, `nor`, `xnor`, `lshl`, `lshr`, `ashr`, `min`, `max`, `cselect`, `bfm`, `mul`, `mul_hi`, `bfe`, `absdiff`, `lshl_add`, `mul24`, `mul_hi24` (vector only), `mov` and `cmov` (SOPK only), `compare` and the SOP1 unaries | +| `operation` | The primitive the form uses | `add`, `sub`, `and`, `or`, `xor`, `andn2`, `orn2`, `nand`, `nor`, `xnor`, `lshl`, `lshr`, `ashr`, `min`, `max`, `cselect`, `bfm`, `mul`, `mul_hi`, `bfe`, `absdiff`, `lshl_add`, `mul24`, `mul_hi24` (vector only), `mov` (SOP1 and SOPK), `cmov` (SOPK only), `compare` and the SOP1 unaries | | `signedness` | How operands are read | `unsigned`, `signed`, `bitwise` (always `bitwise` for the logical operations, `cselect` and `bfm`; never for the arithmetic ones, `add`, `sub`, `min`, `max`, `mul`, `mul_hi`, `bfe`, `absdiff` and `lshl_add`; shifts take their primitive's signedness) | | `carry_in` | Whether the form reads SCC: carry-in, borrow-in or the select condition | `none`, `scc` (`scc` only for unsigned `add` and `sub`, and required for `cselect`) | | `width` | Operand and result width in bits | `32` | @@ -119,7 +119,7 @@ error. | `shift_amount` | `lshl_add` only: the fixed left shift of S0 before the add | `1` to `4`; required for `lshl_add`, rejected elsewhere | | `shift_count_bits` | Shifts only: the low bits of the count source used as the count: S1, or S0 for a vector form with `source_order = "reversed"`. Scalar forms mask it in the generated evaluation, vector forms in their MSL template; the XML must list the count source as unsigned | `5` (log2 of `width`); required for shifts, rejected elsewhere | | `scc` | What the form writes to SCC | `carry_out`, `borrow`, `signed_overflow`, `nonzero`, `relation` (SOPC and SOPK compares only), `selected_src0` (min and max: S0 won the strict compare, so a tie gives 0), `unchanged` | -| `vcc`, `exec` | Effect on VCC and EXEC, stated rather than implied | `unchanged`; `vcc` is `lane_mask` exactly for the VOPC compares (VCC_LO bit n = EXEC[n] & test, fully written; VCC_HI unknown afterwards, see [vector-compare.md](vector-compare.md)); `exec` must be `unchanged` (no EXEC-writing contract yet) | +| `vcc`, `exec` | Implicit effect on VCC and EXEC | `unchanged`; `vcc` is `lane_mask` exactly for the VOPC compares (VCC_LO bit n = EXEC[n] & test, fully written; VCC_HI unknown afterwards, see [vector-compare.md](vector-compare.md)); `exec` must be `unchanged` (explicit destinations are covered by the operand rule) | | `wave` | Wave sizes the form is valid in | `wave32` exactly for the VOPC compares (their one entry point is the Wave32 compute fixture ABI, vector-compare.md section 2), `any` for everything else; the decoder has no wave-size input, so no other form may claim `wave32` | | `operands` | Name of an `[operand_rules]` entry for the same family | e.g. `sop2_sgpr` | | `spec` | References `{ document, section, page }` | at least one `guide` reference with a page above 0 | @@ -154,6 +154,14 @@ fixes the `scc` value: | `cmov` / `signed` (SOPK only) | `unchanged` | `sext_simm16` | required | | `compare` / `signed` or `unsigned` | `relation` | `eq_b32`, `ne_b32` (for both signednesses), `gt_i32`/`gt_u32`, `ge_*`, `lt_*`, `le_*` | no | +SOP1 unary forms share `ScalarUnaryOp`. The `sop1_sgpr` rule accepts +destination encodings 0–105. The `sop1_move` rule for `s_mov_b32` also accepts +106–107 (VCC halves) and 126–127 (EXEC halves) as explicit destinations. +Both rules accept source registers s0–s105, inline integers −16 through 64, +and one literal dword. The move copies the source and leaves SCC unchanged. +The destination vocabulary preserves the original decoder subset of the +RDNA 2 guide sections 5.3 and 12.3. + Vector forms (operand rules `vop2_vgpr` and `vop2_vgpr2`, kind `vector`; both generate the one `VectorAluOp` enum, whose `operand_rule()` tells the decoder which rule a form uses) use a separate table: