From b559fb575ca14e453fa4f6a02fabff3b43c360cc Mon Sep 17 00:00:00 2001 From: elforeign <324243036+elforeign@users.noreply.github.com> Date: Tue, 24 Nov 2026 07:38:55 -0600 Subject: [PATCH] isa, decoder, shader: v_cmp_{f,t}_{i32,u32} through the semantic registry (#215) Adds the four constant Wave32 VOPC compares as registry forms with the relations f and t (guide Table 59 offsets 0 and 7), valid only for the vopc_vcc rule, backed by false_b32/true_b32 primitives. They keep the #239 contract: sources are decoded and checked as for every compare, VCC_LO := EXEC & existing lanes & test, fully written, and the mask is lane-derived. Their MSL wave mask reads no operand bits. A new LLVM-assembled fixture covers F clearing a stale VCC, T and F under partial EXEC, T reading vcc_lo and runtime s_cbranch_vccz on both results; the oracle merged from task/215-vopc-oracle supplies the reference side. Signed-off-by: elforeign <324243036+elforeign@users.noreply.github.com> --- CHANGELOG.md | 1 + crates/decoder/tests/gfx1030.rs | 9 +- crates/isa/generate_semantics.py | 8 +- crates/isa/semantics/rdna2.toml | 89 +++++++++++ crates/isa/src/lib.rs | 4 + crates/isa/src/primitive.rs | 10 ++ crates/isa/src/semantics_gen.rs | 138 +++++++++++++++++- crates/isa/tests/semantics.rs | 4 +- crates/shader/src/lib.rs | 13 +- crates/shader/tests/compiler.rs | 14 ++ docs/assets/xenora-progress.svg | 8 +- docs/shaders/instruction-coverage.md | 4 + docs/shaders/reference-interpreter.md | 2 +- docs/shaders/semantic-coverage.md | 4 +- docs/shaders/vector-compare.md | 12 +- docs/status.toml | 48 ++++++ fixtures/golden/vector-compare-ft.ir | 28 ++++ fixtures/golden/vector-compare-ft.metal | 76 ++++++++++ fixtures/rdna2/vector-compare-ft.bin | Bin 0 -> 164 bytes fixtures/rdna2/vector-compare-ft.s | 45 ++++++ scripts/assemble-fixture.sh | 2 +- .../test_generate_semantics.py | 16 ++ tests/validation/known_answers.rs | 43 ++++++ 23 files changed, 554 insertions(+), 24 deletions(-) create mode 100644 fixtures/golden/vector-compare-ft.ir create mode 100644 fixtures/golden/vector-compare-ft.metal create mode 100644 fixtures/rdna2/vector-compare-ft.bin create mode 100644 fixtures/rdna2/vector-compare-ft.s diff --git a/CHANGELOG.md b/CHANGELOG.md index acc1736..4efdfe2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,7 @@ remains unsupported. - Added advisory infrastructure QA helpers under `scripts/qa/` and `scripts/release/` (issue #277): exit-status-preserving orchestration with JSON reports, PR scope/DCO/artifact checks, benchmark percentile analysis over existing samples, environment and repository health diagnostics, ARM64 Mach-O/bundle/codesign helpers, and checksum manifests. Covered by `tests/qa/` and `tests/release/`; checks stay advisory until reviewed. - Recorded agent-queue live smoke evidence for issue #180 against the disposable private repository `ranveersoni98/xenora-agent-queue-smoke`, including claim grant, overlap refusal, release, not-ready denial, progress renew and a successful audit dispatch after fixing comment-only `apply_actions` and audit permissions/argparse issues. - Added twelve gfx1030 VOP2 vector integer forms through the semantic registry: `v_mul_i32_i24`, `v_mul_hi_i32_i24`, `v_mul_u32_u24`, `v_mul_hi_u32_u24`, `v_min_i32`, `v_max_i32`, `v_min_u32`, `v_max_u32`, `v_xnor_b32`, `v_add_nc_u32`, `v_sub_nc_u32` and `v_subrev_nc_u32` (AMD guide section 12.7), with SRC0 a VGPR, an SGPR, `vcc_lo`, an inline integer or a literal. The registry gained a `vop2_vgpr` operand rule, the vector operations `mul24` and `mul_hi24`, a declared `source_order` for SUBREV, and a per-lane `VectorBinary` that selects one reusable MSL template per operation. Both reference interpreters, written separately from the guide, run the same twelve forms and are checked against 2,040 guide-derived cases, each asserting every lane of a 7-, 32- or 45-lane dispatch (partial, empty and full EXEC), on both CPU interpreters and on native Metal; 575 rejected programs are refused by both interpreters and by the compiler at the same word. A new LLVM-assembled fixture computes every lane from its own input. Part of #215. +- Moved the twelve Wave32 VOPC integer compares from #239 into the semantic registry (operand rule `vopc_vcc`, `vcc = "lane_mask"`, `wave = "wave32"`) with no behaviour change, and added `v_cmp_f_i32`, `v_cmp_t_i32`, `v_cmp_f_u32` and `v_cmp_t_u32` as registry forms under the same Wave32 VCC/EXEC contract, verified by an independent guide-derived oracle (`tests/validation/tests/vopc_f_t.rs`), a new LLVM-assembled fixture and native Metal (part of #215). `v_cmpx_*`, the VOP3 encoding and Wave64 stay unsupported. - Added sixteen gfx1030 SOP2 integer forms through the semantic registry: `s_min_i32`, `s_min_u32`, `s_max_i32`, `s_max_u32`, `s_cselect_b32`, `s_bfm_b32`, `s_mul_i32`, `s_bfe_u32`, `s_bfe_i32`, `s_absdiff_i32`, `s_lshl1_add_u32` to `s_lshl4_add_u32`, `s_mul_hi_u32` and `s_mul_hi_i32` (AMD guide section 12.1). Min and max set SCC from the strict compare (a tie gives S1 and SCC 0), `s_cselect_b32` reads SCC and is refused when SCC is unset, and BFM, MUL, MUL_HI and CSELECT leave SCC unchanged. The registry gained these primitives, a `selected_src0` SCC effect, the select's SCC input and a declared `shift_amount` for the shift-and-add forms; `ScalarAluOp::evaluate` now returns an optional SCC. Both reference interpreters, written separately from the guide, run the same sixteen forms and are checked against 21,070 guide-derived cases on both CPU interpreters and on native Metal; 597 rejected programs are refused by both interpreters and by the compiler. A new LLVM-assembled fixture covers all sixteen. Part of #215. - Added audio PCM streaming and sandboxed virtual filesystem (VFS) integration to the native application runtime (Gate 6, #284). The C interface gains audio management functions (`xenora_session_audio_init`, `xenora_session_audio_submit`, `xenora_session_audio_read`, `xenora_session_audio_status`, `xenora_session_audio_set_volume`) and virtual filesystem functions (`xenora_session_vfs_set_root`, `xenora_session_vfs_open`, `xenora_session_vfs_read`, `xenora_session_vfs_seek`, `xenora_session_vfs_close`, `xenora_session_run_audio_vfs_fixture`). The audio subsystem implements a bounded ring buffer supporting configurable sample rates, channel configurations, PCM formats (S16LE, F32LE), volume attenuation, mute, and buffer underrun tracking. The virtual filesystem operates within an explicitly configured, sandboxed directory root (`fixtures/assets`), strictly rejecting path traversal attempts (`..`, absolute paths, null bytes) and invalid or stale handles, while supporting sequential and seekable file reads (`XENORA_SEEK_SET`, `XENORA_SEEK_CUR`, `XENORA_SEEK_END`). An original PE fixture (`fixtures/pe/audio_vfs.exe`, generated by `fixtures/pe/audio_vfs.py` using only the supported ARM64 DBT instruction subset) opens `asset.bin` (generated by `fixtures/assets/generate.py`), loads a 2x2 RGBA texture and 256 PCM audio samples via VFS, initializes audio, submits the PCM audio queue, and renders the loaded texture on Metal. Verified with unit tests, four Metal acceptance tests in `crates/ffi/tests/audio_vfs.rs`, UI controls and a `--smoke-audio-vfs` CLI in `Xenora.app`. - Added persistent GPU resources, dynamic texture updates, and resource retirement to the native application (Gate 5, #279). The C interface gains `xenora_resource`, resource types (`XENORA_RESOURCE_TYPE_*`), `xenora_session_create_texture`, `xenora_session_update_texture`, `xenora_session_destroy_resource`, `xenora_session_resource_info`, `xenora_session_render_textured`, and `xenora_session_run_textured_fixture`. Persistent GPU resources (textures) are explicitly allocated and owned by the execution session, surviving across execution slices without re-allocation. Dynamic texture subregion updates modify GPU texture contents in-place on native Metal. Resource retirement is completion-aware: destroying a resource held by in-flight GPU execution marks it retired and safely defers destruction until in-flight work completes, while rejecting subsequent caller queries with typed error codes. An original PE fixture (`fixtures/pe/textured.exe`, generated by `fixtures/pe/textured.py` using only the supported ARM64 DBT instruction subset) creates a persistent 2x2 texture via `xenora.dll!texture_create`, renders frame 0, updates pixels via `xenora.dll!texture_update`, renders frame 1, and retires the resource via `xenora.dll!texture_destroy`. Xenora.app gains "Run textured fixture" controls and `--smoke-resources`. Six GPU acceptance tests with Metal validation verify persistent texture lifecycle across multiple frames, dynamic 1x1 and 2x1 subregion updates on native Metal, completion-aware deferred retirement, rejection of invalid/stale/double-destroyed handles, slot reuse across 200 cycles without leaking, and full guest fixture execution. Wired acceptance tests into `scripts/test-gpu.sh`. diff --git a/crates/decoder/tests/gfx1030.rs b/crates/decoder/tests/gfx1030.rs index 257ee62..d9c3f97 100644 --- a/crates/decoder/tests/gfx1030.rs +++ b/crates/decoder/tests/gfx1030.rs @@ -461,6 +461,8 @@ fn reference_op(instruction: Instruction) -> Op { CompareRelation::Greater => 4, CompareRelation::NotEqual => 5, CompareRelation::GreaterOrEqual => 6, + CompareRelation::False => 0, + CompareRelation::True => 7, }, signed: op.signed(), }, @@ -526,12 +528,13 @@ fn compares_fixture_instructions_against_llvm() { include_bytes!("../../../fixtures/rdna2/scalar-arith.bin"), include_bytes!("../../../fixtures/rdna2/vector-integer.bin"), include_bytes!("../../../fixtures/rdna2/vector-compare.bin"), + include_bytes!("../../../fixtures/rdna2/vector-compare-ft.bin"), high_registers, &matrix, ] { count += compare_against_llvm(fixture, &mut forms); } - assert_eq!(forms.len(), 100, "forms compared: {forms:?}"); + assert_eq!(forms.len(), 104, "forms compared: {forms:?}"); eprintln!( "{count} three-way instruction comparisons across {} forms", forms.len() @@ -596,7 +599,7 @@ fn assemble_matrix() -> Vec { ); // Every supported VOPC form with each source class: VGPR, SGPR, vcc_lo, // inline integers at both ends, inline zero and a literal. - for relation in ["lt", "eq", "le", "gt", "ne", "ge"] { + for relation in ["f", "lt", "eq", "le", "gt", "ne", "ge", "t"] { for kind in ["i32", "u32"] { for src0 in [ "v255", @@ -744,8 +747,6 @@ fn distinguishes_llvm_invalid_encodings_from_xenora_subset_rejections() { let outside_subset: &[&[u32]] = &[ &[0x7e04_026b], // VOP1 VCC_HI source &[0x7da2_0501], // v_cmpx_eq_u32_e32 - &[0x7d00_0501], // v_cmp_f_i32_e32 - &[0x7d0e_0501], // v_cmp_t_i32_e32 &[0xd482_006a, 0x0002_0501], // v_cmp_lt_i32_e64 &[0x8788_0908], // s_and_b64 &[0x8008_ffff, 0x1234_5678], // SOP2 with two literal sources diff --git a/crates/isa/generate_semantics.py b/crates/isa/generate_semantics.py index 4612a69..337b897 100755 --- a/crates/isa/generate_semantics.py +++ b/crates/isa/generate_semantics.py @@ -60,8 +60,10 @@ SOURCE_BITS = {8, 16} RELATION_KEY = "relation" RELATIONS = { "eq": "Equal", "lg": "NotEqual", "gt": "Greater", "ge": "GreaterOrEqual", - "lt": "Less", "le": "LessOrEqual", + "lt": "Less", "le": "LessOrEqual", "f": "False", "t": "True", } +# F and T exist only as VOPC compares (guide Table 59 offsets 0 and 7). +VECTOR_ONLY_RELATIONS = {"f", "t"} # (relation, signedness) -> primitive. Equality does not depend on signedness, # so both declared signednesses of EQ and LG share one primitive. COMPARE_PRIMITIVES = { @@ -71,6 +73,8 @@ COMPARE_PRIMITIVES = { ("ge", "signed"): "ge_i32", ("ge", "unsigned"): "ge_u32", ("lt", "signed"): "lt_i32", ("lt", "unsigned"): "lt_u32", ("le", "signed"): "le_i32", ("le", "unsigned"): "le_u32", + ("f", "signed"): "false_b32", ("f", "unsigned"): "false_b32", + ("t", "signed"): "true_b32", ("t", "unsigned"): "true_b32", } # Logical operations take untyped bits; arithmetic ones never do. Shifts take # the signedness their primitive names, and their S1 is an unsigned count. @@ -564,6 +568,8 @@ def validate(registry, snapshot): errors.append(f"{label}: unknown or missing {RELATION_KEY} {relation!r}") elif (relation, form["signedness"]) not in COMPARE_PRIMITIVES: errors.append(f"{label}: no primitive implements {relation}/{form['signedness']}") + elif relation in VECTOR_ONLY_RELATIONS and _rule_kind(form) != "vector_compare": + errors.append(f"{label}: relation {relation} exists only for VOPC compares") # SOPC compares write SCC; VOPC compares write VCC and leave SCC. scc = "unchanged" if _rule_kind(form) == "vector_compare" else "relation" if form["scc"] != scc: diff --git a/crates/isa/semantics/rdna2.toml b/crates/isa/semantics/rdna2.toml index eba44be..29f678a 100644 --- a/crates/isa/semantics/rdna2.toml +++ b/crates/isa/semantics/rdna2.toml @@ -1678,3 +1678,92 @@ spec = [ { document = "guide", section = "3.9", page = 19 }, ] verify = ["reference", "independent", "metal", "llvm_encoding"] + +# ---- VOPC F and T compares (guide Table 59 offsets 0 and 7) ---- +# The test is false or true for every lane, so VCC_LO := 0 or the EXEC lanes +# that exist. Sources are still decoded and checked as for the other compares +# (docs/shaders/vector-compare.md section 5). + +[[form]] +name = "V_CMP_F_I32" +family = "VOPC" +opcode = 128 +variant = "CmpFI32" +operation = "compare" +relation = "f" +signedness = "signed" +carry_in = "none" +width = 32 +scc = "unchanged" +vcc = "lane_mask" +exec = "unchanged" +wave = "wave32" +operands = "vopc_vcc" +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_T_I32" +family = "VOPC" +opcode = 135 +variant = "CmpTI32" +operation = "compare" +relation = "t" +signedness = "signed" +carry_in = "none" +width = 32 +scc = "unchanged" +vcc = "lane_mask" +exec = "unchanged" +wave = "wave32" +operands = "vopc_vcc" +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_F_U32" +family = "VOPC" +opcode = 192 +variant = "CmpFU32" +operation = "compare" +relation = "f" +signedness = "unsigned" +carry_in = "none" +width = 32 +scc = "unchanged" +vcc = "lane_mask" +exec = "unchanged" +wave = "wave32" +operands = "vopc_vcc" +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_T_U32" +family = "VOPC" +opcode = 199 +variant = "CmpTU32" +operation = "compare" +relation = "t" +signedness = "unsigned" +carry_in = "none" +width = 32 +scc = "unchanged" +vcc = "lane_mask" +exec = "unchanged" +wave = "wave32" +operands = "vopc_vcc" +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/lib.rs b/crates/isa/src/lib.rs index a9269db..b5edab6 100644 --- a/crates/isa/src/lib.rs +++ b/crates/isa/src/lib.rs @@ -111,6 +111,10 @@ pub enum CompareRelation { NotEqual, /// S0 >= S1 (offset 6). GreaterOrEqual, + /// Never holds (VOPC F, offset 0). + False, + /// Always holds (VOPC T, offset 7). + True, } /// Output targeted by a supported uncompressed four-component export. diff --git a/crates/isa/src/primitive.rs b/crates/isa/src/primitive.rs index 3395572..bc4eea8 100644 --- a/crates/isa/src/primitive.rs +++ b/crates/isa/src/primitive.rs @@ -99,6 +99,16 @@ pub const fn ashr_nonzero_i32(a: u32, count: u32) -> (u32, bool) { (value, value != 0) } +/// The VOPC F test: false for every operand pair. +pub const fn false_b32(_a: u32, _b: u32) -> bool { + false +} + +/// The VOPC T test: true for every operand pair. +pub const fn true_b32(_a: u32, _b: u32) -> bool { + true +} + /// `a == b` on the raw bits; signedness does not matter for equality. pub const fn eq_b32(a: u32, b: u32) -> bool { a == b diff --git a/crates/isa/src/semantics_gen.rs b/crates/isa/src/semantics_gen.rs index 0366a2b..8e889fb 100644 --- a/crates/isa/src/semantics_gen.rs +++ b/crates/isa/src/semantics_gen.rs @@ -1439,6 +1439,14 @@ pub enum VectorCompareOp { CmpNeU32, /// `v_cmp_ge_u32` (VOPC opcode 198): unsigned compare ge, VCC = lane_mask. CmpGeU32, + /// `v_cmp_f_i32` (VOPC opcode 128): signed compare f, VCC = lane_mask. + CmpFI32, + /// `v_cmp_t_i32` (VOPC opcode 135): signed compare t, VCC = lane_mask. + CmpTI32, + /// `v_cmp_f_u32` (VOPC opcode 192): unsigned compare f, VCC = lane_mask. + CmpFU32, + /// `v_cmp_t_u32` (VOPC opcode 199): unsigned compare t, VCC = lane_mask. + CmpTU32, } /// VectorCompareOp by VOPC OP field value; `None` for undeclared opcodes. @@ -1571,13 +1579,14 @@ const VECTOR_COMPARE_OP_BY_OPCODE: [Option; 256] = [ None, None, None, - None, + Some(VectorCompareOp::CmpFI32), Some(VectorCompareOp::CmpLtI32), Some(VectorCompareOp::CmpEqI32), Some(VectorCompareOp::CmpLeI32), Some(VectorCompareOp::CmpGtI32), Some(VectorCompareOp::CmpNeI32), Some(VectorCompareOp::CmpGeI32), + Some(VectorCompareOp::CmpTI32), None, None, None, @@ -1634,15 +1643,14 @@ const VECTOR_COMPARE_OP_BY_OPCODE: [Option; 256] = [ None, None, None, - None, - None, + Some(VectorCompareOp::CmpFU32), Some(VectorCompareOp::CmpLtU32), Some(VectorCompareOp::CmpEqU32), Some(VectorCompareOp::CmpLeU32), Some(VectorCompareOp::CmpGtU32), Some(VectorCompareOp::CmpNeU32), Some(VectorCompareOp::CmpGeU32), - None, + Some(VectorCompareOp::CmpTU32), None, None, None, @@ -1703,7 +1711,7 @@ const VECTOR_COMPARE_OP_BY_OPCODE: [Option; 256] = [ impl VectorCompareOp { /// Every operation, in registry order. - pub const ALL: [Self; 12] = [ + pub const ALL: [Self; 16] = [ Self::CmpLtI32, Self::CmpEqI32, Self::CmpLeI32, @@ -1716,6 +1724,10 @@ impl VectorCompareOp { Self::CmpGtU32, Self::CmpNeU32, Self::CmpGeU32, + Self::CmpFI32, + Self::CmpTI32, + Self::CmpFU32, + Self::CmpTU32, ]; /// Selects the operation from a first instruction word: the VOPC encoding @@ -1742,6 +1754,10 @@ impl VectorCompareOp { Self::CmpGtU32 => "v_cmp_gt_u32", Self::CmpNeU32 => "v_cmp_ne_u32", Self::CmpGeU32 => "v_cmp_ge_u32", + Self::CmpFI32 => "v_cmp_f_i32", + Self::CmpTI32 => "v_cmp_t_i32", + Self::CmpFU32 => "v_cmp_f_u32", + Self::CmpTU32 => "v_cmp_t_u32", } } @@ -1760,6 +1776,10 @@ impl VectorCompareOp { Self::CmpGtU32 => 77, Self::CmpNeU32 => 78, Self::CmpGeU32 => 79, + Self::CmpFI32 => 80, + Self::CmpTI32 => 81, + Self::CmpFU32 => 82, + Self::CmpTU32 => 83, }] } @@ -1778,6 +1798,10 @@ impl VectorCompareOp { Self::CmpGtU32 => "v_cmp_gt_u32_e32", Self::CmpNeU32 => "v_cmp_ne_u32_e32", Self::CmpGeU32 => "v_cmp_ge_u32_e32", + Self::CmpFI32 => "v_cmp_f_i32_e32", + Self::CmpTI32 => "v_cmp_t_i32_e32", + Self::CmpFU32 => "v_cmp_f_u32_e32", + Self::CmpTU32 => "v_cmp_t_u32_e32", } } @@ -1796,6 +1820,10 @@ impl VectorCompareOp { Self::CmpGtU32 => false, Self::CmpNeU32 => false, Self::CmpGeU32 => false, + Self::CmpFI32 => true, + Self::CmpTI32 => true, + Self::CmpFU32 => false, + Self::CmpTU32 => false, } } @@ -1814,6 +1842,10 @@ impl VectorCompareOp { Self::CmpGtU32 => CompareRelation::Greater, Self::CmpNeU32 => CompareRelation::NotEqual, Self::CmpGeU32 => CompareRelation::GreaterOrEqual, + Self::CmpFI32 => CompareRelation::False, + Self::CmpTI32 => CompareRelation::True, + Self::CmpFU32 => CompareRelation::False, + Self::CmpTU32 => CompareRelation::True, } } @@ -1832,12 +1864,16 @@ impl VectorCompareOp { Self::CmpGtU32 => primitive::gt_u32(src0, src1), Self::CmpNeU32 => primitive::ne_b32(src0, src1), Self::CmpGeU32 => primitive::ge_u32(src0, src1), + Self::CmpFI32 => primitive::false_b32(src0, src1), + Self::CmpTI32 => primitive::true_b32(src0, src1), + Self::CmpFU32 => primitive::false_b32(src0, src1), + Self::CmpTU32 => primitive::true_b32(src0, src1), } } } /// Identity of every registry form, in registry order. -pub const FORM_IDS: [(&str, EncodingFamily); 80] = [ +pub const FORM_IDS: [(&str, EncodingFamily); 84] = [ ("S_ADD_U32", EncodingFamily::Sop2), ("S_SUB_U32", EncodingFamily::Sop2), ("S_ADD_I32", EncodingFamily::Sop2), @@ -1918,10 +1954,14 @@ pub const FORM_IDS: [(&str, EncodingFamily); 80] = [ ("V_CMP_GT_U32", EncodingFamily::Vopc), ("V_CMP_NE_U32", EncodingFamily::Vopc), ("V_CMP_GE_U32", EncodingFamily::Vopc), + ("V_CMP_F_I32", EncodingFamily::Vopc), + ("V_CMP_T_I32", EncodingFamily::Vopc), + ("V_CMP_F_U32", EncodingFamily::Vopc), + ("V_CMP_T_U32", EncodingFamily::Vopc), ]; /// One validated row per registry form, in registry order. -pub static FORMS: [FormSemantics; 80] = [ +pub static FORMS: [FormSemantics; 84] = [ FormSemantics { name: "S_ADD_U32", family: EncodingFamily::Sop2, @@ -3602,4 +3642,88 @@ pub static FORMS: [FormSemantics; 80] = [ 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_F_I32", + family: EncodingFamily::Vopc, + opcode: 128, + operation: Operation::Compare, + signedness: Signedness::Signed, + carry_in: CarryIn::None, + width: 32, + shift_count_bits: 0, + shift_amount: 0, + swap_sources: false, + source_bits: 32, + relation: Some(CompareRelation::False), + scc: SccEffect::Unchanged, + vcc: MaskEffect::LaneMask, + exec: MaskEffect::Unchanged, + wave: Wave::Wave32, + operands: OperandRule::VopcVcc, + 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_T_I32", + family: EncodingFamily::Vopc, + opcode: 135, + operation: Operation::Compare, + signedness: Signedness::Signed, + carry_in: CarryIn::None, + width: 32, + shift_count_bits: 0, + shift_amount: 0, + swap_sources: false, + source_bits: 32, + relation: Some(CompareRelation::True), + scc: SccEffect::Unchanged, + vcc: MaskEffect::LaneMask, + exec: MaskEffect::Unchanged, + wave: Wave::Wave32, + operands: OperandRule::VopcVcc, + 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_F_U32", + family: EncodingFamily::Vopc, + opcode: 192, + operation: Operation::Compare, + signedness: Signedness::Unsigned, + carry_in: CarryIn::None, + width: 32, + shift_count_bits: 0, + shift_amount: 0, + swap_sources: false, + source_bits: 32, + relation: Some(CompareRelation::False), + scc: SccEffect::Unchanged, + vcc: MaskEffect::LaneMask, + exec: MaskEffect::Unchanged, + wave: Wave::Wave32, + operands: OperandRule::VopcVcc, + 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_T_U32", + family: EncodingFamily::Vopc, + opcode: 199, + operation: Operation::Compare, + signedness: Signedness::Unsigned, + carry_in: CarryIn::None, + width: 32, + shift_count_bits: 0, + shift_amount: 0, + swap_sources: false, + source_bits: 32, + relation: Some(CompareRelation::True), + scc: SccEffect::Unchanged, + vcc: MaskEffect::LaneMask, + exec: MaskEffect::Unchanged, + wave: Wave::Wave32, + operands: OperandRule::VopcVcc, + 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], + }, ]; diff --git a/crates/isa/tests/semantics.rs b/crates/isa/tests/semantics.rs index b46b692..895b7ff 100644 --- a/crates/isa/tests/semantics.rs +++ b/crates/isa/tests/semantics.rs @@ -143,6 +143,8 @@ fn vector_compare_dispatch_selects_exactly_the_registry_vopc_forms() { CompareRelation::Greater => ordering.is_gt(), CompareRelation::NotEqual => ordering.is_ne(), CompareRelation::GreaterOrEqual => ordering.is_ge(), + CompareRelation::False => false, + CompareRelation::True => true, }; assert_eq!( op.test(src0, src1), @@ -153,7 +155,7 @@ fn vector_compare_dispatch_selects_exactly_the_registry_vopc_forms() { } } } - // v_cmpx, F/T and the 16-, 64-bit and float compares must not be dispatched. + // v_cmpx and the 16-, 64-bit and 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 50a8130..3eae65c 100644 --- a/crates/shader/src/lib.rs +++ b/crates/shader/src/lib.rs @@ -202,6 +202,9 @@ fn compare_expression(op: VectorCompareOp, left: &str, right: &str) -> String { CompareRelation::Greater => ">", CompareRelation::NotEqual => "!=", CompareRelation::GreaterOrEqual => ">=", + // F and T read no operand bits. + CompareRelation::False => return "false".to_owned(), + CompareRelation::True => return "true".to_owned(), }; if op.signed() { format!("as_type({left}) {symbol} as_type({right})") @@ -523,7 +526,15 @@ fn emit_lane_mask( exec: u32, ) { let mut cone = vec![false; index]; - let mut pending = vec![src0, src1]; + // F and T do not depend on the operands, so their lanes compute none. + let mut pending = if matches!( + op.relation(), + xenora_decoder::CompareRelation::False | xenora_decoder::CompareRelation::True + ) { + Vec::new() + } else { + vec![src0, src1] + }; while let Some(value) = pending.pop() { if uniform[value.0] || cone[value.0] { continue; diff --git a/crates/shader/tests/compiler.rs b/crates/shader/tests/compiler.rs index e72291a..6d94175 100644 --- a/crates/shader/tests/compiler.rs +++ b/crates/shader/tests/compiler.rs @@ -350,6 +350,20 @@ fn vector_integer_forms_lower_to_per_lane_templates() { ); } +#[test] +fn vector_f_and_t_compares_lower_to_operand_free_wave_masks() { + let code = include_bytes!("../../../fixtures/rdna2/vector-compare-ft.bin"); + let result = compile(Architecture::Gfx1030, code).unwrap(); + assert_eq!( + result.ir, + include_str!("../../../fixtures/golden/vector-compare-ft.ir") + ); + assert_eq!( + result.msl, + include_str!("../../../fixtures/golden/vector-compare-ft.metal") + ); +} + #[test] fn vector_compares_lower_to_per_thread_wave_masks_and_selects() { let code = include_bytes!("../../../fixtures/rdna2/vector-compare.bin"); diff --git a/docs/assets/xenora-progress.svg b/docs/assets/xenora-progress.svg index d5ef3f6..7e30221 100644 --- a/docs/assets/xenora-progress.svg +++ b/docs/assets/xenora-progress.svg @@ -1,17 +1,17 @@ Xenora · recorded progress -Decoded gfx1030 forms: 100 of 100. Accepted Metal forms · Apple M5: 18 of 100. Accepted guest milestones · X1–X4: 4 of 4 +Decoded gfx1030 forms: 104 of 104. Accepted Metal forms · Apple M5: 18 of 104. Accepted guest milestones · X1–X4: 4 of 4 RECORDED FIXTURE PROGRESS Decoded gfx1030 forms -100 / 100 +104 / 104 Accepted Metal forms · Apple M5 -18 / 100 +18 / 104 - + Accepted guest milestones · X1–X4 4 / 4 diff --git a/docs/shaders/instruction-coverage.md b/docs/shaders/instruction-coverage.md index 448d6bc..d3f72f4 100644 --- a/docs/shaders/instruction-coverage.md +++ b/docs/shaders/instruction-coverage.md @@ -89,6 +89,10 @@ The wider LLVM operand matrix exercises decoding only. ABI means application bin | `v_cmp_gt_u32_e32` | VOPC, Wave32; VGPR, normal SGPR (known during translation), vcc_lo, inline integer or literal SRC0; VGPR VSRC1; VCC_LO[n] = EXEC_LO[n] & (unsigned S0 > S1), fully written | `7D8802C0` | yes | yes | three-way passed | per-thread Wave32 mask over the dispatch's own 32 lanes; runtime s_cbranch_vccz as a join select | implemented | local known-answer test passed | local Apple M5 readback passed; acceptance pending | | `v_cmp_ne_u32_e32` | VOPC, Wave32; VGPR, normal SGPR (known during translation), vcc_lo, inline integer or literal SRC0; VGPR VSRC1; VCC_LO[n] = EXEC_LO[n] & (unsigned S0 != S1), fully written | `7D8A026A` | yes | yes | three-way passed | per-thread Wave32 mask over the dispatch's own 32 lanes; runtime s_cbranch_vccz as a join select | implemented | local known-answer test passed | local Apple M5 readback passed; acceptance pending | | `v_cmp_ge_u32_e32` | VOPC, Wave32; VGPR, normal SGPR (known during translation), vcc_lo, inline integer or literal SRC0; VGPR VSRC1; VCC_LO[n] = EXEC_LO[n] & (unsigned S0 >= S1), fully written | `7D8C0D01` | yes | yes | three-way passed | per-thread Wave32 mask over the dispatch's own 32 lanes; runtime s_cbranch_vccz as a join select | implemented | local known-answer test passed | local Apple M5 readback passed; acceptance pending | +| `v_cmp_f_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] & false, fully written | `7D000501` | 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_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 | | `s_cbranch_scc0` | Nonnegative signed dword displacement | `BF840002` | yes | yes | three-way passed | resolved conditional branch | implemented | fixture verified | fixture verified | | `s_branch` | Nonnegative signed dword displacement | `BF820001` | yes | yes | three-way passed | resolved branch | implemented | fixture verified | fixture verified | | `v_and_b32_e32` | Two VGPR sources and one VGPR destination | `36020702` | yes | yes | three-way passed | MSL bitwise AND | implemented | fixture verified | fixture verified | diff --git a/docs/shaders/reference-interpreter.md b/docs/shaders/reference-interpreter.md index 60a3059..9b55af5 100644 --- a/docs/shaders/reference-interpreter.md +++ b/docs/shaders/reference-interpreter.md @@ -12,7 +12,7 @@ | SOP1 `S_NOT_B32`, `S_BREV_B32`, `S_BCNT{0,1}_I32_B32`, `S_FF{0,1}_I32_B32`, `S_FLBIT_I32_B32`, `S_FLBIT_I32`, `S_SEXT_I32_I{8,16}`, `S_ABS_I32` | The guide's section 12.3 result; a search that finds nothing gives -1, and `S_ABS_I32` of 0x80000000 is 0x80000000. Only NOT, BCNT0, BCNT1 and ABS write SCC (= D != 0). Descriptor SGPRs are reserved. | | SOP1 `S_MOV_B32`, SOPC `S_CMP_{EQ,LG,GT,GE,LT,LE}_{I32,U32}` | Copy 32 bits into a scalar register, or compare SSRC0 with SSRC1 (signed for `_I32` ordering, unsigned for `_U32`; EQ and LG on the raw bits) and set only SCC. Descriptor SGPRs are reserved. | | SOP2 `S_ADD_U32`, `S_SUB_U32`, `S_ADD_I32`, `S_SUB_I32`, `S_ADDC_U32`, `S_SUBB_U32`, `S_AND_B32`, `S_OR_B32`, `S_XOR_B32`, `S_ANDN2_B32`, `S_ORN2_B32`, `S_NAND_B32`, `S_NOR_B32`, `S_XNOR_B32`, `S_LSHL_B32`, `S_LSHR_B32`, `S_ASHR_I32` | Exact integer result reduced modulo 2^32; shifts use S1[4:0]; SCC is the carry-out, the borrow, signed overflow (the exact signed result does not fit in i32), or a nonzero logical or shift result, and ADDC/SUBB consume SCC ([SOP2 scalar ALU](scalar-alu.md)). Descriptor SGPRs are reserved. | -| VOPC `V_CMP_{LT,EQ,LE,GT,NE,GE}_{I32,U32}` | Compare widened 64-bit values per active lane. VCC_LO gets EXEC & the test results and is fully written, so empty EXEC gives 0. A later `S_CBRANCH_VCCZ` on such a mask checks the skipped code statically ([VOPC integer compares](vector-compare.md)). | +| VOPC `V_CMP_{F,LT,EQ,LE,GT,NE,GE,T}_{I32,U32}` | Compare widened 64-bit values per active lane (F is false and T true for every lane). VCC_LO gets EXEC & the test results and is fully written, so empty EXEC gives 0. A later `S_CBRANCH_VCCZ` on such a mask checks the skipped code statically ([VOPC integer compares](vector-compare.md)). | | SOPP `S_BRANCH`, `S_CBRANCH_SCC0` | Use a signed dword displacement from the next instruction (CLAIM-RDNA2-SOPP-BRANCH-DISPLACEMENT). Require a nonnegative word displacement to a decoded instruction boundary, including for untaken edges. | | VOP2 `V_AND_B32`, `V_XOR_B32` | Apply the bitwise operator to two VGPRs. | | VOP2 `V_MUL_{I32_I24,HI_I32_I24,U32_U24,HI_U32_U24}`, `V_MIN_{I32,U32}`, `V_MAX_{I32,U32}`, `V_XNOR_B32`, `V_ADD_NC_U32`, `V_SUB_NC_U32`, `V_SUBREV_NC_U32` | The guide's section 12.7 result per active lane, computed exactly: the 24-bit multiplies use S0[23:0] and S1[23:0] (sign-extended for I24) and keep bits 31:0 or 63:32; SUBREV gives S1 - S0. SRC0 is a VGPR, s0-s105, `vcc_lo`, an inline integer or a literal. Inactive lanes keep VDST; no SCC or VCC write. | diff --git a/docs/shaders/semantic-coverage.md b/docs/shaders/semantic-coverage.md index 3b51194..04f437a 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 | 0 | 1 | 1 | 1 | 1 | 1 | 0 | | VOP3P | 29 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | | VOP3SDST | 10 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | -| VOPC | 190 | 12 | 12 | 12 | 12 | 12 | 0 | 0 | 7 | -| **Total** | 1465 | 100 | 80 | 104 | 100 | 100 | 18 | 18 | 44 | +| VOPC | 190 | 16 | 16 | 16 | 16 | 16 | 0 | 0 | 7 | +| **Total** | 1465 | 104 | 84 | 108 | 104 | 104 | 18 | 18 | 44 | ## Unsupported operand variants diff --git a/docs/shaders/vector-compare.md b/docs/shaders/vector-compare.md index 9d8a8ca..a9b1dec 100644 --- a/docs/shaders/vector-compare.md +++ b/docs/shaders/vector-compare.md @@ -53,6 +53,8 @@ The 32-bit VOPC encoding (bits 31:25 = 0b0111110), no SDWA or DPP: | v_cmp_gt_i32 / v_cmp_gt_u32 | S0 > S1 | | v_cmp_ne_i32 / v_cmp_ne_u32 | S0 != S1 | | v_cmp_ge_i32 / v_cmp_ge_u32 | S0 >= S1 | +| v_cmp_f_i32 / v_cmp_f_u32 | false (Table 59 offset 0) | +| v_cmp_t_i32 / v_cmp_t_u32 | true (offset 7) | `_i32` compares the 32-bit two's-complement values, `_u32` the unsigned values. The forms are declared in the semantic registry @@ -98,7 +100,7 @@ this wave (all 32 except in a final partial wave, see 7). As an unsigned - V_CMPX_* (writes EXEC: divergent execution; needs its own contract). - The VOP3 encoding of any compare (arbitrary SGPR destination, modifiers). -- SDWA and DPP forms; F/T, 16-bit, 64-bit and float compares; v_cmp_class. +- SDWA and DPP forms; 16-bit, 64-bit and float compares; v_cmp_class. - SRC0 inline float constants (240-248), SGPRs other than s0-s106, TTMPs, M0, EXEC_LO/HI, VCC_HI, SCC/VCCZ/EXECZ selectors, LDS direct. - A normal-SGPR SRC0 without a known value, when EXEC_LO != 0. @@ -197,7 +199,7 @@ instructions are pure 32-bit ALU and are evaluated unconditionally. ## 9. Verification `fixtures/rdna2/vector-compare.s` is an original program, assembled by LLVM. -It uses all twelve forms with VGPR, SGPR, inline, literal and `vcc_lo` +It uses the twelve relational forms with VGPR, SGPR, inline, literal and `vcc_lo` sources, a compare and a mask move under partial EXEC, a compare under empty EXEC that must clear a stale VCC, SCC kept across compares, and a runtime `s_cbranch_vccz`. Its expected output is written in @@ -205,6 +207,12 @@ EXEC that must clear a stale VCC, SCC kept across compares, and a runtime relation for each row. The test input has a wave whose branch is taken, one whose branch is not, and a final partial wave of 9 lanes. +`fixtures/rdna2/vector-compare-ft.s` does the same for the four F and T +forms: an F that clears a stale VCC, T and F under partial EXEC, a T reading +`vcc_lo`, and runtime `s_cbranch_vccz` on a T result (never taken) and an F +result (always taken). The independent oracle for F and T is +`tests/validation/tests/vopc_f_t.rs`. + The same file runs each form against 10 boundary values (0, 1, 0x7ffffffe, 0x7fffffff, 0x80000000, 0x80000001, 0xfffffff0, 0xfffffffe, 0xffffffff, 0x0f0f0f0f), in both operand orders. That is 240 programs, checked against diff --git a/docs/status.toml b/docs/status.toml index f96bee7..01fb189 100644 --- a/docs/status.toml +++ b/docs/status.toml @@ -950,6 +950,54 @@ gpu = "local Apple M5 readback passed; acceptance pending" recognized = true decoded = true llvm = "three-way passed" +[[instruction]] +form = "v_cmp_f_i32_e32" +encoding = "VOPC, Wave32; VGPR, normal SGPR (known during translation), vcc_lo, inline integer or literal SRC0 (signed); VGPR VSRC1; VCC_LO[n] = EXEC_LO[n] & false, fully written" +representation = "`7D000501`" +lowering = "per-thread Wave32 mask over the dispatch's own 32 lanes, reading no operand bits; runtime s_cbranch_vccz as a join select" +reference = "implemented" +cpu = "local known-answer test passed" +gpu = "local Apple M5 readback passed; acceptance pending" +recognized = true +decoded = true +llvm = "three-way passed" + +[[instruction]] +form = "v_cmp_t_i32_e32" +encoding = "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" +representation = "`7D0E0501`" +lowering = "per-thread Wave32 mask over the dispatch's own 32 lanes, reading no operand bits; runtime s_cbranch_vccz as a join select" +reference = "implemented" +cpu = "local known-answer test passed" +gpu = "local Apple M5 readback passed; acceptance pending" +recognized = true +decoded = true +llvm = "three-way passed" + +[[instruction]] +form = "v_cmp_f_u32_e32" +encoding = "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" +representation = "`7D800501`" +lowering = "per-thread Wave32 mask over the dispatch's own 32 lanes, reading no operand bits; runtime s_cbranch_vccz as a join select" +reference = "implemented" +cpu = "local known-answer test passed" +gpu = "local Apple M5 readback passed; acceptance pending" +recognized = true +decoded = true +llvm = "three-way passed" + +[[instruction]] +form = "v_cmp_t_u32_e32" +encoding = "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" +representation = "`7D8E0501`" +lowering = "per-thread Wave32 mask over the dispatch's own 32 lanes, reading no operand bits; runtime s_cbranch_vccz as a join select" +reference = "implemented" +cpu = "local known-answer test passed" +gpu = "local Apple M5 readback passed; acceptance pending" +recognized = true +decoded = true +llvm = "three-way passed" + [[instruction]] form = "s_cbranch_scc0" encoding = "Nonnegative signed dword displacement" diff --git a/fixtures/golden/vector-compare-ft.ir b/fixtures/golden/vector-compare-ft.ir new file mode 100644 index 0000000..f0e68ee --- /dev/null +++ b/fixtures/golden/vector-compare-ft.ir @@ -0,0 +1,28 @@ +0000: t0 = load.u32 input[index] +0014: t1 = const.u32 0x00000000 +0018: t2 = const.u32 0x00000001 +0020: t3 = wave.mask v_cmp_f_i32_e32 t0, t0 exec=0xffffffff +0028: t4 = xor.b32 t1, t3 +002c: t5 = const.u32 0x12345678 +002c: t6 = wave.mask v_cmp_t_i32_e32 t5, t0 exec=0xffffffff +0034: t7 = lshl.b32 t4, t2 +0038: t8 = xor.b32 t7, t6 +0044: t9 = const.u32 0xfffffff9 +0044: t10 = wave.mask v_cmp_t_u32_e32 t9, t0 exec=0x0f0f0f0f +0050: t11 = lshl.b32 t8, t2 +0054: t12 = xor.b32 t11, t10 +0058: t13 = wave.mask v_cmp_t_i32_e32 t0, t0 exec=0xffffffff +0064: t14 = const.u32 0xdeadbeef +0064: t15 = wave.mask v_cmp_f_u32_e32 t14, t0 exec=0x3c3c3c3c +0074: t16 = lshl.b32 t12, t2 +0078: t17 = xor.b32 t16, t15 +007c: t18 = wave.mask v_cmp_t_u32_e32 t15, t0 exec=0xffffffff +0080: branch.vccz t18 -> 0x0088 +0084: t20 = xor.b32 t17, t0 +0088: t21 = join.vccz t18, t20, t17 +0088: t22 = const.u32 0x00000040 +0088: t23 = wave.mask v_cmp_f_i32_e32 t22, t0 exec=0xffffffff +008c: branch.vccz t23 -> 0x0094 +0090: t25 = const.u32 0x00000000 +0094: t26 = join.vccz t23, t25, t21 +0094: store.u32 output[index], t26 diff --git a/fixtures/golden/vector-compare-ft.metal b/fixtures/golden/vector-compare-ft.metal new file mode 100644 index 0000000..b4c83e0 --- /dev/null +++ b/fixtures/golden/vector-compare-ft.metal @@ -0,0 +1,76 @@ +#include +using namespace metal; +kernel void xenora_compute( + device const uint* input [[buffer(0)]], + device uint* output [[buffer(1)]], + uint index [[thread_position_in_grid]], + uint grid [[threads_per_grid]]) { + uint t0 = input[index]; + uint t1 = 0x00000000u; + uint t2 = 0x00000001u; + uint t3 = 0u; + for (uint lane = 0u; lane < 32u; ++lane) { + uint lane_index = (index & ~31u) + lane; + if (lane_index >= grid) { break; } + uint pass = (false) ? 1u : 0u; + t3 |= ((0xffffffffu >> lane) & pass) << lane; + } + uint t4 = t1 ^ t3; + uint t5 = 0x12345678u; + uint t6 = 0u; + for (uint lane = 0u; lane < 32u; ++lane) { + uint lane_index = (index & ~31u) + lane; + if (lane_index >= grid) { break; } + uint pass = (true) ? 1u : 0u; + t6 |= ((0xffffffffu >> lane) & pass) << lane; + } + uint t7 = t4 << (t2 & 31u); + uint t8 = t7 ^ t6; + uint t9 = 0xfffffff9u; + uint t10 = 0u; + for (uint lane = 0u; lane < 32u; ++lane) { + uint lane_index = (index & ~31u) + lane; + if (lane_index >= grid) { break; } + uint pass = (true) ? 1u : 0u; + t10 |= ((0x0f0f0f0fu >> lane) & pass) << lane; + } + uint t11 = t8 << (t2 & 31u); + uint t12 = t11 ^ t10; + uint t13 = 0u; + for (uint lane = 0u; lane < 32u; ++lane) { + uint lane_index = (index & ~31u) + lane; + if (lane_index >= grid) { break; } + uint pass = (true) ? 1u : 0u; + t13 |= ((0xffffffffu >> lane) & pass) << lane; + } + uint t14 = 0xdeadbeefu; + uint t15 = 0u; + for (uint lane = 0u; lane < 32u; ++lane) { + uint lane_index = (index & ~31u) + lane; + if (lane_index >= grid) { break; } + uint pass = (false) ? 1u : 0u; + t15 |= ((0x3c3c3c3cu >> lane) & pass) << lane; + } + uint t16 = t12 << (t2 & 31u); + uint t17 = t16 ^ t15; + uint t18 = 0u; + for (uint lane = 0u; lane < 32u; ++lane) { + uint lane_index = (index & ~31u) + lane; + if (lane_index >= grid) { break; } + uint pass = (true) ? 1u : 0u; + t18 |= ((0xffffffffu >> lane) & pass) << lane; + } + uint t20 = t17 ^ t0; + uint t21 = t18 != 0u ? t20 : t17; + uint t22 = 0x00000040u; + uint t23 = 0u; + for (uint lane = 0u; lane < 32u; ++lane) { + uint lane_index = (index & ~31u) + lane; + if (lane_index >= grid) { break; } + uint pass = (false) ? 1u : 0u; + t23 |= ((0xffffffffu >> lane) & pass) << lane; + } + uint t25 = 0x00000000u; + uint t26 = t23 != 0u ? t25 : t21; + output[index] = t26; +} diff --git a/fixtures/rdna2/vector-compare-ft.bin b/fixtures/rdna2/vector-compare-ft.bin new file mode 100644 index 0000000000000000000000000000000000000000..a12df6665be972abe0f8909240387c255ba5c88b GIT binary patch literal 164 zcmZQjFnGYg$k0$=-?RTebH~1lFcYB$CYHKJCa$`J%&+z_GBea>F>%x}ak5x(F!6!e ztgI|1ApU>mfBX1>;5buX?Li$jny@lD7eZ|4a?F@As{}hpr|IsE?7MZ9fw; ei`4-p1~40BH-kdK0|q9>1_p+|yBQc7_X7Z|oiP9a literal 0 HcmV?d00001 diff --git a/fixtures/rdna2/vector-compare-ft.s b/fixtures/rdna2/vector-compare-ft.s new file mode 100644 index 0000000..7001d86 --- /dev/null +++ b/fixtures/rdna2/vector-compare-ft.s @@ -0,0 +1,45 @@ +// SPDX-License-Identifier: GPL-3.0-or-later +// Original Wave32 VOPC vectors for the F and T compares: both signednesses +// with VGPR, SGPR, inline, literal and vcc_lo sources; F clearing a stale +// VCC; T and F under partial EXEC; and runtime s_cbranch_vccz on a T result +// (never taken) and an F result (always taken). Each wave folds its masks +// into v2 as v2 = (v2 << 1) ^ mask. Expected results come from exact +// definitions in tests/validation/known_answers.rs, not from this file. +.text +buffer_load_dword v1, v0, s[0:3], 0 idxen +s_waitcnt vmcnt(0) +s_mov_b32 s8, 0x12345678 +v_mov_b32_e32 v2, 0 // accumulator +v_mov_b32_e32 v5, 1 // shift count +s_mov_b32 vcc_lo, -1 // stale nonzero mask +v_cmp_f_i32_e32 vcc_lo, v1, v1 // VCC_LO = 0 +v_mov_b32_e32 v4, vcc_lo +v_xor_b32_e32 v2, v2, v4 +v_cmp_t_i32_e32 vcc_lo, s8, v1 // every lane of the wave +v_mov_b32_e32 v4, vcc_lo +v_lshlrev_b32_e32 v2, v5, v2 +v_xor_b32_e32 v2, v2, v4 +s_mov_b32 exec_lo, 0x0f0f0f0f +v_cmp_t_u32_e32 vcc_lo, -7, v1 // only the EXEC lanes +s_mov_b32 exec_lo, -1 +v_mov_b32_e32 v4, vcc_lo +v_lshlrev_b32_e32 v2, v5, v2 +v_xor_b32_e32 v2, v2, v4 +v_cmp_t_i32_e32 vcc_lo, v1, v1 // nonzero again before the F +s_mov_b32 exec_lo, 0x3c3c3c3c +v_cmp_f_u32_e32 vcc_lo, 0xdeadbeef, v1 // 0 even in active lanes +s_mov_b32 exec_lo, -1 +v_mov_b32_e32 v4, vcc_lo +v_lshlrev_b32_e32 v2, v5, v2 +v_xor_b32_e32 v2, v2, v4 +v_cmp_t_u32_e32 vcc_lo, vcc_lo, v1 // reads the zero mask; T anyway +s_cbranch_vccz .Lskip // runtime branch, never taken +v_xor_b32_e32 v2, v2, v1 +.Lskip: +v_cmp_f_i32_e32 vcc_lo, 64, v1 +s_cbranch_vccz .Ldone // runtime branch, always taken +v_mov_b32_e32 v2, 0 +.Ldone: +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 eb0a0f8..6109c31 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 vector-integer; 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 vector-integer vector-compare-ft; 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/tests/semantics_generator/test_generate_semantics.py b/tests/semantics_generator/test_generate_semantics.py index 71b39f5..90eb6fd 100644 --- a/tests/semantics_generator/test_generate_semantics.py +++ b/tests/semantics_generator/test_generate_semantics.py @@ -831,6 +831,22 @@ class Validate(unittest.TestCase): form(reg, "V_CMP_LT_I32")["signedness"] = "unsigned" self.rejects(reg, "V_CMP_LT_I32: signedness unsigned contradicts XML format FMT_NUM_I32") + def test_rejects_f_and_t_outside_vopc(self): + for relation in ("f", "t"): + with self.subTest(relation=relation): + reg = compares() + form(reg, "S_CMP_LT_I32")["relation"] = relation + self.rejects(reg, f"S_CMP_LT_I32: relation {relation} exists only for VOPC compares") + + def test_renders_f_and_t_primitives(self): + reg = vector_compares() + form(reg, "V_CMP_LT_I32")["relation"] = "t" + form(reg, "V_CMP_NE_U32")["relation"] = "f" + self.assertEqual(self.errors(reg), []) + text = gen.render(reg, snapshot()) + self.assertIn("Self::CmpLtI32 => primitive::true_b32(src0, src1),", text) + self.assertIn("Self::CmpNeU32 => CompareRelation::False,", text) + def test_renders_vector_compare_dispatch(self): text = gen.render(vector_compares(), snapshot()) self.assertIn("pub enum VectorCompareOp {", text) diff --git a/tests/validation/known_answers.rs b/tests/validation/known_answers.rs index 6aa3cd3..b4f1f62 100644 --- a/tests/validation/known_answers.rs +++ b/tests/validation/known_answers.rs @@ -1308,6 +1308,21 @@ mod review { // ---- VOPC integer compares (docs/shaders/vector-compare.md) ---- const COMPARE_FIXTURE: &[u8] = include_bytes!("../../fixtures/rdna2/vector-compare.bin"); + const COMPARE_FT_FIXTURE: &[u8] = include_bytes!("../../fixtures/rdna2/vector-compare-ft.bin"); + + /// fixtures/rdna2/vector-compare-ft.s, from its listing and guide 12.9 + /// Table 61 (F: D = 0, T: D = 1) with VCC_LO[n] = EXEC_LO[n] & test: every + /// F mask is 0 and every T mask is EXEC_LO & the lanes that exist, so the + /// T branch is never taken and the F branch always is. + fn compare_ft_expected(input: &[u32]) -> Vec { + let mut output = Vec::new(); + for wave in input.chunks(32) { + let exists = wave_mask(wave, u32::MAX, |_| true); + let folded = ((exists << 1) ^ (exists & 0x0f0f_0f0f)) << 1; + output.extend(wave.iter().map(|&x| folded ^ x)); + } + output + } const COMPARE_VALUES: [u32; 10] = [ 0, 1, @@ -1412,6 +1427,30 @@ mod review { input } + #[test] + fn compare_ft_fixture_matches_exact_definitions() { + // A full wave and a final partial wave of 7 lanes. + let mut input = compare_fixture_input()[..32].to_vec(); + input.extend([0, 1, u32::MAX, 0x8000_0000, 0x7fff_ffff, 64, 0x1234_5678]); + let expected = compare_ft_expected(&input); + verify(COMPARE_FT_FIXTURE, &input, Some(&expected)); + // The partial wave's T masks have only its 7 lanes. + assert_eq!(expected[32], ((0x7f << 1) ^ 0x0f) << 1); + let compiled = compile(Architecture::Gfx1030, COMPARE_FT_FIXTURE).unwrap(); + assert_eq!( + compiled.ir.matches("wave.mask").count(), + 7, + "{}", + compiled.ir + ); + assert_eq!( + compiled.ir.matches("join.vccz").count(), + 2, + "{}", + compiled.ir + ); + } + #[test] fn compare_fixture_matches_exact_definitions() { let input = compare_fixture_input(); @@ -1892,6 +1931,10 @@ mod review { assert_eq!(run(&join, &[1, 0, 5, 0]), [0b1010; 4]); assert_eq!(run(&join, &[0, 0, 0, 0]), [0; 4]); programs += 2; + let mut input = compare_fixture_input()[..32].to_vec(); + input.extend([0, 1, u32::MAX, 0x8000_0000, 0x7fff_ffff, 64, 0x1234_5678]); + assert_eq!(run(COMPARE_FT_FIXTURE, &input), compare_ft_expected(&input)); + programs += 1; eprintln!("{programs} VOPC programs matched on native Metal"); } }