From f8eb976102f07717505ea0775ab1bcadb368b390 Mon Sep 17 00:00:00 2001 From: elforeign <324243036+elforeign@users.noreply.github.com> Date: Tue, 24 Nov 2026 10:20:28 -0600 Subject: [PATCH] isa, decoder, shader: translate the twelve VOPC 16-bit integer compares (#215) v_cmp_{lt,eq,le,gt,ne,ge}_{i16,u16}_e32 (opcodes 137-142, 169-174) now compile for gfx1030: both operands use bits 15:0 of the VGPR, SGPR or VCC_LO source, inline integers at 16 bits, literals rejected, writing the Wave32 VCC mask. The B1 oracle's last native Metal skip is removed. Signed-off-by: elforeign <324243036+elforeign@users.noreply.github.com> --- CHANGELOG.md | 1 + crates/decoder/src/lib.rs | 3 + crates/decoder/tests/gfx1030.rs | 26 +- crates/isa/generate_semantics.py | 39 ++- crates/isa/semantics/rdna2/vopc.toml | 265 +++++++++++++++++ crates/isa/src/semantics.rs | 2 + crates/isa/src/semantics_gen.rs | 406 +++++++++++++++++++++++++-- crates/isa/tests/semantics.rs | 26 +- crates/shader/src/lib.rs | 12 +- docs/assets/xenora-progress.svg | 8 +- docs/shaders/instruction-coverage.md | 12 + docs/shaders/semantic-coverage.md | 5 +- docs/shaders/semantic-registry.md | 11 +- docs/shaders/vector-compare.md | 34 +-- docs/status.toml | 144 ++++++++++ fixtures/rdna2/vector-compare-16.bin | Bin 0 -> 84 bytes fixtures/rdna2/vector-compare-16.s | 23 ++ scripts/assemble-fixture.sh | 2 +- scripts/test-gpu.sh | 5 +- tests/validation/tests/vopc_wide.rs | 38 ++- 20 files changed, 983 insertions(+), 79 deletions(-) create mode 100644 fixtures/rdna2/vector-compare-16.bin create mode 100644 fixtures/rdna2/vector-compare-16.s diff --git a/CHANGELOG.md b/CHANGELOG.md index aafb84c..ff9b10c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ remains unsupported. - 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. ### Added +- Added decoding and Metal shader translation for twelve Wave32 VOPC 16-bit integer compares (#215). The signed and unsigned forms compare the low 16 bits of each source and write the Wave32 VCC mask. CPU verification covers 1,572 compiler acceptance cases and 408 rejections from the guide-derived oracle. Native Metal verification and independent acceptance are pending. - Added decoding and Metal shader translation for the sixteen Wave32 VOPC 64-bit integer compares (#215). They read VGPR pairs, known even-aligned SGPR pairs or sign-extended inline integers and write the Wave32 VCC mask. The guide-derived oracle passes on native Metal (4,640 cases in 3,818 programs on a local Apple M5 under API and shader validation); acceptance is pending. - Added XADD and CMPXCHG for 8- to 64-bit register and memory destinations, and the LOCK prefix on their memory forms (#198). LOCK anywhere else, CMPXCHG8B and CMPXCHG16B stay rejected. Both engines run the new forms on the shared semantics, one instruction at a time, so a locked instruction is indivisible today and LOCK changes no result; `docs/cpu/instruction-registry.md` states the ordering, alignment, compare-failure and fault rules a guest scheduler must preserve. A failed compare still writes the destination, so it faults on memory that cannot be written. Nothing is lowered to ARM64 atomic instructions, and no multi-thread behaviour is established. Fourteen SDM-derived cases already in `cpu_known_answers.rs` moved from refused to verified, with 62 LLVM-assembled fixtures and five new tests in `x86_atomic.rs`; not compared with x86 hardware and awaiting independent review. - Added CPUID with a fixed, host-independent guest contract (#130). It reports a synthetic processor with the vendor string `Xenora guest` and sets a feature bit only when every instruction of that feature is implemented: CMOV, POPCNT, LZCNT and long mode today. SSE and SSE2 are not reported while parts of them, such as RSQRTPS and MFENCE, are still rejected, so the table is truthful about Xenora and not a plausible hardware model. Unlisted leaves return zeros. `tests/cpu_features.rs` pins every leaf in both engines, requires each reported feature's instructions among the executed fixtures, and holds a refused witness instruction for 31 unreported features. `docs/cpu/instruction-registry.md` gives the table and the rule for reporting a new feature. Not compared with a processor; awaiting independent review. diff --git a/crates/decoder/src/lib.rs b/crates/decoder/src/lib.rs index a5ca56d..48badbb 100644 --- a/crates/decoder/src/lib.rs +++ b/crates/decoder/src/lib.rs @@ -686,6 +686,9 @@ fn vector_compare( return Err(unsupported(mnemonic, "invalid 64-bit compare source")); } } + if op.semantics().width == 16 && first & 0x1ff == 255 { + return Err(unsupported(mnemonic, "literal in 16-bit compare")); + } let (src0, len) = vector_src0(first, bytes, mnemonic)?; Ok((Instruction::VectorCompare { op, src0, src1 }, len)) } diff --git a/crates/decoder/tests/gfx1030.rs b/crates/decoder/tests/gfx1030.rs index 723a391..41a59bf 100644 --- a/crates/decoder/tests/gfx1030.rs +++ b/crates/decoder/tests/gfx1030.rs @@ -9,8 +9,8 @@ use xenora_decoder::{ }; use xenora_isa::semantics::Signedness; use xenora_ref::{ - BranchCondition, CompareSource, Comparison, Op, ScalarAlu, ScalarImmediate, ScalarUnary, - Source, VectorAlu, VectorInteger, VectorUnary, + BranchCondition, CompareSource, CompareWidth, Comparison, Op, ScalarAlu, ScalarImmediate, + ScalarUnary, Source, VectorAlu, VectorInteger, VectorUnary, }; const FIXTURE: &[u8] = include_bytes!("../../../fixtures/rdna2/add.bin"); @@ -505,8 +505,8 @@ fn reference_op(instruction: Instruction) -> Op { panic!("compute reference matrix received a graphics/image instruction") } - Instruction::VectorCompare { op, src0, src1 } => Op::Compare( - Comparison { + Instruction::VectorCompare { op, src0, src1 } => { + let comparison = Comparison { offset: match op.relation() { CompareRelation::Less => 1, CompareRelation::Equal => 2, @@ -518,14 +518,19 @@ fn reference_op(instruction: Instruction) -> Op { CompareRelation::True => 7, }, signed: op.signed(), - }, - match src0 { + }; + let src0 = match src0 { VectorSource::Register(reg) => CompareSource::Vector(reg), VectorSource::Scalar(reg) => CompareSource::Scalar(reg), VectorSource::Immediate(bits) => CompareSource::Immediate(bits), - }, - src1, - ), + }; + match op.semantics().width { + 16 => Op::WideCompare(comparison, CompareWidth::Half, src0, src1), + 32 => Op::Compare(comparison, src0, src1), + 64 => Op::WideCompare(comparison, CompareWidth::Double, src0, src1), + width => panic!("unexpected VOPC operand width {width}"), + } + } Instruction::VectorAlu { op, dst, @@ -585,12 +590,13 @@ fn compares_fixture_instructions_against_llvm() { include_bytes!("../../../fixtures/rdna2/vector-compare.bin"), include_bytes!("../../../fixtures/rdna2/vector-compare-ft.bin"), include_bytes!("../../../fixtures/rdna2/vector-unary.bin"), + include_bytes!("../../../fixtures/rdna2/vector-compare-16.bin"), high_registers, &matrix, ] { count += compare_against_llvm(fixture, &mut forms); } - assert_eq!(forms.len(), 126, "forms compared: {forms:?}"); + assert_eq!(forms.len(), 138, "forms compared: {forms:?}"); eprintln!( "{count} three-way instruction comparisons across {} forms", forms.len() diff --git a/crates/isa/generate_semantics.py b/crates/isa/generate_semantics.py index cc2c6af..95240c1 100755 --- a/crates/isa/generate_semantics.py +++ b/crates/isa/generate_semantics.py @@ -78,7 +78,11 @@ RELATIONS = { VECTOR_ONLY_RELATIONS = {"f", "t"} # Guide 12.9 Tables 59 and 61: integer VOPC opcodes are the group base # for the operand width and signedness plus the relation offset. -VOPC_INTEGER_BASES = {32: {"signed": 128, "unsigned": 192}, 64: {"signed": 160, "unsigned": 224}} +VOPC_INTEGER_BASES = { + 16: {"signed": 136, "unsigned": 168}, + 32: {"signed": 128, "unsigned": 192}, + 64: {"signed": 160, "unsigned": 224}, +} VOPC_RELATION_OFFSETS = {"f": 0, "lt": 1, "eq": 2, "le": 3, "gt": 4, "lg": 5, "ge": 6, "t": 7} # (relation, signedness) -> primitive. Equality does not depend on signedness, # so both declared signednesses of EQ and LG share one primitive. @@ -399,6 +403,26 @@ OPERAND_RULES = { }, "kind": "vector_compare", }, + "vopc_vcc_half": { + "rust": "VopcVccHalf", + "enum": "VectorCompareOp", + "shape": { + "family": "VOPC", + "src": [ + {"field": "SRC0", "class": "vector_source"}, + {"field": "VSRC1", "class": "vgpr"}, + ], + "max_literals": 0, + }, + # The destination is implicitly vcc_lo; the decoder rejects these SRC0 + # selectors (the same vector_source as VOP2). + "unsupported": { + "src_literal", "src_vcc_hi", "src_exec", "src_m0", "src_ttmp", "src_null", "src_float_inline", + "src_special", + }, + "kind": "vector_compare", + "width": 16, + }, "vopc_vcc_pair": { "rust": "VopcVccPair", "enum": "VectorCompareOp", @@ -718,8 +742,8 @@ def _check_xml(form, rule, snapshot, errors): if data_format != f"FMT_NUM_I{bits}": errors.append(f"{label}: {field} has XML format {data_format}, not FMT_NUM_I{bits}") elif is_source and data_format not in ( - {f"FMT_NUM_{'I' if form['signedness'] == 'signed' else 'U'}64"} - if form["operands"] == "vopc_vcc_pair" + {f"FMT_NUM_{'I' if form['signedness'] == 'signed' else 'U'}{form['width']}"} + if form["operands"] in ("vopc_vcc_half", "vopc_vcc_pair") else SOURCE_FORMATS.get(form["signedness"], ()) ): errors.append( @@ -1612,9 +1636,14 @@ def _render_enum(rule_name, forms, snapshot, positions): out += [" match self {"] for form in forms: relation = form[RELATION_KEY] - if form["width"] == 64 and relation not in VECTOR_ONLY_RELATIONS: + if form["width"] in (16, 64) and relation not in VECTOR_ONLY_RELATIONS: symbol = {"lt": "<", "eq": "==", "le": "<=", "gt": ">", "lg": "!=", "ge": ">="}[relation] - left, right = ("(src0 as i64)", "(src1 as i64)") if form["signedness"] == "signed" else ("src0", "src1") + width = form["width"] + if width == 64 and form["signedness"] == "unsigned": + left, right = "src0", "src1" + else: + cast = f"{'i' if form['signedness'] == 'signed' else 'u'}{width}" + left, right = f"(src0 as {cast})", f"(src1 as {cast})" expression = f"{left} {symbol} {right}" else: function = COMPARE_PRIMITIVES[(relation, form["signedness"])] diff --git a/crates/isa/semantics/rdna2/vopc.toml b/crates/isa/semantics/rdna2/vopc.toml index b028b74..a93db76 100644 --- a/crates/isa/semantics/rdna2/vopc.toml +++ b/crates/isa/semantics/rdna2/vopc.toml @@ -707,3 +707,268 @@ spec = [ { document = "guide", section = "3.9", page = 19 }, ] verify = ["reference", "independent", "metal"] + +# Wave32 16-bit integer compares (guide 12.9, Tables 59 and 61). +[operand_rules.vopc_vcc_half] +family = "VOPC" +src = [ + { field = "SRC0", class = "vector_source" }, + { field = "VSRC1", class = "vgpr" }, +] +# Guide 6.2, 6.2.5 and 6.8: read the low half of each source. +max_literals = 0 +unsupported = [ + "src_literal", "src_vcc_hi", "src_exec", "src_m0", "src_ttmp", "src_null", "src_float_inline", "src_special", +] + +[[form]] +name = "V_CMP_LT_I16" +family = "VOPC" +opcode = 137 +variant = "CmpLtI16" +operation = "compare" +relation = "lt" +signedness = "signed" +carry_in = "none" +width = 16 +scc = "unchanged" +vcc = "lane_mask" +exec = "unchanged" +wave = "wave32" +operands = "vopc_vcc_half" +spec = [ + { document = "guide", section = "12.9", page = 150 }, + { document = "guide", section = "3.9", page = 19 }, +] +verify = ["reference", "independent", "metal", "llvm_encoding"] + +[[form]] +name = "V_CMP_EQ_I16" +family = "VOPC" +opcode = 138 +variant = "CmpEqI16" +operation = "compare" +relation = "eq" +signedness = "signed" +carry_in = "none" +width = 16 +scc = "unchanged" +vcc = "lane_mask" +exec = "unchanged" +wave = "wave32" +operands = "vopc_vcc_half" +spec = [ + { document = "guide", section = "12.9", page = 150 }, + { document = "guide", section = "3.9", page = 19 }, +] +verify = ["reference", "independent", "metal", "llvm_encoding"] + +[[form]] +name = "V_CMP_LE_I16" +family = "VOPC" +opcode = 139 +variant = "CmpLeI16" +operation = "compare" +relation = "le" +signedness = "signed" +carry_in = "none" +width = 16 +scc = "unchanged" +vcc = "lane_mask" +exec = "unchanged" +wave = "wave32" +operands = "vopc_vcc_half" +spec = [ + { document = "guide", section = "12.9", page = 150 }, + { document = "guide", section = "3.9", page = 19 }, +] +verify = ["reference", "independent", "metal", "llvm_encoding"] + +[[form]] +name = "V_CMP_GT_I16" +family = "VOPC" +opcode = 140 +variant = "CmpGtI16" +operation = "compare" +relation = "gt" +signedness = "signed" +carry_in = "none" +width = 16 +scc = "unchanged" +vcc = "lane_mask" +exec = "unchanged" +wave = "wave32" +operands = "vopc_vcc_half" +spec = [ + { document = "guide", section = "12.9", page = 150 }, + { document = "guide", section = "3.9", page = 19 }, +] +verify = ["reference", "independent", "metal", "llvm_encoding"] + +[[form]] +name = "V_CMP_NE_I16" +family = "VOPC" +opcode = 141 +variant = "CmpNeI16" +operation = "compare" +relation = "lg" +signedness = "signed" +carry_in = "none" +width = 16 +scc = "unchanged" +vcc = "lane_mask" +exec = "unchanged" +wave = "wave32" +operands = "vopc_vcc_half" +spec = [ + { document = "guide", section = "12.9", page = 150 }, + { document = "guide", section = "3.9", page = 19 }, +] +verify = ["reference", "independent", "metal", "llvm_encoding"] + +[[form]] +name = "V_CMP_GE_I16" +family = "VOPC" +opcode = 142 +variant = "CmpGeI16" +operation = "compare" +relation = "ge" +signedness = "signed" +carry_in = "none" +width = 16 +scc = "unchanged" +vcc = "lane_mask" +exec = "unchanged" +wave = "wave32" +operands = "vopc_vcc_half" +spec = [ + { document = "guide", section = "12.9", page = 150 }, + { document = "guide", section = "3.9", page = 19 }, +] +verify = ["reference", "independent", "metal", "llvm_encoding"] + +[[form]] +name = "V_CMP_LT_U16" +family = "VOPC" +opcode = 169 +variant = "CmpLtU16" +operation = "compare" +relation = "lt" +signedness = "unsigned" +carry_in = "none" +width = 16 +scc = "unchanged" +vcc = "lane_mask" +exec = "unchanged" +wave = "wave32" +operands = "vopc_vcc_half" +spec = [ + { document = "guide", section = "12.9", page = 150 }, + { document = "guide", section = "3.9", page = 19 }, +] +verify = ["reference", "independent", "metal", "llvm_encoding"] + +[[form]] +name = "V_CMP_EQ_U16" +family = "VOPC" +opcode = 170 +variant = "CmpEqU16" +operation = "compare" +relation = "eq" +signedness = "unsigned" +carry_in = "none" +width = 16 +scc = "unchanged" +vcc = "lane_mask" +exec = "unchanged" +wave = "wave32" +operands = "vopc_vcc_half" +spec = [ + { document = "guide", section = "12.9", page = 150 }, + { document = "guide", section = "3.9", page = 19 }, +] +verify = ["reference", "independent", "metal", "llvm_encoding"] + +[[form]] +name = "V_CMP_LE_U16" +family = "VOPC" +opcode = 171 +variant = "CmpLeU16" +operation = "compare" +relation = "le" +signedness = "unsigned" +carry_in = "none" +width = 16 +scc = "unchanged" +vcc = "lane_mask" +exec = "unchanged" +wave = "wave32" +operands = "vopc_vcc_half" +spec = [ + { document = "guide", section = "12.9", page = 150 }, + { document = "guide", section = "3.9", page = 19 }, +] +verify = ["reference", "independent", "metal", "llvm_encoding"] + +[[form]] +name = "V_CMP_GT_U16" +family = "VOPC" +opcode = 172 +variant = "CmpGtU16" +operation = "compare" +relation = "gt" +signedness = "unsigned" +carry_in = "none" +width = 16 +scc = "unchanged" +vcc = "lane_mask" +exec = "unchanged" +wave = "wave32" +operands = "vopc_vcc_half" +spec = [ + { document = "guide", section = "12.9", page = 150 }, + { document = "guide", section = "3.9", page = 19 }, +] +verify = ["reference", "independent", "metal", "llvm_encoding"] + +[[form]] +name = "V_CMP_NE_U16" +family = "VOPC" +opcode = 173 +variant = "CmpNeU16" +operation = "compare" +relation = "lg" +signedness = "unsigned" +carry_in = "none" +width = 16 +scc = "unchanged" +vcc = "lane_mask" +exec = "unchanged" +wave = "wave32" +operands = "vopc_vcc_half" +spec = [ + { document = "guide", section = "12.9", page = 150 }, + { document = "guide", section = "3.9", page = 19 }, +] +verify = ["reference", "independent", "metal", "llvm_encoding"] + +[[form]] +name = "V_CMP_GE_U16" +family = "VOPC" +opcode = 174 +variant = "CmpGeU16" +operation = "compare" +relation = "ge" +signedness = "unsigned" +carry_in = "none" +width = 16 +scc = "unchanged" +vcc = "lane_mask" +exec = "unchanged" +wave = "wave32" +operands = "vopc_vcc_half" +spec = [ + { document = "guide", section = "12.9", page = 150 }, + { document = "guide", section = "3.9", page = 19 }, +] +verify = ["reference", "independent", "metal", "llvm_encoding"] diff --git a/crates/isa/src/semantics.rs b/crates/isa/src/semantics.rs index 847f411..8d171e5 100644 --- a/crates/isa/src/semantics.rs +++ b/crates/isa/src/semantics.rs @@ -242,6 +242,8 @@ pub enum OperandRule { /// Wave32 VOPC with a VGPR pair, even normal SGPR pair or inline integer /// as SRC0 and a VGPR pair as VSRC1. The destination is `vcc_lo`. VopcVccPair, + /// VOPC with low-half operands and no literal selector. + VopcVccHalf, /// VOP3 encoding of a VOP2 vector form: VDST is v0-v255, SRC0 and SRC1 are /// VGPRs, no input or output modifiers, SRC2 unused. Everything else is /// rejected as unsupported. diff --git a/crates/isa/src/semantics_gen.rs b/crates/isa/src/semantics_gen.rs index f75b7dc..721feea 100644 --- a/crates/isa/src/semantics_gen.rs +++ b/crates/isa/src/semantics_gen.rs @@ -2432,7 +2432,7 @@ impl VectorAluOp { } } -/// VOPC operations declared in the semantic registry (operand rules `vopc_vcc`, `vopc_vcc_pair`). +/// VOPC operations declared in the semantic registry (operand rules `vopc_vcc`, `vopc_vcc_half`, `vopc_vcc_pair`). #[derive(Clone, Copy, Debug, Eq, PartialEq)] pub enum VectorCompareOp { /// `v_cmp_lt_i32` (VOPC opcode 129): signed compare lt, VCC = lane_mask. @@ -2499,6 +2499,30 @@ pub enum VectorCompareOp { CmpFU64, /// `v_cmp_t_u64` (VOPC opcode 231): unsigned compare t, VCC = lane_mask. CmpTU64, + /// `v_cmp_lt_i16` (VOPC opcode 137): signed compare lt, VCC = lane_mask. + CmpLtI16, + /// `v_cmp_eq_i16` (VOPC opcode 138): signed compare eq, VCC = lane_mask. + CmpEqI16, + /// `v_cmp_le_i16` (VOPC opcode 139): signed compare le, VCC = lane_mask. + CmpLeI16, + /// `v_cmp_gt_i16` (VOPC opcode 140): signed compare gt, VCC = lane_mask. + CmpGtI16, + /// `v_cmp_ne_i16` (VOPC opcode 141): signed compare lg, VCC = lane_mask. + CmpNeI16, + /// `v_cmp_ge_i16` (VOPC opcode 142): signed compare ge, VCC = lane_mask. + CmpGeI16, + /// `v_cmp_lt_u16` (VOPC opcode 169): unsigned compare lt, VCC = lane_mask. + CmpLtU16, + /// `v_cmp_eq_u16` (VOPC opcode 170): unsigned compare eq, VCC = lane_mask. + CmpEqU16, + /// `v_cmp_le_u16` (VOPC opcode 171): unsigned compare le, VCC = lane_mask. + CmpLeU16, + /// `v_cmp_gt_u16` (VOPC opcode 172): unsigned compare gt, VCC = lane_mask. + CmpGtU16, + /// `v_cmp_ne_u16` (VOPC opcode 173): unsigned compare lg, VCC = lane_mask. + CmpNeU16, + /// `v_cmp_ge_u16` (VOPC opcode 174): unsigned compare ge, VCC = lane_mask. + CmpGeU16, } /// VectorCompareOp by VOPC OP field value; `None` for undeclared opcodes. @@ -2640,12 +2664,12 @@ const VECTOR_COMPARE_OP_BY_OPCODE: [Option; 256] = [ Some(VectorCompareOp::CmpGeI32), Some(VectorCompareOp::CmpTI32), None, - None, - None, - None, - None, - None, - None, + Some(VectorCompareOp::CmpLtI16), + Some(VectorCompareOp::CmpEqI16), + Some(VectorCompareOp::CmpLeI16), + Some(VectorCompareOp::CmpGtI16), + Some(VectorCompareOp::CmpNeI16), + Some(VectorCompareOp::CmpGeI16), None, None, None, @@ -2672,12 +2696,12 @@ const VECTOR_COMPARE_OP_BY_OPCODE: [Option; 256] = [ Some(VectorCompareOp::CmpGeI64), Some(VectorCompareOp::CmpTI64), None, - None, - None, - None, - None, - None, - None, + Some(VectorCompareOp::CmpLtU16), + Some(VectorCompareOp::CmpEqU16), + Some(VectorCompareOp::CmpLeU16), + Some(VectorCompareOp::CmpGtU16), + Some(VectorCompareOp::CmpNeU16), + Some(VectorCompareOp::CmpGeU16), None, None, None, @@ -2763,7 +2787,7 @@ const VECTOR_COMPARE_OP_BY_OPCODE: [Option; 256] = [ impl VectorCompareOp { /// Every operation, in registry order. - pub const ALL: [Self; 32] = [ + pub const ALL: [Self; 44] = [ Self::CmpLtI32, Self::CmpEqI32, Self::CmpLeI32, @@ -2796,6 +2820,18 @@ impl VectorCompareOp { Self::CmpTI64, Self::CmpFU64, Self::CmpTU64, + Self::CmpLtI16, + Self::CmpEqI16, + Self::CmpLeI16, + Self::CmpGtI16, + Self::CmpNeI16, + Self::CmpGeI16, + Self::CmpLtU16, + Self::CmpEqU16, + Self::CmpLeU16, + Self::CmpGtU16, + Self::CmpNeU16, + Self::CmpGeU16, ]; /// Selects the operation from a first instruction word: the VOPC encoding @@ -2842,6 +2878,18 @@ impl VectorCompareOp { Self::CmpTI64 => "v_cmp_t_i64", Self::CmpFU64 => "v_cmp_f_u64", Self::CmpTU64 => "v_cmp_t_u64", + Self::CmpLtI16 => "v_cmp_lt_i16", + Self::CmpEqI16 => "v_cmp_eq_i16", + Self::CmpLeI16 => "v_cmp_le_i16", + Self::CmpGtI16 => "v_cmp_gt_i16", + Self::CmpNeI16 => "v_cmp_ne_i16", + Self::CmpGeI16 => "v_cmp_ge_i16", + Self::CmpLtU16 => "v_cmp_lt_u16", + Self::CmpEqU16 => "v_cmp_eq_u16", + Self::CmpLeU16 => "v_cmp_le_u16", + Self::CmpGtU16 => "v_cmp_gt_u16", + Self::CmpNeU16 => "v_cmp_ne_u16", + Self::CmpGeU16 => "v_cmp_ge_u16", } } @@ -2880,6 +2928,18 @@ impl VectorCompareOp { Self::CmpTI64 => 126, Self::CmpFU64 => 127, Self::CmpTU64 => 128, + Self::CmpLtI16 => 129, + Self::CmpEqI16 => 130, + Self::CmpLeI16 => 131, + Self::CmpGtI16 => 132, + Self::CmpNeI16 => 133, + Self::CmpGeI16 => 134, + Self::CmpLtU16 => 135, + Self::CmpEqU16 => 136, + Self::CmpLeU16 => 137, + Self::CmpGtU16 => 138, + Self::CmpNeU16 => 139, + Self::CmpGeU16 => 140, }] } @@ -2918,6 +2978,18 @@ impl VectorCompareOp { Self::CmpTI64 => "v_cmp_t_i64_e32", Self::CmpFU64 => "v_cmp_f_u64_e32", Self::CmpTU64 => "v_cmp_t_u64_e32", + Self::CmpLtI16 => "v_cmp_lt_i16_e32", + Self::CmpEqI16 => "v_cmp_eq_i16_e32", + Self::CmpLeI16 => "v_cmp_le_i16_e32", + Self::CmpGtI16 => "v_cmp_gt_i16_e32", + Self::CmpNeI16 => "v_cmp_ne_i16_e32", + Self::CmpGeI16 => "v_cmp_ge_i16_e32", + Self::CmpLtU16 => "v_cmp_lt_u16_e32", + Self::CmpEqU16 => "v_cmp_eq_u16_e32", + Self::CmpLeU16 => "v_cmp_le_u16_e32", + Self::CmpGtU16 => "v_cmp_gt_u16_e32", + Self::CmpNeU16 => "v_cmp_ne_u16_e32", + Self::CmpGeU16 => "v_cmp_ge_u16_e32", } } @@ -2956,6 +3028,18 @@ impl VectorCompareOp { Self::CmpTI64 => true, Self::CmpFU64 => false, Self::CmpTU64 => false, + Self::CmpLtI16 => true, + Self::CmpEqI16 => true, + Self::CmpLeI16 => true, + Self::CmpGtI16 => true, + Self::CmpNeI16 => true, + Self::CmpGeI16 => true, + Self::CmpLtU16 => false, + Self::CmpEqU16 => false, + Self::CmpLeU16 => false, + Self::CmpGtU16 => false, + Self::CmpNeU16 => false, + Self::CmpGeU16 => false, } } @@ -2994,6 +3078,18 @@ impl VectorCompareOp { Self::CmpTI64 => CompareRelation::True, Self::CmpFU64 => CompareRelation::False, Self::CmpTU64 => CompareRelation::True, + Self::CmpLtI16 => CompareRelation::Less, + Self::CmpEqI16 => CompareRelation::Equal, + Self::CmpLeI16 => CompareRelation::LessOrEqual, + Self::CmpGtI16 => CompareRelation::Greater, + Self::CmpNeI16 => CompareRelation::NotEqual, + Self::CmpGeI16 => CompareRelation::GreaterOrEqual, + Self::CmpLtU16 => CompareRelation::Less, + Self::CmpEqU16 => CompareRelation::Equal, + Self::CmpLeU16 => CompareRelation::LessOrEqual, + Self::CmpGtU16 => CompareRelation::Greater, + Self::CmpNeU16 => CompareRelation::NotEqual, + Self::CmpGeU16 => CompareRelation::GreaterOrEqual, } } @@ -3037,6 +3133,18 @@ impl VectorCompareOp { Self::CmpTI64 => primitive::true_b32(src0 as u32, src1 as u32), Self::CmpFU64 => primitive::false_b32(src0 as u32, src1 as u32), Self::CmpTU64 => primitive::true_b32(src0 as u32, src1 as u32), + Self::CmpLtI16 => (src0 as i16) < (src1 as i16), + Self::CmpEqI16 => (src0 as i16) == (src1 as i16), + Self::CmpLeI16 => (src0 as i16) <= (src1 as i16), + Self::CmpGtI16 => (src0 as i16) > (src1 as i16), + Self::CmpNeI16 => (src0 as i16) != (src1 as i16), + Self::CmpGeI16 => (src0 as i16) >= (src1 as i16), + Self::CmpLtU16 => (src0 as u16) < (src1 as u16), + Self::CmpEqU16 => (src0 as u16) == (src1 as u16), + Self::CmpLeU16 => (src0 as u16) <= (src1 as u16), + Self::CmpGtU16 => (src0 as u16) > (src1 as u16), + Self::CmpNeU16 => (src0 as u16) != (src1 as u16), + Self::CmpGeU16 => (src0 as u16) >= (src1 as u16), } } } @@ -3084,13 +3192,13 @@ impl VectorAluVop3Op { /// The validated registry row of this encoding. pub fn semantics(self) -> &'static FormSemantics { &FORMS[match self { - Self::AddNcU32 => 129, + Self::AddNcU32 => 141, }] } } /// Identity of every registry form and encoding variant, in registry order. -pub const FORM_IDS: [(&str, EncodingFamily); 130] = [ +pub const FORM_IDS: [(&str, EncodingFamily); 142] = [ ("S_ADD_U32", EncodingFamily::Sop2), ("S_SUB_U32", EncodingFamily::Sop2), ("S_ADD_I32", EncodingFamily::Sop2), @@ -3220,11 +3328,23 @@ pub const FORM_IDS: [(&str, EncodingFamily); 130] = [ ("V_CMP_T_I64", EncodingFamily::Vopc), ("V_CMP_F_U64", EncodingFamily::Vopc), ("V_CMP_T_U64", EncodingFamily::Vopc), + ("V_CMP_LT_I16", EncodingFamily::Vopc), + ("V_CMP_EQ_I16", EncodingFamily::Vopc), + ("V_CMP_LE_I16", EncodingFamily::Vopc), + ("V_CMP_GT_I16", EncodingFamily::Vopc), + ("V_CMP_NE_I16", EncodingFamily::Vopc), + ("V_CMP_GE_I16", EncodingFamily::Vopc), + ("V_CMP_LT_U16", EncodingFamily::Vopc), + ("V_CMP_EQ_U16", EncodingFamily::Vopc), + ("V_CMP_LE_U16", EncodingFamily::Vopc), + ("V_CMP_GT_U16", EncodingFamily::Vopc), + ("V_CMP_NE_U16", EncodingFamily::Vopc), + ("V_CMP_GE_U16", EncodingFamily::Vopc), ("V_ADD_NC_U32", EncodingFamily::Vop3), ]; /// One validated row per registry form, in registry order. -pub static FORMS: [FormSemantics; 130] = [ +pub static FORMS: [FormSemantics; 142] = [ FormSemantics { name: "S_ADD_U32", family: EncodingFamily::Sop2, @@ -5934,6 +6054,258 @@ pub static FORMS: [FormSemantics; 130] = [ spec: &[SpecRef { document: Document::Guide, section: "12.9", page: 150 }, SpecRef { document: Document::Guide, section: "3.9", page: 19 }], verify: &[Evidence::Reference, Evidence::Independent, Evidence::Metal], }, + FormSemantics { + name: "V_CMP_LT_I16", + family: EncodingFamily::Vopc, + opcode: 137, + operation: Operation::Compare, + signedness: Signedness::Signed, + carry_in: CarryIn::None, + width: 16, + shift_count_bits: 0, + shift_amount: 0, + swap_sources: false, + source_bits: 16, + relation: Some(CompareRelation::Less), + scc: SccEffect::Unchanged, + vcc: MaskEffect::LaneMask, + exec: MaskEffect::Unchanged, + wave: Wave::Wave32, + operands: OperandRule::VopcVccHalf, + spec: &[SpecRef { document: Document::Guide, section: "12.9", page: 150 }, SpecRef { document: Document::Guide, section: "3.9", page: 19 }], + verify: &[Evidence::Reference, Evidence::Independent, Evidence::Metal, Evidence::LlvmEncoding], + }, + FormSemantics { + name: "V_CMP_EQ_I16", + family: EncodingFamily::Vopc, + opcode: 138, + operation: Operation::Compare, + signedness: Signedness::Signed, + carry_in: CarryIn::None, + width: 16, + shift_count_bits: 0, + shift_amount: 0, + swap_sources: false, + source_bits: 16, + relation: Some(CompareRelation::Equal), + scc: SccEffect::Unchanged, + vcc: MaskEffect::LaneMask, + exec: MaskEffect::Unchanged, + wave: Wave::Wave32, + operands: OperandRule::VopcVccHalf, + spec: &[SpecRef { document: Document::Guide, section: "12.9", page: 150 }, SpecRef { document: Document::Guide, section: "3.9", page: 19 }], + verify: &[Evidence::Reference, Evidence::Independent, Evidence::Metal, Evidence::LlvmEncoding], + }, + FormSemantics { + name: "V_CMP_LE_I16", + family: EncodingFamily::Vopc, + opcode: 139, + operation: Operation::Compare, + signedness: Signedness::Signed, + carry_in: CarryIn::None, + width: 16, + shift_count_bits: 0, + shift_amount: 0, + swap_sources: false, + source_bits: 16, + relation: Some(CompareRelation::LessOrEqual), + scc: SccEffect::Unchanged, + vcc: MaskEffect::LaneMask, + exec: MaskEffect::Unchanged, + wave: Wave::Wave32, + operands: OperandRule::VopcVccHalf, + spec: &[SpecRef { document: Document::Guide, section: "12.9", page: 150 }, SpecRef { document: Document::Guide, section: "3.9", page: 19 }], + verify: &[Evidence::Reference, Evidence::Independent, Evidence::Metal, Evidence::LlvmEncoding], + }, + FormSemantics { + name: "V_CMP_GT_I16", + family: EncodingFamily::Vopc, + opcode: 140, + operation: Operation::Compare, + signedness: Signedness::Signed, + carry_in: CarryIn::None, + width: 16, + shift_count_bits: 0, + shift_amount: 0, + swap_sources: false, + source_bits: 16, + relation: Some(CompareRelation::Greater), + scc: SccEffect::Unchanged, + vcc: MaskEffect::LaneMask, + exec: MaskEffect::Unchanged, + wave: Wave::Wave32, + operands: OperandRule::VopcVccHalf, + spec: &[SpecRef { document: Document::Guide, section: "12.9", page: 150 }, SpecRef { document: Document::Guide, section: "3.9", page: 19 }], + verify: &[Evidence::Reference, Evidence::Independent, Evidence::Metal, Evidence::LlvmEncoding], + }, + FormSemantics { + name: "V_CMP_NE_I16", + family: EncodingFamily::Vopc, + opcode: 141, + operation: Operation::Compare, + signedness: Signedness::Signed, + carry_in: CarryIn::None, + width: 16, + shift_count_bits: 0, + shift_amount: 0, + swap_sources: false, + source_bits: 16, + relation: Some(CompareRelation::NotEqual), + scc: SccEffect::Unchanged, + vcc: MaskEffect::LaneMask, + exec: MaskEffect::Unchanged, + wave: Wave::Wave32, + operands: OperandRule::VopcVccHalf, + spec: &[SpecRef { document: Document::Guide, section: "12.9", page: 150 }, SpecRef { document: Document::Guide, section: "3.9", page: 19 }], + verify: &[Evidence::Reference, Evidence::Independent, Evidence::Metal, Evidence::LlvmEncoding], + }, + FormSemantics { + name: "V_CMP_GE_I16", + family: EncodingFamily::Vopc, + opcode: 142, + operation: Operation::Compare, + signedness: Signedness::Signed, + carry_in: CarryIn::None, + width: 16, + shift_count_bits: 0, + shift_amount: 0, + swap_sources: false, + source_bits: 16, + relation: Some(CompareRelation::GreaterOrEqual), + scc: SccEffect::Unchanged, + vcc: MaskEffect::LaneMask, + exec: MaskEffect::Unchanged, + wave: Wave::Wave32, + operands: OperandRule::VopcVccHalf, + spec: &[SpecRef { document: Document::Guide, section: "12.9", page: 150 }, SpecRef { document: Document::Guide, section: "3.9", page: 19 }], + verify: &[Evidence::Reference, Evidence::Independent, Evidence::Metal, Evidence::LlvmEncoding], + }, + FormSemantics { + name: "V_CMP_LT_U16", + family: EncodingFamily::Vopc, + opcode: 169, + operation: Operation::Compare, + signedness: Signedness::Unsigned, + carry_in: CarryIn::None, + width: 16, + shift_count_bits: 0, + shift_amount: 0, + swap_sources: false, + source_bits: 16, + relation: Some(CompareRelation::Less), + scc: SccEffect::Unchanged, + vcc: MaskEffect::LaneMask, + exec: MaskEffect::Unchanged, + wave: Wave::Wave32, + operands: OperandRule::VopcVccHalf, + spec: &[SpecRef { document: Document::Guide, section: "12.9", page: 150 }, SpecRef { document: Document::Guide, section: "3.9", page: 19 }], + verify: &[Evidence::Reference, Evidence::Independent, Evidence::Metal, Evidence::LlvmEncoding], + }, + FormSemantics { + name: "V_CMP_EQ_U16", + family: EncodingFamily::Vopc, + opcode: 170, + operation: Operation::Compare, + signedness: Signedness::Unsigned, + carry_in: CarryIn::None, + width: 16, + shift_count_bits: 0, + shift_amount: 0, + swap_sources: false, + source_bits: 16, + relation: Some(CompareRelation::Equal), + scc: SccEffect::Unchanged, + vcc: MaskEffect::LaneMask, + exec: MaskEffect::Unchanged, + wave: Wave::Wave32, + operands: OperandRule::VopcVccHalf, + spec: &[SpecRef { document: Document::Guide, section: "12.9", page: 150 }, SpecRef { document: Document::Guide, section: "3.9", page: 19 }], + verify: &[Evidence::Reference, Evidence::Independent, Evidence::Metal, Evidence::LlvmEncoding], + }, + FormSemantics { + name: "V_CMP_LE_U16", + family: EncodingFamily::Vopc, + opcode: 171, + operation: Operation::Compare, + signedness: Signedness::Unsigned, + carry_in: CarryIn::None, + width: 16, + shift_count_bits: 0, + shift_amount: 0, + swap_sources: false, + source_bits: 16, + relation: Some(CompareRelation::LessOrEqual), + scc: SccEffect::Unchanged, + vcc: MaskEffect::LaneMask, + exec: MaskEffect::Unchanged, + wave: Wave::Wave32, + operands: OperandRule::VopcVccHalf, + spec: &[SpecRef { document: Document::Guide, section: "12.9", page: 150 }, SpecRef { document: Document::Guide, section: "3.9", page: 19 }], + verify: &[Evidence::Reference, Evidence::Independent, Evidence::Metal, Evidence::LlvmEncoding], + }, + FormSemantics { + name: "V_CMP_GT_U16", + family: EncodingFamily::Vopc, + opcode: 172, + operation: Operation::Compare, + signedness: Signedness::Unsigned, + carry_in: CarryIn::None, + width: 16, + shift_count_bits: 0, + shift_amount: 0, + swap_sources: false, + source_bits: 16, + relation: Some(CompareRelation::Greater), + scc: SccEffect::Unchanged, + vcc: MaskEffect::LaneMask, + exec: MaskEffect::Unchanged, + wave: Wave::Wave32, + operands: OperandRule::VopcVccHalf, + spec: &[SpecRef { document: Document::Guide, section: "12.9", page: 150 }, SpecRef { document: Document::Guide, section: "3.9", page: 19 }], + verify: &[Evidence::Reference, Evidence::Independent, Evidence::Metal, Evidence::LlvmEncoding], + }, + FormSemantics { + name: "V_CMP_NE_U16", + family: EncodingFamily::Vopc, + opcode: 173, + operation: Operation::Compare, + signedness: Signedness::Unsigned, + carry_in: CarryIn::None, + width: 16, + shift_count_bits: 0, + shift_amount: 0, + swap_sources: false, + source_bits: 16, + relation: Some(CompareRelation::NotEqual), + scc: SccEffect::Unchanged, + vcc: MaskEffect::LaneMask, + exec: MaskEffect::Unchanged, + wave: Wave::Wave32, + operands: OperandRule::VopcVccHalf, + spec: &[SpecRef { document: Document::Guide, section: "12.9", page: 150 }, SpecRef { document: Document::Guide, section: "3.9", page: 19 }], + verify: &[Evidence::Reference, Evidence::Independent, Evidence::Metal, Evidence::LlvmEncoding], + }, + FormSemantics { + name: "V_CMP_GE_U16", + family: EncodingFamily::Vopc, + opcode: 174, + operation: Operation::Compare, + signedness: Signedness::Unsigned, + carry_in: CarryIn::None, + width: 16, + shift_count_bits: 0, + shift_amount: 0, + swap_sources: false, + source_bits: 16, + relation: Some(CompareRelation::GreaterOrEqual), + scc: SccEffect::Unchanged, + vcc: MaskEffect::LaneMask, + exec: MaskEffect::Unchanged, + wave: Wave::Wave32, + operands: OperandRule::VopcVccHalf, + spec: &[SpecRef { document: Document::Guide, section: "12.9", page: 150 }, SpecRef { document: Document::Guide, section: "3.9", page: 19 }], + verify: &[Evidence::Reference, Evidence::Independent, Evidence::Metal, Evidence::LlvmEncoding], + }, FormSemantics { name: "V_ADD_NC_U32", family: EncodingFamily::Vop3, diff --git a/crates/isa/tests/semantics.rs b/crates/isa/tests/semantics.rs index 7d3057c..7db8e65 100644 --- a/crates/isa/tests/semantics.rs +++ b/crates/isa/tests/semantics.rs @@ -168,6 +168,14 @@ fn vector_alu_dispatch_selects_exactly_the_registry_vop2_forms() { #[test] fn vector_compare_dispatch_selects_exactly_the_registry_vopc_forms() { + const OPERANDS16: [u64; 6] = [ + 0xaaaa_0000, + 0x5555_0001, + 0xdead_7fff, + 0x8000, + 0xfffe, + 0xffff, + ]; const OPERANDS32: [u64; 6] = [0, 1, 0x7fff_ffff, 0x8000_0000, 0xffff_fffe, 0xffff_ffff]; const OPERANDS64: [u64; 6] = [0, 1, u64::MAX >> 1, 1 << 63, u64::MAX - 1, u64::MAX]; for op in VectorCompareOp::ALL { @@ -188,14 +196,20 @@ fn vector_compare_dispatch_selects_exactly_the_registry_vopc_forms() { ); // The per-lane test is the declared relation over the declared // signedness, with SRC0 on the left. - let operands = if row.width == 64 { - OPERANDS64 - } else { - OPERANDS32 + let operands = match row.width { + 16 => OPERANDS16, + 64 => OPERANDS64, + _ => OPERANDS32, }; for src0 in operands { for src1 in operands { - let ordering = if op.signed() && row.width == 64 { + let ordering = if row.width == 16 { + if op.signed() { + (src0 as i16).cmp(&(src1 as i16)) + } else { + (src0 as u16).cmp(&(src1 as u16)) + } + } else if op.signed() && row.width == 64 { (src0 as i64).cmp(&(src1 as i64)) } else if op.signed() { (src0 as i32).cmp(&(src1 as i32)) @@ -221,7 +235,7 @@ fn vector_compare_dispatch_selects_exactly_the_registry_vopc_forms() { } } } - // v_cmpx and the 16-bit and float compares must not be dispatched. + // v_cmpx and the float compares must not be dispatched. dispatch_selects_exactly(EncodingFamily::Vopc, |word| { VectorCompareOp::from_word(word).map(|op| op.semantics().name) }); diff --git a/crates/shader/src/lib.rs b/crates/shader/src/lib.rs index f229ee6..7ea985e 100644 --- a/crates/shader/src/lib.rs +++ b/crates/shader/src/lib.rs @@ -225,7 +225,17 @@ fn compare_expression(op: VectorCompareOp, left: &str, right: &str) -> String { CompareRelation::False => return "false".to_owned(), CompareRelation::True => return "true".to_owned(), }; - if op.signed() && op.semantics().width == 64 { + if op.semantics().width == 16 { + // Guide §§6.2, 6.2.5 and 6.8: the e32 form reads the low half. + let half = |value| { + if op.signed() { + format!("as_type(ushort({value}))") + } else { + format!("ushort({value})") + } + }; + format!("{} {symbol} {}", half(left), half(right)) + } else if op.signed() && op.semantics().width == 64 { format!("as_type({left}) {symbol} as_type({right})") } else if op.signed() { format!("as_type({left}) {symbol} as_type({right})") diff --git a/docs/assets/xenora-progress.svg b/docs/assets/xenora-progress.svg index b9ee462..c275380 100644 --- a/docs/assets/xenora-progress.svg +++ b/docs/assets/xenora-progress.svg @@ -1,17 +1,17 @@ Xenora · recorded progress -Decoded gfx1030 forms: 142 of 142. Accepted Metal forms · Apple M5: 18 of 142. Accepted guest milestones · X1–X4: 4 of 4 +Decoded gfx1030 forms: 154 of 154. Accepted Metal forms · Apple M5: 18 of 154. Accepted guest milestones · X1–X4: 4 of 4 RECORDED FIXTURE PROGRESS Decoded gfx1030 forms -142 / 142 +154 / 154 Accepted Metal forms · Apple M5 -18 / 142 +18 / 154 - + Accepted guest milestones · X1–X4 4 / 4 diff --git a/docs/shaders/instruction-coverage.md b/docs/shaders/instruction-coverage.md index 8370be6..82fc2cc 100644 --- a/docs/shaders/instruction-coverage.md +++ b/docs/shaders/instruction-coverage.md @@ -109,6 +109,18 @@ The wider LLVM operand matrix exercises decoding only. ABI means application bin | `v_cmp_t_i32_e32` | VOPC, Wave32; VGPR, normal SGPR (known during translation), vcc_lo, inline integer or literal SRC0 (signed); VGPR VSRC1; VCC_LO[n] = EXEC_LO[n] & true, fully written | `7D0E0501` | yes | yes | three-way passed | per-thread Wave32 mask over the dispatch's own 32 lanes, reading no operand bits; runtime s_cbranch_vccz as a join select | implemented | local known-answer test passed | local Apple M5 readback passed; acceptance pending | | `v_cmp_f_u32_e32` | VOPC, Wave32; VGPR, normal SGPR (known during translation), vcc_lo, inline integer or literal SRC0 (unsigned); VGPR VSRC1; VCC_LO[n] = EXEC_LO[n] & false, fully written | `7D800501` | yes | yes | three-way passed | per-thread Wave32 mask over the dispatch's own 32 lanes, reading no operand bits; runtime s_cbranch_vccz as a join select | implemented | local known-answer test passed | local Apple M5 readback passed; acceptance pending | | `v_cmp_t_u32_e32` | VOPC, Wave32; VGPR, normal SGPR (known during translation), vcc_lo, inline integer or literal SRC0 (unsigned); VGPR VSRC1; VCC_LO[n] = EXEC_LO[n] & true, fully written | `7D8E0501` | yes | yes | three-way passed | per-thread Wave32 mask over the dispatch's own 32 lanes, reading no operand bits; runtime s_cbranch_vccz as a join select | implemented | local known-answer test passed | local Apple M5 readback passed; acceptance pending | +| `v_cmp_lt_i16_e32` | VOPC, Wave32; VGPR, known SGPR, VCC_LO or inline integer SRC0; VGPR VSRC1; signed low 16 bits; VCC_LO[n] = EXEC_LO[n] & (S0 < S1), fully written | `7D120702` | yes | yes | three-way passed | per-thread Wave32 mask with low-half operands | implemented | local known-answer test passed | acceptance pending | +| `v_cmp_eq_i16_e32` | VOPC, Wave32; VGPR, known SGPR, VCC_LO or inline integer SRC0; VGPR VSRC1; signed low 16 bits; VCC_LO[n] = EXEC_LO[n] & (S0 == S1), fully written | `7D140702` | yes | yes | three-way passed | per-thread Wave32 mask with low-half operands | implemented | local known-answer test passed | acceptance pending | +| `v_cmp_le_i16_e32` | VOPC, Wave32; VGPR, known SGPR, VCC_LO or inline integer SRC0; VGPR VSRC1; signed low 16 bits; VCC_LO[n] = EXEC_LO[n] & (S0 <= S1), fully written | `7D160702` | yes | yes | three-way passed | per-thread Wave32 mask with low-half operands | implemented | local known-answer test passed | acceptance pending | +| `v_cmp_gt_i16_e32` | VOPC, Wave32; VGPR, known SGPR, VCC_LO or inline integer SRC0; VGPR VSRC1; signed low 16 bits; VCC_LO[n] = EXEC_LO[n] & (S0 > S1), fully written | `7D180702` | yes | yes | three-way passed | per-thread Wave32 mask with low-half operands | implemented | local known-answer test passed | acceptance pending | +| `v_cmp_ne_i16_e32` | VOPC, Wave32; VGPR, known SGPR, VCC_LO or inline integer SRC0; VGPR VSRC1; signed low 16 bits; VCC_LO[n] = EXEC_LO[n] & (S0 != S1), fully written | `7D1A0702` | yes | yes | three-way passed | per-thread Wave32 mask with low-half operands | implemented | local known-answer test passed | acceptance pending | +| `v_cmp_ge_i16_e32` | VOPC, Wave32; VGPR, known SGPR, VCC_LO or inline integer SRC0; VGPR VSRC1; signed low 16 bits; VCC_LO[n] = EXEC_LO[n] & (S0 >= S1), fully written | `7D1C0702` | yes | yes | three-way passed | per-thread Wave32 mask with low-half operands | implemented | local known-answer test passed | acceptance pending | +| `v_cmp_lt_u16_e32` | VOPC, Wave32; VGPR, known SGPR, VCC_LO or inline integer SRC0; VGPR VSRC1; unsigned low 16 bits; VCC_LO[n] = EXEC_LO[n] & (S0 < S1), fully written | `7D520702` | yes | yes | three-way passed | per-thread Wave32 mask with low-half operands | implemented | local known-answer test passed | acceptance pending | +| `v_cmp_eq_u16_e32` | VOPC, Wave32; VGPR, known SGPR, VCC_LO or inline integer SRC0; VGPR VSRC1; unsigned low 16 bits; VCC_LO[n] = EXEC_LO[n] & (S0 == S1), fully written | `7D540702` | yes | yes | three-way passed | per-thread Wave32 mask with low-half operands | implemented | local known-answer test passed | acceptance pending | +| `v_cmp_le_u16_e32` | VOPC, Wave32; VGPR, known SGPR, VCC_LO or inline integer SRC0; VGPR VSRC1; unsigned low 16 bits; VCC_LO[n] = EXEC_LO[n] & (S0 <= S1), fully written | `7D560702` | yes | yes | three-way passed | per-thread Wave32 mask with low-half operands | implemented | local known-answer test passed | acceptance pending | +| `v_cmp_gt_u16_e32` | VOPC, Wave32; VGPR, known SGPR, VCC_LO or inline integer SRC0; VGPR VSRC1; unsigned low 16 bits; VCC_LO[n] = EXEC_LO[n] & (S0 > S1), fully written | `7D580702` | yes | yes | three-way passed | per-thread Wave32 mask with low-half operands | implemented | local known-answer test passed | acceptance pending | +| `v_cmp_ne_u16_e32` | VOPC, Wave32; VGPR, known SGPR, VCC_LO or inline integer SRC0; VGPR VSRC1; unsigned low 16 bits; VCC_LO[n] = EXEC_LO[n] & (S0 != S1), fully written | `7D5A0702` | yes | yes | three-way passed | per-thread Wave32 mask with low-half operands | implemented | local known-answer test passed | acceptance pending | +| `v_cmp_ge_u16_e32` | VOPC, Wave32; VGPR, known SGPR, VCC_LO or inline integer SRC0; VGPR VSRC1; unsigned low 16 bits; VCC_LO[n] = EXEC_LO[n] & (S0 >= S1), fully written | `7D5C0702` | yes | yes | three-way passed | per-thread Wave32 mask with low-half operands | implemented | local known-answer test passed | acceptance pending | | `v_cmp_f_i64_e32` | VOPC, Wave32; VGPR pair, known even SGPR pair or sign-extended inline integer SRC0; VGPR pair VSRC1; signed 64-bit operands; VCC_LO[n] = EXEC_LO[n] & (false), fully written | `7D400902` | yes | yes | assembled fixture matched | per-thread Wave32 mask with 64-bit operands | implemented | local known-answer test passed | local Apple M5 readback passed; acceptance pending | | `v_cmp_lt_i64_e32` | VOPC, Wave32; VGPR pair, known even SGPR pair or sign-extended inline integer SRC0; VGPR pair VSRC1; signed 64-bit operands; VCC_LO[n] = EXEC_LO[n] & (S0 < S1), fully written | `7D420902` | yes | yes | assembled fixture matched | per-thread Wave32 mask with 64-bit operands | implemented | local known-answer test passed | local Apple M5 readback passed; acceptance pending | | `v_cmp_eq_i64_e32` | VOPC, Wave32; VGPR pair, known even SGPR pair or sign-extended inline integer SRC0; VGPR pair VSRC1; signed 64-bit operands; VCC_LO[n] = EXEC_LO[n] & (S0 == S1), fully written | `7D440902` | yes | yes | assembled fixture matched | per-thread Wave32 mask with 64-bit operands | implemented | local known-answer test passed | local Apple M5 readback passed; acceptance pending | diff --git a/docs/shaders/semantic-coverage.md b/docs/shaders/semantic-coverage.md index d3e1bbd..9dcfeed 100644 --- a/docs/shaders/semantic-coverage.md +++ b/docs/shaders/semantic-coverage.md @@ -35,8 +35,8 @@ acceptance remain outside the verified count. All results concern synthetic fixt | VOP3 | 416 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 12 | | VOP3P | 29 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | | VOP3SDST | 10 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | -| VOPC | 190 | 16 | 32 | 32 | 32 | 32 | 0 | 0 | 9 | -| **Total** | 1465 | 126 | 130 | 146 | 142 | 142 | 18 | 18 | 78 | +| VOPC | 190 | 28 | 44 | 44 | 44 | 44 | 0 | 0 | 9 | +| **Total** | 1465 | 138 | 142 | 158 | 154 | 154 | 18 | 18 | 78 | ## Unsupported operand variants @@ -56,4 +56,5 @@ The table counts distinct variant names per family across registry operand rules | VOP2 | `vop2_vgpr2` | `src_exec`, `src_float_inline`, `src_inline`, `src_literal`, `src_m0`, `src_null`, `src_sgpr`, `src_special`, `src_ttmp`, `src_vcc` | | VOP3 | `vop3_vgpr2` | `modifiers`, `src2`, `src_exec`, `src_float_inline`, `src_inline`, `src_literal`, `src_m0`, `src_null`, `src_sgpr`, `src_special`, `src_ttmp`, `src_vcc` | | VOPC | `vopc_vcc` | `src_exec`, `src_float_inline`, `src_m0`, `src_null`, `src_special`, `src_ttmp`, `src_vcc_hi` | +| VOPC | `vopc_vcc_half` | `src_exec`, `src_float_inline`, `src_literal`, `src_m0`, `src_null`, `src_special`, `src_ttmp`, `src_vcc_hi` | | VOPC | `vopc_vcc_pair` | `src_exec`, `src_float_inline`, `src_literal`, `src_m0`, `src_null`, `src_special`, `src_ttmp`, `src_vcc` | diff --git a/docs/shaders/semantic-registry.md b/docs/shaders/semantic-registry.md index 9ae7bf3..4a278ed 100644 --- a/docs/shaders/semantic-registry.md +++ b/docs/shaders/semantic-registry.md @@ -112,7 +112,7 @@ error. | `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 (operand width for compares) | `32`, or `64` with `vopc_vcc_pair` | +| `width` | Operand and result width in bits (operand width for compares) | `32`, `16` with `vopc_vcc_half`, or `64` with `vopc_vcc_pair` | | `source_bits` | Sign extension only: the low bits of S0 that are read. The XML must list S0 with that size and format (`FMT_NUM_I8` or `FMT_NUM_I16`) | `8`, `16`; required for `sext`, rejected elsewhere | | `relation` | Compares only: the relation tested with S0 on the left | `eq`, `lg` (not equal), `gt`, `ge`, `lt`, `le`; required for `compare`, rejected elsewhere | | `source_order` | Vector forms only: `reversed` when the guide computes `op(S1, S0)` (the XML records no operand order); absent otherwise | `reversed` | @@ -185,9 +185,11 @@ shifts declare `source_order = "reversed"` (D = S1 shifted by S0[4:0]), so the generator checks the XML's unsigned count format on SRC0, not VSRC1. VOPC compares (kind `vector_compare`) write `vcc_lo`. The 32-bit rule -`vopc_vcc` accepts a `vector_source` as for VOP2 and a VGPR. The 64-bit rule +`vopc_vcc` accepts a `vector_source` as for VOP2 and a VGPR. The 16-bit rule +`vopc_vcc_half` reads the low half of the same source types and rejects +literals (guide sections 6.2, 6.2.5 and 6.8). The 64-bit rule `vopc_vcc_pair` accepts a VGPR pair, an even normal SGPR pair or an inline -integer as SRC0 and a VGPR pair as VSRC1. Both declare a `relation`, +integer as SRC0 and a VGPR pair as VSRC1. All three declare a `relation`, `scc = "unchanged"`, `vcc = "lane_mask"` and `wave = "wave32"`. The XML's implicit 64-bit VCC output must be present and is accounted for by `lane_mask`. Signedness still matters for `eq` and `lg`, because the MSL lowering casts signed operands. @@ -221,7 +223,8 @@ vocabularies above, it rejects: - contradictions: a declared `scc` or `carry_in` that the primitive does not have, `bitwise` on an arithmetic operation or the reverse; - VOPC compares whose opcode is not the group base (128 and 192 for signed and - unsigned 32-bit forms, 160 and 224 for their 64-bit counterparts) plus the relation's offset in guide Table 59 (F 0, LT 1, + unsigned 32-bit forms, 136 and 168 for 16-bit forms, 160 and 224 for 64-bit + forms) plus the relation's offset in guide Table 59 (F 0, LT 1, EQ 2, LE 3, GT 4, LG/NE 5, GE 6, T 7), and a `lane_mask` form whose XML does not have exactly one implicit VCC operand that is written and not read; - duplicates: the same `name`, the same `(family, opcode)`, or the same diff --git a/docs/shaders/vector-compare.md b/docs/shaders/vector-compare.md index 086cbec..b2ba4dd 100644 --- a/docs/shaders/vector-compare.md +++ b/docs/shaders/vector-compare.md @@ -77,16 +77,16 @@ using this ABI; there is no Wave64 entry point to reject. ### 2a. 16-bit and 64-bit compares -The reference (`crates/ref`) and the second interpreter -(`tests/validation/independent_ref.rs`) also accept the `_e32` forms -`v_cmp_{lt,eq,le,gt,ne,ge}_{i16,u16}` (opcodes 137-142, 169-174) and -`v_cmp_{f,lt,eq,le,gt,ne,ge,t}_{i64,u64}` (160-167, 224-231). The decoder and -translator support the 64-bit forms through the `vopc_vcc_pair` operand rule. -The 16-bit forms are available only in the interpreters. +The decoder, translator and both reference interpreters accept the `_e32` +forms `v_cmp_{lt,eq,le,gt,ne,ge}_{i16,u16}` (opcodes 137–142, 169–174) and +`v_cmp_{f,lt,eq,le,gt,ne,ge,t}_{i64,u64}` (160–167, 224–231). The registry +uses `vopc_vcc_half` for the 16-bit forms and `vopc_vcc_pair` for the 64-bit +forms. - 16-bit forms read bits 15:0 of each 32-bit source and ignore bits 31:16 (an inference from guide 6.2, 6.2.5 and 6.8: only SDWA selects a half). - There is no literal source. + SRC0 accepts a VGPR, a known SGPR, `vcc_lo` or an inline integer + (for example, −1 supplies `0xffff`). VSRC1 is a VGPR. Literals are rejected. - 64-bit forms read a pair: v[n:n+1] with n <= 254, an even-aligned s[2k:2k+1] with k <= 52 (3.6.3), or an inline integer, which is sign-extended to 64 bits (-1 is all ones, also for `_u64`; a reading of @@ -254,13 +254,14 @@ run in `vopc_f_t_match_the_guide_on_native_metal`. The 16-bit and 64-bit oracle (`tests/validation/tests/vopc_wide.rs`) checks 6,212 cases on both reference interpreters, plus 1,208 rejections and 13 -neighbouring opcodes. CPU tests check compilation of the 4,640 64-bit cases -and rejection of out-of-contract 64-bit operands and all 12 16-bit forms. -The LLVM-assembled `fixtures/rdna2/vector-compare-64.s` covers all sixteen -64-bit opcodes in the decoder's fixture inventory. -`scripts/test-gpu.sh` includes `vopc64_match_the_guide_on_native_metal` and -skips `vopc16_match_the_guide_on_native_metal`. On a local Apple M5 under API and -shader validation, all 4,640 64-bit cases (3,818 programs) agree; acceptance is pending. Deliberately broken copies of both +neighbouring opcodes. CPU tests check compilation of 1,572 16-bit and 4,640 +64-bit cases, plus compiler rejection of out-of-contract programs. LLVM +assembled `vector-compare-16.s` and `vector-compare-64.s` cover all 28 opcodes +in the decoder's fixture inventory. The native Metal gate runs both +`vopc16_match_the_guide_on_native_metal` and +`vopc64_match_the_guide_on_native_metal`. On a local Apple M5 with API and +shader validation, all 4,640 64-bit cases (3,818 programs) agree with the +oracle. The 16-bit Metal run and independent acceptance are pending. Deliberately broken copies of both interpreters (16-bit reads of 32 bits, swapped pair halves, zero-extended inline integers, flipped signedness, reads under empty EXEC and others) each fail it. @@ -274,13 +275,12 @@ swapped signedness, without the EXEC mask, without the absent-lane bound (shader validation aborts on the out-of-range read) or with an inverted join. The 32-bit readback evidence is local agreement with a specification-derived -reference on Apple M5 Pro. The 64-bit compiler evidence is CPU-only. +reference on Apple M5 Pro. The 16-bit compiler evidence is CPU-only. There is no RDNA 2 or Xbox hardware evidence. ## 10. Limitations -- Wave32 only. No `v_cmpx`, VOP3, SDWA, DPP or float compares. The 16-bit - compares are available only in the reference interpreters (2a). +- Wave32 only. No `v_cmpx`, VOP3, SDWA, DPP or float compares. - A lane-derived VCC_LO cannot reach EXEC or any scalar instruction, so there is no divergent execution. That needs its own contract. - The skipped region of a runtime `s_cbranch_vccz` holds only integer vector diff --git a/docs/status.toml b/docs/status.toml index 25c9abb..5d65f37 100644 --- a/docs/status.toml +++ b/docs/status.toml @@ -1190,6 +1190,150 @@ recognized = true decoded = true llvm = "three-way passed" +[[instruction]] +form = "v_cmp_lt_i16_e32" +encoding = "VOPC, Wave32; VGPR, known SGPR, VCC_LO or inline integer SRC0; VGPR VSRC1; signed low 16 bits; VCC_LO[n] = EXEC_LO[n] & (S0 < S1), fully written" +representation = "`7D120702`" +lowering = "per-thread Wave32 mask with low-half operands" +reference = "implemented" +cpu = "local known-answer test passed" +gpu = "acceptance pending" +recognized = true +decoded = true +llvm = "three-way passed" + +[[instruction]] +form = "v_cmp_eq_i16_e32" +encoding = "VOPC, Wave32; VGPR, known SGPR, VCC_LO or inline integer SRC0; VGPR VSRC1; signed low 16 bits; VCC_LO[n] = EXEC_LO[n] & (S0 == S1), fully written" +representation = "`7D140702`" +lowering = "per-thread Wave32 mask with low-half operands" +reference = "implemented" +cpu = "local known-answer test passed" +gpu = "acceptance pending" +recognized = true +decoded = true +llvm = "three-way passed" + +[[instruction]] +form = "v_cmp_le_i16_e32" +encoding = "VOPC, Wave32; VGPR, known SGPR, VCC_LO or inline integer SRC0; VGPR VSRC1; signed low 16 bits; VCC_LO[n] = EXEC_LO[n] & (S0 <= S1), fully written" +representation = "`7D160702`" +lowering = "per-thread Wave32 mask with low-half operands" +reference = "implemented" +cpu = "local known-answer test passed" +gpu = "acceptance pending" +recognized = true +decoded = true +llvm = "three-way passed" + +[[instruction]] +form = "v_cmp_gt_i16_e32" +encoding = "VOPC, Wave32; VGPR, known SGPR, VCC_LO or inline integer SRC0; VGPR VSRC1; signed low 16 bits; VCC_LO[n] = EXEC_LO[n] & (S0 > S1), fully written" +representation = "`7D180702`" +lowering = "per-thread Wave32 mask with low-half operands" +reference = "implemented" +cpu = "local known-answer test passed" +gpu = "acceptance pending" +recognized = true +decoded = true +llvm = "three-way passed" + +[[instruction]] +form = "v_cmp_ne_i16_e32" +encoding = "VOPC, Wave32; VGPR, known SGPR, VCC_LO or inline integer SRC0; VGPR VSRC1; signed low 16 bits; VCC_LO[n] = EXEC_LO[n] & (S0 != S1), fully written" +representation = "`7D1A0702`" +lowering = "per-thread Wave32 mask with low-half operands" +reference = "implemented" +cpu = "local known-answer test passed" +gpu = "acceptance pending" +recognized = true +decoded = true +llvm = "three-way passed" + +[[instruction]] +form = "v_cmp_ge_i16_e32" +encoding = "VOPC, Wave32; VGPR, known SGPR, VCC_LO or inline integer SRC0; VGPR VSRC1; signed low 16 bits; VCC_LO[n] = EXEC_LO[n] & (S0 >= S1), fully written" +representation = "`7D1C0702`" +lowering = "per-thread Wave32 mask with low-half operands" +reference = "implemented" +cpu = "local known-answer test passed" +gpu = "acceptance pending" +recognized = true +decoded = true +llvm = "three-way passed" + +[[instruction]] +form = "v_cmp_lt_u16_e32" +encoding = "VOPC, Wave32; VGPR, known SGPR, VCC_LO or inline integer SRC0; VGPR VSRC1; unsigned low 16 bits; VCC_LO[n] = EXEC_LO[n] & (S0 < S1), fully written" +representation = "`7D520702`" +lowering = "per-thread Wave32 mask with low-half operands" +reference = "implemented" +cpu = "local known-answer test passed" +gpu = "acceptance pending" +recognized = true +decoded = true +llvm = "three-way passed" + +[[instruction]] +form = "v_cmp_eq_u16_e32" +encoding = "VOPC, Wave32; VGPR, known SGPR, VCC_LO or inline integer SRC0; VGPR VSRC1; unsigned low 16 bits; VCC_LO[n] = EXEC_LO[n] & (S0 == S1), fully written" +representation = "`7D540702`" +lowering = "per-thread Wave32 mask with low-half operands" +reference = "implemented" +cpu = "local known-answer test passed" +gpu = "acceptance pending" +recognized = true +decoded = true +llvm = "three-way passed" + +[[instruction]] +form = "v_cmp_le_u16_e32" +encoding = "VOPC, Wave32; VGPR, known SGPR, VCC_LO or inline integer SRC0; VGPR VSRC1; unsigned low 16 bits; VCC_LO[n] = EXEC_LO[n] & (S0 <= S1), fully written" +representation = "`7D560702`" +lowering = "per-thread Wave32 mask with low-half operands" +reference = "implemented" +cpu = "local known-answer test passed" +gpu = "acceptance pending" +recognized = true +decoded = true +llvm = "three-way passed" + +[[instruction]] +form = "v_cmp_gt_u16_e32" +encoding = "VOPC, Wave32; VGPR, known SGPR, VCC_LO or inline integer SRC0; VGPR VSRC1; unsigned low 16 bits; VCC_LO[n] = EXEC_LO[n] & (S0 > S1), fully written" +representation = "`7D580702`" +lowering = "per-thread Wave32 mask with low-half operands" +reference = "implemented" +cpu = "local known-answer test passed" +gpu = "acceptance pending" +recognized = true +decoded = true +llvm = "three-way passed" + +[[instruction]] +form = "v_cmp_ne_u16_e32" +encoding = "VOPC, Wave32; VGPR, known SGPR, VCC_LO or inline integer SRC0; VGPR VSRC1; unsigned low 16 bits; VCC_LO[n] = EXEC_LO[n] & (S0 != S1), fully written" +representation = "`7D5A0702`" +lowering = "per-thread Wave32 mask with low-half operands" +reference = "implemented" +cpu = "local known-answer test passed" +gpu = "acceptance pending" +recognized = true +decoded = true +llvm = "three-way passed" + +[[instruction]] +form = "v_cmp_ge_u16_e32" +encoding = "VOPC, Wave32; VGPR, known SGPR, VCC_LO or inline integer SRC0; VGPR VSRC1; unsigned low 16 bits; VCC_LO[n] = EXEC_LO[n] & (S0 >= S1), fully written" +representation = "`7D5C0702`" +lowering = "per-thread Wave32 mask with low-half operands" +reference = "implemented" +cpu = "local known-answer test passed" +gpu = "acceptance pending" +recognized = true +decoded = true +llvm = "three-way passed" + [[instruction]] form = "v_cmp_f_i64_e32" encoding = "VOPC, Wave32; VGPR pair, known even SGPR pair or sign-extended inline integer SRC0; VGPR pair VSRC1; signed 64-bit operands; VCC_LO[n] = EXEC_LO[n] & (false), fully written" diff --git a/fixtures/rdna2/vector-compare-16.bin b/fixtures/rdna2/vector-compare-16.bin new file mode 100644 index 0000000000000000000000000000000000000000..1dee37d792df4949c330cee97e3fe69d6191648c GIT binary patch literal 84 zcmZQjFnGYg#L!S+-?P7+iLH)_U8t6cT?B~5fLH>ErGQulh=YJQ1c<|cI0A^HfH24e#Q!{6Nu42}B%2F(+1 literal 0 HcmV?d00001 diff --git a/fixtures/rdna2/vector-compare-16.s b/fixtures/rdna2/vector-compare-16.s new file mode 100644 index 0000000..3fc9f17 --- /dev/null +++ b/fixtures/rdna2/vector-compare-16.s @@ -0,0 +1,23 @@ +// SPDX-License-Identifier: GPL-3.0-or-later +// Encoding inventory for Wave32 16-bit VOPC compares (guide Table 61). +// Operand and execution cases are in tests/validation/tests/vopc_wide.rs. +.text +buffer_load_dword v2, v0, s[0:3], 0 idxen +s_waitcnt vmcnt(0) +v_mov_b32_e32 v3, 7 +v_cmp_lt_i16_e32 vcc_lo, v2, v3 +v_cmp_eq_i16_e32 vcc_lo, v2, v3 +v_cmp_le_i16_e32 vcc_lo, v2, v3 +v_cmp_gt_i16_e32 vcc_lo, v2, v3 +v_cmp_ne_i16_e32 vcc_lo, v2, v3 +v_cmp_ge_i16_e32 vcc_lo, v2, v3 +v_cmp_lt_u16_e32 vcc_lo, v2, v3 +v_cmp_eq_u16_e32 vcc_lo, v2, v3 +v_cmp_le_u16_e32 vcc_lo, v2, v3 +v_cmp_gt_u16_e32 vcc_lo, v2, v3 +v_cmp_ne_u16_e32 vcc_lo, v2, v3 +v_cmp_ge_u16_e32 vcc_lo, v2, v3 +v_mov_b32_e32 v2, vcc_lo +buffer_store_dword v2, v0, s[4:7], 0 idxen +s_waitcnt_vscnt null, 0 +s_endpgm diff --git a/scripts/assemble-fixture.sh b/scripts/assemble-fixture.sh index f6ccfc1..9a39f90 100755 --- a/scripts/assemble-fixture.sh +++ b/scripts/assemble-fixture.sh @@ -12,7 +12,7 @@ case "${1:-}" in esac for name in add bitwise-branch float-exact or shifts ashr \ - x9-constant-vs x9-constant-ps x9-varying-vs x9-varying-ps x9-transform-vs scalar-alu vector-compare scalar-logic scalar-compare scalar-unary scalar-arith scalar-immediate vector-integer vector-compare-ft vector-unary vector-compare-64; do + x9-constant-vs x9-constant-ps x9-varying-vs x9-varying-ps x9-transform-vs scalar-alu vector-compare scalar-logic scalar-compare scalar-unary scalar-arith scalar-immediate vector-integer vector-compare-ft vector-unary vector-compare-64 vector-compare-16; do "$llvm_bin/llvm-mc" -triple=amdgcn-amd-amdhsa -mcpu=gfx1030 -mattr=+wavefrontsize32 \ -filetype=obj "fixtures/rdna2/$name.s" -o "$scratch/$name.o" "$llvm_bin/llvm-objcopy" -O binary --only-section=.text "$scratch/$name.o" "$scratch/$name.bin" diff --git a/scripts/test-gpu.sh b/scripts/test-gpu.sh index 342fcbd3..9627db8 100755 --- a/scripts/test-gpu.sh +++ b/scripts/test-gpu.sh @@ -53,7 +53,4 @@ timeout 30s cargo test --locked -p xenora-ffi --features gpu-tests --test audio_ # Native Metal known answers of the independent semantic review, including SOP2 scalar ALU # and VOPC compares. cargo test --locked -p xenora-semantic-review --no-run -# Oracles whose translator side has not landed are skipped by name until it does -# (#215: the PR that translates the forms removes its skip). -timeout 120s cargo test --locked -p xenora-semantic-review -- --ignored --nocapture --test-threads=1 \ - --skip vopc16_match_the_guide_on_native_metal +timeout 120s cargo test --locked -p xenora-semantic-review -- --ignored --nocapture --test-threads=1 diff --git a/tests/validation/tests/vopc_wide.rs b/tests/validation/tests/vopc_wide.rs index 61ab83b..861739e 100644 --- a/tests/validation/tests/vopc_wide.rs +++ b/tests/validation/tests/vopc_wide.rs @@ -11,9 +11,7 @@ //! 6.2 (Table 20 and 6.2.1), 6.2.5, 6.8 and 9.1. Nothing here comes from the //! ISA crate, the semantic registry, the decoder or the shader compiler. Every //! case runs on the reference interpreter `xenora_ref` and on the second -//! interpreter `independent_ref`. The native Metal gate includes the 64-bit -//! cases. The 16-bit Metal cases remain skipped while the compiler rejects -//! those forms. +//! interpreter `independent_ref`. The native Metal gate includes both widths. //! //! Readings of the guide (not hardware evidence): //! - Table 59: offsets F 0, LT 1, EQ 2, LE 3, GT 4, LG/NE 5, GE 6, TRU 7 with @@ -1169,10 +1167,34 @@ fn vopc_wide_outside_the_contract_are_rejected() { } #[test] -fn production_compiler_still_rejects_the_16_bit_compares() { - for form in forms().into_iter().filter(|form| form.bits == 16) { - let (code, offset) = program(&vmov(3, 7), None, &[vopc(form.op, vgpr(1), 3)], &[]); - assert_compiler_rejected_at(form.name, &code, offset); +fn production_compiler_lowers_the_16_bit_compares() { + let cases = cases_at_width(16); + harness::check_reference(&cases).assert_none("16-bit compare compilation and reference"); + check_compiler_rejections(16); + eprintln!("vopc16: {} compiler acceptance cases", cases.len()); +} + +#[test] +fn production_compiler_emits_signed_and_unsigned_low_half_relations() { + for (name, signed) in [("v_cmp_lt_i16", true), ("v_cmp_lt_u16", false)] { + let code = code(&vmov(3, 7), None, &[vopc(form(name).op, 193, 3)]); + let shader = compile(Architecture::Gfx1030, &code).unwrap(); + let predicate = shader + .msl + .lines() + .find(|line| line.contains("uint pass = (")) + .unwrap(); + let cast = if signed { + "as_type(ushort(" + } else { + "ushort(" + }; + assert_eq!(predicate.matches(cast).count(), 2, "{name}: {predicate}"); + assert!(!predicate.contains(">>"), "{name}: {predicate}"); + assert_eq!( + predicate.matches("as_type(").count(), + if signed { 2 } else { 0 } + ); } } @@ -1268,7 +1290,7 @@ fn vopc64_match_the_guide_on_native_metal() { } #[test] -#[ignore = "requires the translator's 16-bit forms and native Metal validation"] +#[ignore = "requires a native Metal device with API and shader validation"] fn vopc16_match_the_guide_on_native_metal() { check_compiler_rejections(16); check_native_metal(16);