mirror of
https://github.com/MacosPorters/betterxen.git
synced 2026-11-26 18:10:43 +00:00
* isa, decoder, shader: move the twelve Wave32 VOPC compares into the semantic registry (#215) The v_cmp_{lt,eq,le,gt,ne,ge}_{i32,u32}_e32 forms from #239 are now registry data under a new vopc_vcc operand rule (SRC0 a vector_source, VSRC1 a VGPR, destination implicitly vcc_lo). The decoder dispatches them through the generated VectorCompareOp instead of a hand-written opcode table, and the hand-written VectorCompareOp struct in xenora-isa is gone. No behaviour change: goldens, known answers and the LLVM oracle are unchanged. The vocabulary gains vcc = "lane_mask", allowed exactly for the VOPC rule and required to account for the XML's implicit VCC output, and wave = "wave32", now allowed exactly for that rule (its one entry point is the Wave32 compute fixture ABI) and still rejected elsewhere. exec must stay unchanged, so v_cmpx cannot be declared. Signed-off-by: elforeign <324243036+elforeign@users.noreply.github.com> * test(vopc): independent oracle for v_cmp_{f,t}_{i32,u32}_e32 (#215) The registry stage adds the four constant 32-bit integer VOPC compares, which nothing could check: the reference and the second interpreter both rejected them. Derive them from the RDNA 2 guide only (12.9 Table 61: D = 0 / D = 1; 3.9: VCC[n] = EXEC[n] & test, fully written) under the #239 Wave32 contract, so T writes EXEC_LO masked to existing lanes, F writes 0, and sources keep the allowlist and initialization rules. vopc_f_t.rs covers every SRC0 class, aliasing, full, partial and empty EXEC with a stale VCC_LO, a partial final wave, s_cbranch_vccz on both edges and the rejections; the native Metal part is ignored until the translator side lands. known_answers no longer expects F and T to be rejected. Signed-off-by: elforeign <324243036+elforeign@users.noreply.github.com> * 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> * test(vopc): cover EXEC preservation, known-0 branch, pending loads (#215) Review found four ways F/T could be wrong and still pass: clearing EXEC under partial EXEC, treating the empty-EXEC result as lane-derived, ignoring an outstanding load on a source, and decoding opcode 200. Add a case or rejection for each; each was shown failing with that break. Signed-off-by: elforeign <324243036+elforeign@users.noreply.github.com> * isa: check VOPC relations against the Table 59 opcode layout and the VCC write direction (#215) Review fixes. A VOPC compare's opcode must equal its group base (128 signed, 192 unsigned) plus its relation's Table 59 offset, so a row such as V_CMP_T_I32 with relation f is rejected instead of lowering to false. A lane_mask form now needs exactly one fieldless XML VCC operand that is written and not read. The generator tests render the real F/T rows, and the vector-compare doc names the file each count comes from. Signed-off-by: elforeign <324243036+elforeign@users.noreply.github.com> --------- Signed-off-by: elforeign <324243036+elforeign@users.noreply.github.com>
30 lines
6.5 KiB
Markdown
30 lines
6.5 KiB
Markdown
# Independent gfx1030 CPU reference
|
|
|
|
`xenora_ref::execute` reads raw little-endian code bytes and input words without dependencies on the production ISA crate, the compiler or Metal. It accepts at most 1024 instruction bytes and 4096 input words. The synthetic ABI gives every invocation its own input and output word. The indexed load and store forms need no host address arithmetic, and V0 is reserved for that indexing. Dispatch indices form Wave32 waves of 32 consecutive invocations, executed in lockstep with shared scalar state. The reference accepts uniform forward branches driven by scalar register state or by a compare mask in VCC_LO. Cross-lane register access other than compare masks, and EXEC derived from lane data, are outside the subset. Floating-point arithmetic is restricted to positive normal inputs and exact normal results.
|
|
|
|
| AMD RDNA 2 ISA guide instruction | Reference operation |
|
|
|---|---|
|
|
| MUBUF `BUFFER_LOAD_DWORD`, `BUFFER_STORE_DWORD` | Track a pending read and write. Each accesses one 32-bit word under the synthetic mapping. Only one output store is allowed. |
|
|
| SOPP `S_WAITCNT`, SOPK `S_WAITCNT_VSCNT` | A zero vector-load or vector-store threshold completes the associated transfer. The model permits one pending operation per counter (CLAIM-RDNA2-TRANSFER-WAITS). |
|
|
| VOP1 `V_MOV_B32` | Read a register, inline integer or literal. Copy all 32 bits. |
|
|
| VOP3 `V_ADD_NC_U32` | Read two vector registers and add modulo 2^32. No implicit carry or flag update. |
|
|
| SOP2 `S_MIN_{I32,U32}`, `S_MAX_{I32,U32}`, `S_CSELECT_B32`, `S_BFM_B32`, `S_MUL_I32`, `S_MUL_HI_{U32,I32}`, `S_BFE_{U32,I32}`, `S_ABSDIFF_I32`, `S_LSHL{1,2,3,4}_ADD_U32` | The guide's section 12.1 result, computed exactly and reduced modulo 2^32. Min and max compare strictly (a tie gives S1, SCC = 0); CSELECT reads SCC and refuses it unset; BFM, MUL, MUL_HI and CSELECT leave SCC unchanged; BFE uses offset S1[4:0] and width S1[22:16] (32 or more keeps every shifted bit); ABSDIFF negates the wrapped difference; LSHLn_ADD sets SCC to the carry of the exact sum. Descriptor SGPRs are reserved. |
|
|
| 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_{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. |
|
|
| VOP2 `V_ADD_F32`, `V_MUL_F32` | Require exact binary32 results by checking the inputs and the wider intermediate. Multiplication of the significands fits in binary64. Addition must also recover the smaller operand by subtracting the larger. |
|
|
| SOPP `S_ENDPGM` | Stop at the end of the byte stream. The synthetic contract requires explicitly completed transfers and a produced output first (CLAIM-RDNA2-TRANSFER-WAITS). |
|
|
|
|
The encoding and instruction semantics are based on AMD's RDNA 2 ISA reference guide 70648, dated 30 November 2020, chapter 12 for instruction behavior and chapter 13 for microcode formats. The guide supports class B semantics for documented desktop RDNA 2. Xbox applicability is unknown. The exact gfx1030 encodings, including VGPR 255 and VOP3 source-field crossings, were checked with LLVM 23.1.6 `llvm-mc` (class E). The project uses the document as a specification reference and distributes no specification text or LLVM code. [AMD RDNA 2 ISA reference](https://www.amd.com/content/dam/amd/en/documents/radeon-tech-docs/instruction-set-architectures/rdna2-shader-instruction-set-architecture.pdf)
|
|
|
|
Run `cargo test -p xenora-ref` for fixture results, both conditional paths, invalid targets, the exact FP32 domain, truncation, wait enforcement and register-index boundaries. This author-run suite is development evidence. Independent validation and three-way decode agreement are separately tracked release gates.
|
|
|
|
## Second independent interpreter (semantic review)
|
|
|
|
`tests/validation/independent_ref.rs` is a second interpreter for the same subset, written for the semantic-review suite. It imports neither `xenora-decoder`, `xenora-isa` nor `xenora-ref`; it re-decodes the RDNA 2 encoding fields and executes a program-counter machine. The review test `second_interpreter_agrees_with_reference_on_boundary_and_random_inputs` compares the two interpreters on all three demo fixtures over boundary-dense and pseudorandom inputs (about 3,268 inputs per fixture, including the 2^32 addition wrap, the FP32 selection bit and signed/unsigned extremes). The CPU implementations agree under the bounded synthetic gfx1030 fixture contract. Xbox applicability is unknown. This is R2-owned validation and is distinct from the production reference.
|
|
|