test: harden independent Phase 01 oracle and record assurance

This commit is contained in:
Ranveer Soni committed 2026-11-22 18:48:08 +05:30
1 parent aff46b0904
commit 5c479005b0
16 files changed
+783 -99

No files matched your search

+1
View File
@@ -38,6 +38,7 @@ jobs:
cargo test --locked --workspace
scripts/audit/dependencies.sh
scripts/audit/claims.sh
python3 scripts/audit/status.py --check
- name: Inspect native CLI
run: |
cargo build --locked -p xenora
+1
View File
@@ -54,6 +54,7 @@ Read docs/interfaces.md and docs/progress.md before implementation.
- Run independent CPU validation: `cargo test --locked -p xenora-semantic-review`
- Run the correctness-gated benchmark suite: `scripts/benchmark.sh` (idle machine, release, validation off)
- Run source mutation on decoder/shader/ref: `scripts/mutation.sh` (R2 owns triage)
- Check generated status tables: `python3 scripts/audit/status.py --check`.
- Check claims and dependency direction: `scripts/audit/claims.sh` and `scripts/audit/dependencies.sh`
- Fuzz one CPU-only parser at a time: `scripts/fuzz.sh <instruction_stream|fixture|reference>` (600 seconds by default).
+10
View File
@@ -29,6 +29,16 @@ flowchart TD
Run `scripts/demo.sh` to execute three original gfx1030 compute fixtures on Apple Silicon. Integer addition, bitwise and scalar branch, and restricted FP32 outputs matched the independent CPU reference and hand-derived values on Apple M5 (class A, CLAIM-METAL-M5-RDNA-DEMO). Run `scripts/test-gpu.sh` for native Metal correctness, including offscreen rendering with original MSL (class A, CLAIM-METAL-M5-NATIVE-SUITE). The [status file](docs/status.toml) records the verified scope. SPIR-V may be used as an optional compiler intermediate representation without introducing a Vulkan runtime dependency.
## Host and guest compatibility
<!-- status:features:start -->
| Feature | Target | Implementation | Correctness | Hardware | Evidence | Limits |
| --- | --- | --- | --- | --- | --- | --- |
| native-compute | arm64 macOS | implemented | initial-native-suite-passed | verified on Apple M5 | A | Trusted MSL with bounded word buffers and an original native offscreen rendering test on Apple M5. |
| synthetic-gfx1030 | gfx1030 Wave32 | three-fixture-demo-implemented | three-way-output-passed | verified on Apple M5 | A, B | Synthetic memory contract, statically resolved forward control flow, exact positive normal FP32 only. |
| xbox-execution | Xbox Series X\|S | unsupported | untested | unverified | U | Game execution, proprietary guest containers and full guest execution-mask divergence are unsupported. The console launch ABI is unknown. |
<!-- status:features:end -->
## Development roadmap
The following describes the project's intended development stages, not a claim that the features are already implemented.
+22 -1
View File
@@ -181,10 +181,11 @@ uncertainty = "Availability of the feature does not establish Xenora correctness
[[claim]]
id = "CLAIM-METAL-NATIVE-CONTRACTS"
class = "B"
claim = "Metal dispatchThreads specifies an exact grid subject to supported dispatch and pipeline limits. Shared storage is accessible to CPU and GPU, and waitUntilCompleted waits for command-buffer completion."
claim = "Metal dispatchThreads specifies an exact grid subject to supported dispatch and pipeline limits. Shared storage is accessible to CPU and GPU, makeBuffer(bytes:length:options:) copies initialization bytes, and waitUntilCompleted waits for command-buffer completion."
sources = [
"https://developer.apple.com/documentation/metal/calculating-threadgroup-and-grid-sizes",
"https://developer.apple.com/documentation/metal/choosing-a-resource-storage-mode-for-apple-gpus",
"https://developer.apple.com/documentation/metal/mtldevice/makebuffer(bytes:length:options:)",
"https://developer.apple.com/documentation/metal/mtlcommandbuffer/waituntilcompleted()",
]
retrieved = "2026-11-22"
@@ -201,3 +202,23 @@ retrieved = "2026-11-22"
architecture = "AMD RDNA 2, document 70648"
test = "Reviewed the wait and program-termination descriptions. Workspace tests exercise the stricter synthetic wait rule."
uncertainty = "The fixture requires explicit waits and does not establish console behavior."
[[claim]]
id = "CLAIM-MSL-COMPUTE-TYPES"
class = "B"
claim = "MSL defines uint as a 32-bit unsigned integer, the device address space for device-allocated buffers, and thread_position_in_grid for compute invocation coordinates."
sources = ["https://developer.apple.com/metal/Metal-Shading-Language-Specification.pdf"]
retrieved = "2026-11-22"
architecture = "Metal Shading Language scalar types, address spaces and compute attributes"
test = "Reviewed the scalar type table, section 4.1 and compute function declarations. The checked native fixtures use these interfaces."
uncertainty = "These language rules do not establish a console resource ABI."
[[claim]]
id = "CLAIM-XBOX-SERIES-X-DCU"
class = "D"
claim = "Microsoft's Hot Chips 32 presentation describes the Series X GPU as 26 active Dual Compute Units and labels LDS within its Dual Compute Unit diagram."
sources = ["https://hc32.hotchips.org/assets/program/conference/day1/HotChips2020_GPU_Microsoft_Jeff_Andrews_v2.pdf"]
retrieved = "2026-11-22"
architecture = "Xbox Series X, Hot Chips 32 architectural presentation"
test = "Read slides 12 and 13. No console execution."
uncertainty = "The slides do not specify opcode semantics, an ABI or a command packet layout."
+6 -6
View File
@@ -1,6 +1,6 @@
# Phase 01 checkpoint
**NOT RELEASE-READY.** The three-fixture demo checkpoint was pushed at `96cff7c66e55f1e4693ace19577c207795258d5c` and its [Native Rust checks](https://github.com/ranveersoni98/Xenora/actions/runs/45001680455) passed. See the [engineering report](testing/phase01-checkpoint.md) for gate status and subsequent assurance evidence.
**NOT RELEASE-READY.** The three-fixture demo checkpoint was pushed at `96cff7c66e55f1e4693ace19577c207795258d5c` and its [Native Rust checks](https://github.com/ranveersoni98/Xenora/actions/runs/45001680455) passed. See the [current assurance report](testing/phase01-assurance.md) for candidate evidence and the [historical engineering report](testing/phase01-checkpoint.md) for the initial checkpoint.
## Reproduce
@@ -25,8 +25,8 @@ The independent CPU validation tests are part of the workspace. The native suite
## Remaining work
1. G7 is the immediate priority. The historical source campaign at `a34dadc` reported 387 mutants. The targeted rerun and accounting rules are in [mutation testing](testing/mutation.md). Run the complete source campaign against the clean candidate, then run the separate semantic and oracle campaigns with R2.
2. G5–G6 require independent R2 validation against the candidate. The automated three-way comparison covers all 15 decoded forms. Reproduce with the LLVM command above.
3. G9 has three successful historical 601-second transcripts in `artifacts/g9/`. Record candidate scope, nightly version and individual process exit codes on the confirmation run. Run `scripts/fuzz.sh instruction_stream`, `scripts/fuzz.sh fixture` and `scripts/fuzz.sh reference` serially.
4. G10 has a tracked [battery run](../benchmarks/results/apple-m5/run-1795338391/report.md). A second exploratory run used AC power. [Benchmark protocol and outstanding coverage](testing/benchmarks.md#exploratory-ac-run).
5. G11 remains open for objc2 SDK-derived binding redistribution and the pinned license inventory audit. See the [runtime redistribution review](licenses.md#runtime-redistribution-review). R1 also owns the claims, history and status audits. Both reviewers must review the final candidate.
1. Finish G7 independent oracle assurance. The complete source campaign at `aff46b0` killed 359 of 361 non-equivalent eligible mutants. The native semantic campaign killed all 12. The separate 44-case oracle campaign exposed seven independent-test gaps. R2’s witness tests are integrated. Rerun the [mutation commands](testing/mutation.md) against the resulting candidate.
2. Preserve the G6 R2 sign-off. The G5 form-by-form report is in `tests/validation/README.md`. Confirm independent-oracle sensitivity on the integrated candidate. Run `cargo test --locked -p xenora-semantic-review` before candidate regression and mutation runs.
3. Complete the affected candidate fixture fuzz run and record exit, duration, counts and log hash. `CARGO_BUILD_JOBS=2 scripts/fuzz.sh fixture 600`. Decoder and reference historical transcripts are under `artifacts/g9/`.
4. Finish benchmark corpus and protocol coverage before rerunning on AC and an idle system. Preserve the [exploratory battery and AC records](testing/benchmarks.md).
5. Close independent claims, status, history and review findings against the integrated candidate. Verify the [runtime redistribution blockers](licenses.md#runtime-redistribution-review) before claiming G11.
+1 -1
View File
@@ -1,5 +1,5 @@
# Xbox Series X|S GPU evidence
Microsoft describes Series X and Series S as using custom RDNA 2 GPUs (CLAIM-XBOX-RDNA2). Its Hot Chips 32 presentation describes the Series X GPU at the architectural block level, including Dual Compute Units, per-unit local storage, and the command processor. The public AMD RDNA 2 ISA is the architectural source for the chosen synthetic target. Any transfer of a desktop ISA statement to the console requires separate evidence (CLAIM-XBOX-ISA-ABI). [Series X announcement](https://news.xbox.com/en-us/2020/07/14/a-closer-look-at-xbox-velocity-architecture/), [Series S specifications](https://www.xbox.com/en-US/consoles/xbox-series-s#specs), [Hot Chips 32 slides](https://hc32.hotchips.org/assets/program/conference/day1/HotChips2020_GPU_Microsoft_Jeff_Andrews_v2.pdf), [AMD architecture documentation](https://gpuopen.com/amd-gpu-architecture-programming-documentation/)
Microsoft describes Series X and Series S as using custom RDNA 2 GPUs (CLAIM-XBOX-RDNA2). Microsoft’s Hot Chips 32 slides describe 26 active Dual Compute Units and show LDS in the Series X Dual Compute Unit diagram (class D, CLAIM-XBOX-SERIES-X-DCU). The public AMD RDNA 2 ISA is the architectural source for the chosen synthetic target. Any transfer of a desktop ISA statement to the console requires separate evidence (CLAIM-XBOX-ISA-ABI). [Series X announcement](https://news.xbox.com/en-us/2020/07/14/a-closer-look-at-xbox-velocity-architecture/), [Series S specifications](https://www.xbox.com/en-US/consoles/xbox-series-s#specs), [Hot Chips 32 slides](https://hc32.hotchips.org/assets/program/conference/day1/HotChips2020_GPU_Microsoft_Jeff_Andrews_v2.pdf), [AMD architecture documentation](https://gpuopen.com/amd-gpu-architecture-programming-documentation/)
The reviewed sources leave console opcode and operand differences, shader entry state, descriptor layout, guest GPU address rules, and command packet encoding unresolved. Record these separately when evaluating future public evidence. A test using gfx1030 bytes exercises the declared Xenora fixture contract. LLVM's AMDGPU table identifies gfx1030 as a desktop GFX10.3 RDNA 2 target (CLAIM-LLVM-GFX1030). [LLVM AMDGPU processor table](https://llvm.org/docs/AMDGPUUsage.html#processors)
+23 -22
View File
@@ -5,16 +5,28 @@ stream under the [synthetic memory ABI](../adr/0003-demo-memory-model.md).
Recognition means that the opcode mask matches. Decode additionally checks
operands, flags, instruction width and any literal word. Register
initialization and memory safety require verification after decoding.
CPU and GPU entries refer to the original synthetic fixture workloads.
The wider LLVM operand matrix exercises decoding only.
| Form | Accepted encoding and operands | Size | Recognized | Decoded | LLVM fixture comparison |
| --- | --- | --- | --- | --- | --- |
| `buffer_load_dword` | MUBUF, VGPR data/index, four normal SGPRs, `idxen`, zero offsets and remaining flags | 8 B | yes | yes | pass |
| `s_waitcnt vmcnt(0)` | SOPP, exact immediate `0x3f70`; other counters disabled by their maximum values | 4 B | yes | yes | pass |
| `v_mov_b32_e32` | VOP1, VGPR destination, VGPR or inline integer or literal source, plus the inline bit pattern for +1.0f | 4 or 8 B | yes | yes | pass for literal, inline zero and inline +1.0f |
| `v_add_nc_u32_e64` | VOP3, VGPR destination and two VGPR inputs, modifier fields clear, third source field encoded as inline zero | 8 B | yes | yes | pass |
| `buffer_store_dword` | MUBUF, VGPR data/index, four normal SGPRs, `idxen`, zero offsets and remaining flags | 8 B | yes | yes | pass |
| `s_waitcnt_vscnt null, 0` | SOPK, exact null source and zero immediate | 4 B | yes | yes | pass |
| `s_endpgm` | SOPP, zero immediate | 4 B | yes | yes | pass |
<!-- status:instructions:start -->
| Form | Operands | Size or word | Recognized | Decoded | LLVM | Lowering | Reference | CPU | GPU |
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
| `buffer_load_dword` | MUBUF, VGPR data/index, four normal SGPRs, `idxen`, zero offsets and remaining flags | 8 B | yes | yes | three-way passed | MSL load | implemented | fixture verified | fixture verified |
| `s_waitcnt vmcnt(0)` | SOPP, exact immediate `0x3f70`; other counters disabled by their maximum values | 4 B | yes | yes | three-way passed | verified load wait | implemented | fixture verified | fixture verified |
| `v_mov_b32_e32` | VOP1, VGPR destination, VGPR or inline integer or literal source, plus the inline bit pattern for +1.0f | 4 or 8 B | yes | yes | three-way passed | constant or register value | implemented | fixture verified | fixture verified |
| `v_add_nc_u32_e64` | VOP3, VGPR destination and two VGPR inputs, modifier fields clear, third source field encoded as inline zero | 8 B | yes | yes | three-way passed | MSL unsigned add | implemented | fixture verified | fixture verified |
| `buffer_store_dword` | MUBUF, VGPR data/index, four normal SGPRs, `idxen`, zero offsets and remaining flags | 8 B | yes | yes | three-way passed | MSL store | implemented | fixture verified | fixture verified |
| `s_waitcnt_vscnt null, 0` | SOPK, exact null source and zero immediate | 4 B | yes | yes | three-way passed | verified store wait | implemented | fixture verified | fixture verified |
| `s_endpgm` | SOPP, zero immediate | 4 B | yes | yes | three-way passed | verified termination | implemented | fixture verified | fixture verified |
| `s_mov_b32` | Normal SGPR destination and normal SGPR, inline integer or literal source | `BE880387` | yes | yes | three-way passed | resolved scalar state | implemented | fixture verified | fixture verified |
| `s_cmp_eq_u32` | Normal SGPR or integer operands, with at most one source selecting a literal | `BF068708` | yes | yes | three-way passed | resolved SCC | implemented | fixture verified | fixture verified |
| `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 |
| `v_xor_b32_e32` | Two VGPR sources and one VGPR destination | `3A020702` | yes | yes | three-way passed | MSL bitwise XOR | implemented | fixture verified | fixture verified |
| `v_add_f32_e32` | Two VGPR sources and one VGPR destination | `06020702` | yes | yes | three-way passed | MSL FP32 add | implemented | fixture verified | fixture verified |
| `v_mul_f32_e32` | Two VGPR sources and one VGPR destination | `10020702` | yes | yes | three-way passed | MSL FP32 multiply | implemented | fixture verified | fixture verified |
<!-- status:instructions:end -->
## Automated three-way comparison
@@ -56,23 +68,12 @@ scripts/demo.sh
The [source notes](../research/rdna2.md) record the XML revision and license.
## Expansion variants
## Operand and execution notes
AMD RDNA 2 ISA §§12.3–12.5 and 12.7 define these forms. AMD's pinned XML
AMD RDNA 2 ISA §§12.3–12.5 and 12.7 define the scalar and vector forms. AMD's pinned XML
and native LLVM 23.1.6 agree on the representative words. The target of each
branch is the byte offset after its four-byte instruction plus four times the
sign-extended 16-bit displacement. This subset requires forward targets at
instruction boundaries. The vector forms carry two VGPR sources and no
modifiers. Floating-point arithmetic and its mode constraints are execution
requirements outside the decoder.
| Form | Operands | Representative LLVM encoding | Recognized | Decoded | LLVM fixture comparison |
| --- | --- | --- | --- | --- | --- |
| `s_mov_b32` | Normal SGPR destination and normal SGPR, inline integer or literal source | `BE880387` | yes | yes | pass |
| `s_cmp_eq_u32` | Normal SGPR or integer operands, with at most one source selecting a literal | `BF068708` | yes | yes | pass |
| `s_cbranch_scc0` | Nonnegative signed dword displacement | `BF840002` | yes | yes | pass |
| `s_branch` | Nonnegative signed dword displacement | `BF820001` | yes | yes | pass |
| `v_and_b32_e32` | Two VGPR sources and one VGPR destination | `36020702` | yes | yes | pass |
| `v_xor_b32_e32` | Two VGPR sources and one VGPR destination | `3A020702` | yes | yes | pass |
| `v_add_f32_e32` | Two VGPR sources and one VGPR destination | `06020702` | yes | yes | pass |
| `v_mul_f32_e32` | Two VGPR sources and one VGPR destination | `10020702` | yes | yes | pass |
+1 -1
View File
@@ -4,7 +4,7 @@ The compiler accepts explicitly tagged raw gfx1030 code up to 1,024 bytes and re
Verification maps each initialized register to its latest typed temporary. Reads after a load require a load wait. Because generated memory accesses are synchronous expressions within a thread and buffers are disjoint, waits can be discharged during verification. Metal completion is still required before host readback. Store and load aliases between lanes are excluded by the [fixture ABI](../adr/0003-demo-memory-model.md). The output buffer uses Metal index 1 and the read-only input uses index 0.
Apple documents `uint`, device address space and the scalar compute grid-position attribute used here. Class B applies to those MSL language features. [Metal Shading Language Specification](https://developer.apple.com/metal/Metal-Shading-Language-Specification.pdf)
Apple documents `uint`, device address space and the scalar compute grid-position attribute used here. These MSL language features are class B (CLAIM-MSL-COMPUTE-TYPES). [Metal Shading Language Specification](https://developer.apple.com/metal/Metal-Shading-Language-Specification.pdf)
The integer emitter uses unsigned addition, bitwise AND and bitwise XOR. Scalar moves and compares are evaluated at translation time using known SGPR initializers. Forward branches must target instruction boundaries, and a conditional branch requires initialized SCC. The IR records the statically selected path. Scalar values can originate only from constants and initialized SGPRs, and SGPR 0–7 remain reserved for synthetic descriptors. The generated kernel executes the selected path without physical GPU branching.
+188
View File
@@ -7,8 +7,11 @@ id = "native-compute"
implementation = "implemented"
correctness = "initial-native-suite-passed"
hardware_verification = "verified"
hardware_target = "Apple M5"
claims = ["CLAIM-METAL-M5-NATIVE-SUITE"]
architecture = "arm64 macOS"
semantics = "Native Metal work submissions with bounded resources"
metal_mapping = "Native compute kernels and an original offscreen render test"
limitations = "Trusted MSL with bounded word buffers and an original native offscreen rendering test on Apple M5."
test = "scripts/test-gpu.sh"
@@ -17,8 +20,11 @@ id = "synthetic-gfx1030"
implementation = "three-fixture-demo-implemented"
correctness = "three-way-output-passed"
hardware_verification = "verified"
hardware_target = "Apple M5"
claims = ["CLAIM-METAL-M5-RDNA-DEMO", "CLAIM-RDNA2-ADD-NO-CARRY"]
architecture = "gfx1030 Wave32"
semantics = "Original gfx1030 compute code under the synthetic fixture ABI"
metal_mapping = "One lane-indexed MSL compute invocation per word"
limitations = "Synthetic memory contract, statically resolved forward control flow, exact positive normal FP32 only."
test = "scripts/demo.sh"
@@ -29,4 +35,186 @@ correctness = "untested"
hardware_verification = "unverified"
claims = ["CLAIM-XBOX-ISA-ABI"]
architecture = "Xbox Series X|S"
semantics = "Console-specific GPU and guest execution contracts remain unknown"
metal_mapping = "Unresolved"
limitations = "Game execution, proprietary guest containers and full guest execution-mask divergence are unsupported. The console launch ABI is unknown."
[[instruction]]
form = "buffer_load_dword"
encoding = "MUBUF, VGPR data/index, four normal SGPRs, `idxen`, zero offsets and remaining flags"
representation = "8 B"
lowering = "MSL load"
reference = "implemented"
cpu = "fixture verified"
gpu = "fixture verified"
recognized = true
decoded = true
llvm = "three-way passed"
[[instruction]]
form = "s_waitcnt vmcnt(0)"
encoding = "SOPP, exact immediate `0x3f70`; other counters disabled by their maximum values"
representation = "4 B"
lowering = "verified load wait"
reference = "implemented"
cpu = "fixture verified"
gpu = "fixture verified"
recognized = true
decoded = true
llvm = "three-way passed"
[[instruction]]
form = "v_mov_b32_e32"
encoding = "VOP1, VGPR destination, VGPR or inline integer or literal source, plus the inline bit pattern for +1.0f"
representation = "4 or 8 B"
lowering = "constant or register value"
reference = "implemented"
cpu = "fixture verified"
gpu = "fixture verified"
recognized = true
decoded = true
llvm = "three-way passed"
[[instruction]]
form = "v_add_nc_u32_e64"
encoding = "VOP3, VGPR destination and two VGPR inputs, modifier fields clear, third source field encoded as inline zero"
representation = "8 B"
lowering = "MSL unsigned add"
reference = "implemented"
cpu = "fixture verified"
gpu = "fixture verified"
recognized = true
decoded = true
llvm = "three-way passed"
[[instruction]]
form = "buffer_store_dword"
encoding = "MUBUF, VGPR data/index, four normal SGPRs, `idxen`, zero offsets and remaining flags"
representation = "8 B"
lowering = "MSL store"
reference = "implemented"
cpu = "fixture verified"
gpu = "fixture verified"
recognized = true
decoded = true
llvm = "three-way passed"
[[instruction]]
form = "s_waitcnt_vscnt null, 0"
encoding = "SOPK, exact null source and zero immediate"
representation = "4 B"
lowering = "verified store wait"
reference = "implemented"
cpu = "fixture verified"
gpu = "fixture verified"
recognized = true
decoded = true
llvm = "three-way passed"
[[instruction]]
form = "s_endpgm"
encoding = "SOPP, zero immediate"
representation = "4 B"
lowering = "verified termination"
reference = "implemented"
cpu = "fixture verified"
gpu = "fixture verified"
recognized = true
decoded = true
llvm = "three-way passed"
[[instruction]]
form = "s_mov_b32"
encoding = "Normal SGPR destination and normal SGPR, inline integer or literal source"
representation = "`BE880387`"
lowering = "resolved scalar state"
reference = "implemented"
cpu = "fixture verified"
gpu = "fixture verified"
recognized = true
decoded = true
llvm = "three-way passed"
[[instruction]]
form = "s_cmp_eq_u32"
encoding = "Normal SGPR or integer operands, with at most one source selecting a literal"
representation = "`BF068708`"
lowering = "resolved SCC"
reference = "implemented"
cpu = "fixture verified"
gpu = "fixture verified"
recognized = true
decoded = true
llvm = "three-way passed"
[[instruction]]
form = "s_cbranch_scc0"
encoding = "Nonnegative signed dword displacement"
representation = "`BF840002`"
lowering = "resolved conditional branch"
reference = "implemented"
cpu = "fixture verified"
gpu = "fixture verified"
recognized = true
decoded = true
llvm = "three-way passed"
[[instruction]]
form = "s_branch"
encoding = "Nonnegative signed dword displacement"
representation = "`BF820001`"
lowering = "resolved branch"
reference = "implemented"
cpu = "fixture verified"
gpu = "fixture verified"
recognized = true
decoded = true
llvm = "three-way passed"
[[instruction]]
form = "v_and_b32_e32"
encoding = "Two VGPR sources and one VGPR destination"
representation = "`36020702`"
lowering = "MSL bitwise AND"
reference = "implemented"
cpu = "fixture verified"
gpu = "fixture verified"
recognized = true
decoded = true
llvm = "three-way passed"
[[instruction]]
form = "v_xor_b32_e32"
encoding = "Two VGPR sources and one VGPR destination"
representation = "`3A020702`"
lowering = "MSL bitwise XOR"
reference = "implemented"
cpu = "fixture verified"
gpu = "fixture verified"
recognized = true
decoded = true
llvm = "three-way passed"
[[instruction]]
form = "v_add_f32_e32"
encoding = "Two VGPR sources and one VGPR destination"
representation = "`06020702`"
lowering = "MSL FP32 add"
reference = "implemented"
cpu = "fixture verified"
gpu = "fixture verified"
recognized = true
decoded = true
llvm = "three-way passed"
[[instruction]]
form = "v_mul_f32_e32"
encoding = "Two VGPR sources and one VGPR destination"
representation = "`10020702`"
lowering = "MSL FP32 multiply"
reference = "implemented"
cpu = "fixture verified"
gpu = "fixture verified"
recognized = true
decoded = true
llvm = "three-way passed"
+4 -3
View File
@@ -1,7 +1,7 @@
# Benchmark protocol
The benchmark harness measures every shader in the correctness corpus that passes
its correctness test in the same run. It never reports a number for a shader that
The benchmark harness measures each fixture in its manifest that passes its
correctness test in the same run. It never reports a number for a shader that
failed or was skipped.
## Corpus
@@ -87,7 +87,8 @@ with AC power confirmed before and after, 30 seconds between the build and
timing, two warmups, 21 measured repetitions per size and Metal validation
off. Neither thermal nor performance warnings were recorded by
`pmset -g therm`. All three declared translated fixtures passed their
correctness checks. G10 remains open for the full correctness corpus,
correctness checks. The recorded 1-, 5- and 15-minute load averages were
8.12, 8.68 and 6.31, so an idle environment was not established. G10 remains open for the full correctness corpus,
individual compiler stages and cold/warm timing, tool and capability metadata,
and noise-based variability reporting. See the
[generated report](../../benchmarks/results/apple-m5/run-1795352394/report.md).
+82
View File
@@ -60,3 +60,85 @@ R2 identified diagnostic, scalar and vector selector, fixture limit, transfer
ordering, reserved register and exact FP32 verifier regressions for the
remaining survivors. The targeted rerun records which tests actually
distinguish each mutant.
## Complete source campaign at aff46b0
Run from the clean candidate on 2026-11-22 with native ARM64 cargo-mutants
27.1.0 and two workers.
```sh
CARGO_BUILD_JOBS=2 scripts/mutation.sh artifacts/mutation/source-aff46b0
```
The 399-entry inventory and finished outcomes contain the same identities.
The baseline passed. Cargo-mutants exited 3 after reporting 360 caught,
13 missed, 25 unviable, and one timeout. Independent R2 review inspected
every survivor, every unviable compilation and each raw caught log.
The conservative count credits named behavioral test failures only.
| Module | Generated | Raw caught | Verified kills | Raw misses | Equivalent | Invalid | Timeout | Other non-progress | Non-equivalent score |
| --- | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: |
| Decoder | 116 | 102 | 102 | 1 | 1 | 12 | 1 | 0 | 102/103 (99.03%) |
| Reference | 171 | 161 | 160 | 5 | 5 | 5 | 0 | 1 | 160/161 (99.38%) |
| Shader parser, verification and lowering | 112 | 97 | 97 | 7 | 7 | 8 | 0 | 0 | 97/97 (100%) |
| **Total** | **399** | **360** | **359** | **13** | **13** | **25** | **1** | **1** | **359/361 (99.45%)** |
The 13 raw misses were all independently reviewed as equivalent. The
historical location table above applies except for the two shader branch
guards moved during the whole-stream verification fix.
- Shader `279:20`, entire guard replaced with false. `lift` is private and
receives decoder output only. The decoder rejects negative displacements
and targets outside instruction boundaries. The guard's original predicate
is always false.
- Shader `280:21`, OR changed to AND. The same input contract makes both
components false, so the combined predicate is still false.
- The 25 invalid entries are 22 missing `Default` implementations, one
ambiguous trait call, and two unsupported OR operators in a let chain.
The ledger maps every entry to the compiler log and mutation diff.
- Decoder `120:16`, `+=` changed to `*=`, built successfully and explicitly
timed out after 300 seconds. A successfully decoded instruction leaves
the initially zero byte offset at zero, so the loop repeats.
- Reference `235:16` applies the same change to the independent byte
offset. The test process received SIGKILL after about 183 seconds, with
no assertion failure. The mutant repeatedly appends the same instruction
at offset zero. The signal's origin was not recorded. This entry remains
in the denominator, separate from the explicit timeout.
The ignored `artifacts/mutation/source-aff46b0/` directory contains
`environment.log`, `exit-code`, `ledger.tsv`, `ledger-summary.txt`, and
the original `mutants.out/` reports with per-mutant logs and diffs.
| Artifact | SHA-256 |
| --- | --- |
| `mutants.out/mutants.json` | `1776e2a91e91f0e451ef6a24c483cda6251e2ae8561222bae665564d2edbe8a6` |
| `mutants.out/outcomes.json` | `ff258c717976d1f9cb74ce776413200418fff04ffe5f81fad30f8932a6335d24` |
| `ledger.tsv` | `fabd5488d0954f8778d118708f55e3818902d60788dcf4b877b108639513ae05` |
## Semantic and oracle campaigns at aff46b0
The [native semantic suite](../../tests/mutation/README.md) killed all 12
enumerated mutations with both Metal validation layers enabled on Apple M5.
Every unmodified GPU readback matched six hand-derived words and the CPU
reference. Each deliberately changed shader then ran successfully and
returned different words. R1 independently verified the scope, output and
30-second child process cutoff. Raw log
`artifacts/assurance-aff46b0/semantic.log` and exit 0.
The oracle-only campaign mutated all generated `vector_alu` and
`execute_lane` entries and ran the independent validation package alone.
```sh
CARGO_BUILD_JOBS=2 cargo mutants --file crates/ref/src/lib.rs \
--re ' in (vector_alu|execute_lane)$|replace (vector_alu|execute_lane) ->' \
--test-package xenora-semantic-review --jobs 2 --timeout 60 \
--output artifacts/mutation/oracle-aff46b0
```
Of 44 mutations, 37 were caught and seven survived. The survivors were the
three changed operators in the FP32 operand guard at 287, the load or index
guard at 339, the output write check at 350, the resource SGPR test at 367,
and the outstanding transfer check at 392. They remain test gaps in the
independent oracle package. Source and native semantic evidence are
complete for the reviewed candidate. G7 remains open pending independent
oracle follow-up.
+70
View File
@@ -0,0 +1,70 @@
# Phase 01 assurance checkpoint
**NOT RELEASE-READY.** The full source mutation campaign and native
technical evidence in this checkpoint ran from the clean
`aff46b0904a0182a6f0543125e4491ab67270f64` candidate on 2026-11-22. The
exploratory AC benchmark ran at `cc0daa79e63c468e748f0333bd1314224752893a`.
Later changes have separate evidence. Nothing was published from this sprint.
The test machine was a native Apple M5 MacBook Air with macOS 27.3
(26C5047e), Rust 1.100.0, Xcode 27.2 (27B52), and Homebrew LLVM 23.1.6.
Commands, effective environment and exit statuses are in ignored
`artifacts/assurance-aff46b0/{commands,environment,exits}.log`. PASS means the
listed gate has candidate evidence, and FAIL or BLOCKED means it remains
unmet.
| Gate | Status | Evidence and remaining work |
| --- | --- | --- |
| G1 | PASS | `scripts/audit/native.sh` exited 0. Host was ARM64 with translation off. All 15 checked workspace executables or loadable dependencies were ARM64 with no Vulkan or MoltenVK linkage. The release benchmark and dependency graph were checked separately in `additional-linkage.log`. |
| G2 | PASS | Formatting, all-target and all-feature Clippy with warnings denied, and locked workspace tests exited 0. 46 tests passed and two LLVM tests ran separately under G6. |
| G3 | PASS | `scripts/test-gpu.sh` exited 0. 12 Metal tests passed with zero skips and both validation layers active on Apple M5, including 48 offscreen RGBA8 pixels. |
| G4 | PASS | `scripts/demo.sh` exited 0. All three original synthetic gfx1030 fixtures returned the hand-derived outputs and matched the CPU reference. |
| G5 | BLOCKED | The candidate's five validation tests passed. R2 identified and corrected defects in an isolated second-interpreter draft, which passed 10 Rust tests against the candidate crates. Integration and renewed oracle sensitivity checks remain open. |
| G6 | PASS | Both Homebrew LLVM tests passed. The two Xenora decoders and LLVM matched 303 instructions from all 15 supported forms, with three malformed and six out-of-subset probes. R2 signed off on this exact candidate and scope. |
| G7 | FAIL | Full source score 359/361 (99.45%) after R2 review. All 13 raw misses were equivalent and the two non-progress outcomes remain in the denominator. All 12 native semantic mutations were killed. Seven of 44 mutations survived the independent oracle-only campaign. See [mutation testing](mutation.md). |
| G8 | BLOCKED | Candidate claims lint exited 0 with 18 entries. Follow-up claims and generated status checks passed with 20 entries. Complete the independent prose coverage audit on the final candidate. |
| G9 | BLOCKED | Historical logs show 435,803,394 executions across three 601-second campaigns. The verifier change invalidated fixture fuzz coverage. The refreshed candidate fixture campaign was started at 18:44 IST. |
| G10 | BLOCKED | The historical battery and new exploratory AC evidence are preserved. The AC run covered the three declared translated fixtures. Idleness, complete protocol and corpus coverage remain unresolved. See [benchmark protocol](benchmarks.md). |
| G11 | BLOCKED | The updated inventory records six active dependencies. Both lockfiles passed the local advisory scan. Pinned-binding attribution and SDK-derived compiled redistribution rights remain open. See [licensing](../licenses.md#runtime-redistribution-review). |
| G12 | BLOCKED | Strict Git integrity and scans of all 19 reachable commits found no matching private paths, credentials or tracked artifacts. Expected local directories are ignored. Missing contribution attestations remain a policy finding. See `hygiene.log` for exact results. |
| G13 | BLOCKED | README, interfaces and status describe the tested scope. The status generation and consistency check were added after the source candidate. Independent confirmation of the integrated checkout remains. |
| G14 | PASS | `scripts/audit/dependencies.sh` exited 0, checking five graphics crates. The [CPU boundary ADR](../adr/0004-cpu-boundary.md) records the direction and guest address translation contract. |
| G15 | BLOCKED | R1 independently reviewed documentation, licensing, AC benchmark provenance and semantic campaign safety. R2 independently reviewed the source campaign, LLVM evidence and reference assurance. The oracle, benchmark, licensing and final integrated review findings remain unresolved. |
## Commands
```sh
export CARGO_BUILD_JOBS=2
export LLVM_BIN="$(brew --prefix llvm)/bin"
export PATH="$LLVM_BIN:$PATH"
scripts/bootstrap.sh
cargo fmt --all -- --check
cargo clippy --locked --workspace --all-targets --all-features -- -D warnings
cargo test --locked --workspace
scripts/assemble-fixture.sh --check
cargo test --locked -p xenora-decoder --test gfx1030 -- --ignored --nocapture
scripts/test-gpu.sh
scripts/demo.sh
cargo run --locked -p xenora-semantic-review --example semantic-mutation --features native-mutation
scripts/audit/native.sh
scripts/audit/claims.sh
python3 scripts/audit/status.py --check
scripts/audit/dependencies.sh
cargo audit --no-fetch
cargo audit --no-fetch --file fuzz/Cargo.lock
```
The native readbacks agree with the independent reference and hand-derived
words for all three unmodified shaders.
| Fixture | Readback words |
| --- | --- |
| Add | `[305419896, 305419897, 305419895, 0]` |
| Bitwise and branch | `[305419896, 305419897, 315315847, 318723824]` |
| Exact FP32 | `[1091305472, 1091305472, 1092616192, 1092616192]` |
The semantic mutation suite separately executed 12 deliberately wrong
shaders and required a completed output mismatch after a matching unmodified
baseline. Compile errors, crashes, validation failures and timeouts cannot
count as semantic kills. Game execution, proprietary console containers,
full guest execution-mask divergence and a guest CPU runtime are unsupported.
+90
View File
@@ -0,0 +1,90 @@
#!/usr/bin/env python3
# SPDX-License-Identifier: GPL-3.0-or-later
"""Render the feature and instruction tables from the checked-in status registry."""
import argparse
from pathlib import Path
import sys
import tomllib
def table(headers, rows):
def line(cells):
return "| " + " | ".join(str(cell).replace("|", r"\|") for cell in cells) + " |"
return "\n".join([line(headers), line(["---"] * len(headers)), *(line(row) for row in rows)])
def replace_block(path, name, body, check):
original = path.read_text()
start = f"<!-- status:{name}:start -->\n"
stop = f"\n<!-- status:{name}:end -->"
head, _, tail = original.partition(start)
if not tail or stop not in tail:
raise ValueError(f"{path}: missing status markers")
updated = head + start + body + stop + tail.split(stop, 1)[1]
if updated == original:
return True
if check:
print(f"{path}: status table differs from docs/status.toml", file=sys.stderr)
return False
path.write_text(updated)
return True
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--check", action="store_true")
check = parser.parse_args().check
root = Path(__file__).resolve().parents[2]
docs = root / "docs"
status = tomllib.loads((docs / "status.toml").read_text())
claims = tomllib.loads((docs / "claims.toml").read_text())
classes = {claim["id"]: claim["class"] for claim in claims["claim"]}
features = table(
("Feature", "Target", "Implementation", "Correctness", "Hardware", "Evidence", "Limits"),
[
(
feature["id"],
feature["architecture"],
feature["implementation"],
feature["correctness"],
feature["hardware_verification"] + (
f" on {feature['hardware_target']}" if "hardware_target" in feature else ""
),
", ".join(sorted({classes[claim] for claim in feature["claims"]})),
feature["limitations"],
)
for feature in status["feature"]
],
)
instructions = table(
("Form", "Operands", "Size or word", "Recognized", "Decoded", "LLVM",
"Lowering", "Reference", "CPU", "GPU"),
[
(
f"`{item['form']}`",
item["encoding"],
item["representation"],
"yes" if item["recognized"] else "no",
"yes" if item["decoded"] else "no",
item["llvm"],
item["lowering"],
item["reference"],
item["cpu"],
item["gpu"],
)
for item in status["instruction"]
],
)
checks = [
replace_block(root / "README.md", "features", features, check),
replace_block(docs / "shaders/instruction-coverage.md", "instructions", instructions, check),
]
return 0 if all(checks) else 1
if __name__ == "__main__":
sys.exit(main())
+37
View File
@@ -20,3 +20,40 @@ AMD RDNA2 ISA §12.4 defines equality as an SCC update, and §12.5 uses a signed
The mask in `float-exact` erases every bit except 22 before XOR with the representation of 1. Input bit 22 then selects exactly 1 or 3/2. Adding 5/2 and multiplying by 5/2 gives 35/4 or 10, with positive normal binary32 operands and intermediate and final values. The integer input words may have arbitrary exponent bits, including NaN and infinity patterns, because the mask erases them before reinterpretation. For the verifier's general restricted domain, products of two binary32 significands fit within 48 significant bits and the normal binary32 range is inside the binary64 exponent range even after multiplying. For positive sums, the rounded binary64 sum and its larger operand are within a factor of two, so subtraction is exact by Sterbenz's lemma. Recovering the smaller operand proves the binary64 addition exact before the binary32 representability check. Tests reject a subnormal operand, a midpoint requiring binary32 rounding, binary64 absorption of the smallest normal binary32 operand, and negative infinity.
The locked validation package passed all four tests. The reviewer used CPU execution only. No independent GPU conclusion follows from these tests.
## Independent Phase 01 assurance
R2 reviewed the supported gfx1030 subset at `aff46b0` and signed off on
303 three-way comparisons over 15 instruction forms, three malformed
encoding probes and six supported-architecture encodings outside Xenora's
subset. Section 13 of AMD's RDNA2 guide describes the relevant encoding
layouts. LLVM provides class E tool evidence and the AMD architecture
guide provides class B semantics for the documented AMD target.
[AMD RDNA 2 ISA reference](https://docs.amd.com/v/u/en-US/rdna2-shader-instruction-set-architecture)
| Instructions | Independent evidence |
| --- | --- |
| `buffer_load_dword`, `buffer_store_dword` | The synthetic descriptors select separate input and output lane words. High VGPR renaming preserves outputs. Skipped invalid bindings, overlapping input operations and a second store are rejected. |
| `s_waitcnt vmcnt(0)`, `s_waitcnt_vscnt null, 0`, `s_endpgm` | Pending loads and stores block premature reads and termination. An early end is rejected even when skipped by a branch. A completed store does not discharge a later load. |
| `v_mov_b32_e32`, `v_add_nc_u32_e64` | Register moves preserve words, and a widened sum reduced modulo 2^32 supplies independent expected outputs. Coverage includes high VGPRs, in-place addition and wrap to zero. |
| `s_mov_b32`, `s_cmp_eq_u32`, `s_cbranch_scc0`, `s_branch` | SGPR and literal values select independently known branch outputs for both SCC results. The descriptor/ordinary SGPR boundary and invalid branch targets have negative cases. |
| `v_and_b32_e32`, `v_xor_b32_e32` | Fixed masks are checked with all-ones and mixed-bit words. The float fixture's mask keeps only bit 22, then XOR supplies the exponent of 1.0. |
| `v_add_f32_e32`, `v_mul_f32_e32` | Independent integer-significand verification covers exact products and sums, representational midpoint, underflow, overflow, absorption, and excluded operand classes. |
The second interpreter extracts the 24-bit significand and exponent.
For positive sums, an exponent gap of at least 24 makes the smaller
operand strictly smaller than one ULP of the larger. Smaller gaps allow
an exact integer sum in 48 bits. A product of two significands also fits
in 48 bits. A result is representable in the supported normal domain
when its reduced significant width is at most 24 bits and its normalized
exponent is between -126 and 127. This independent computation avoids
the previous secondary oracle's binary64 absorption of `1.0 + 2^-126`.
R1 independently rederived 20 expected boundary cases with rational
arithmetic and found no critical arithmetic issue in the reviewed draft.
The original draft passed 10 isolated Rust tests against the candidate
crates. The integrated suite adds witnesses for seven independent-oracle
survivors and passes 13 locked tests. The high-register and alias cases
compare both interpreters' readbacks and compiler acceptance. Native GPU
evidence continues to cover the three original fixtures. See the
[mutation report](../../docs/testing/mutation.md) for sensitivity results.
+71 -64
View File
@@ -33,8 +33,8 @@ enum Insn {
VXor(u8, u8, u8),
VAddF(u8, u8, u8),
VMulF(u8, u8, u8),
Load { data: u8, index: u8, resource: u8 },
Store { data: u8, index: u8, resource: u8 },
Load(u8),
Store(u8),
WaitRead,
WaitWrite,
End,
@@ -82,27 +82,13 @@ fn run_lane(program: &[(usize, Insn)], lane_input: u32) -> Result<u32, String> {
};
match insn {
Insn::Load {
data,
index,
resource,
} => {
if index != 0 || resource != 0 {
return Err(format!("{offset:#x}: load outside synthetic ABI"));
}
Insn::Load(data) => {
if data == 0 || pending_read.is_some() {
return Err(format!("{offset:#x}: invalid or overlapping load"));
}
pending_read = Some(data);
}
Insn::Store {
data,
index,
resource,
} => {
if index != 0 || resource != 4 {
return Err(format!("{offset:#x}: store outside synthetic ABI"));
}
Insn::Store(data) => {
let value = read_v(data)?;
if pending_write.is_some() || written.is_some() {
return Err(format!("{offset:#x}: multiple output writes"));
@@ -124,28 +110,31 @@ fn run_lane(program: &[(usize, Insn)], lane_input: u32) -> Result<u32, String> {
Src::Imm(value) => value,
Src::Reg(reg) => read_v(reg)?,
};
if dst == 0 {
return Err(format!("{offset:#x}: move writes v0"));
}
check_destination(dst, pending_read, offset)?;
vgpr[dst as usize] = Some(value);
}
Insn::VAddNc(dst, a, b) => {
let value = read_v(a)?.wrapping_add(read_v(b)?);
vgpr[dst as usize] = Some(value);
check_destination(dst, pending_read, offset)?;
let sum = u64::from(read_v(a)?) + u64::from(read_v(b)?);
vgpr[dst as usize] = Some(sum as u32);
}
Insn::VAnd(dst, a, b) => {
check_destination(dst, pending_read, offset)?;
let value = read_v(a)? & read_v(b)?;
vgpr[dst as usize] = Some(value);
}
Insn::VXor(dst, a, b) => {
check_destination(dst, pending_read, offset)?;
let value = read_v(a)? ^ read_v(b)?;
vgpr[dst as usize] = Some(value);
}
Insn::VAddF(dst, a, b) => {
check_destination(dst, pending_read, offset)?;
let value = exact_float(true, read_v(a)?, read_v(b)?, offset)?;
vgpr[dst as usize] = Some(value);
}
Insn::VMulF(dst, a, b) => {
check_destination(dst, pending_read, offset)?;
let value = exact_float(false, read_v(a)?, read_v(b)?, offset)?;
vgpr[dst as usize] = Some(value);
}
@@ -173,9 +162,6 @@ fn run_lane(program: &[(usize, Insn)], lane_input: u32) -> Result<u32, String> {
if pending_read.is_some() || pending_write.is_some() {
return Err(format!("{offset:#x}: outstanding transfer at end"));
}
if pc + 1 != program.len() {
return Err(format!("{offset:#x}: code after s_endpgm"));
}
return written.ok_or_else(|| format!("{offset:#x}: missing output store"));
}
}
@@ -184,6 +170,13 @@ fn run_lane(program: &[(usize, Insn)], lane_input: u32) -> Result<u32, String> {
Err("stream ended without s_endpgm".to_string())
}
fn check_destination(dst: u8, load: Option<u8>, offset: usize) -> Result<(), String> {
if dst == 0 || load == Some(dst) {
return Err(format!("{offset:#x}: write to the index or pending VGPR"));
}
Ok(())
}
fn index_of(program: &[(usize, Insn)], target: usize, offset: usize) -> Result<usize, String> {
program
.iter()
@@ -192,17 +185,41 @@ fn index_of(program: &[(usize, Insn)], target: usize, offset: usize) -> Result<u
}
fn exact_float(add: bool, a_bits: u32, b_bits: u32, offset: usize) -> Result<u32, String> {
let (a, b) = (f32::from_bits(a_bits), f32::from_bits(b_bits));
if !a.is_normal() || !b.is_normal() || a.is_sign_negative() || b.is_sign_negative() {
return Err(format!("{offset:#x}: float outside positive normal domain"));
fn unpack(bits: u32) -> Option<(u64, i32)> {
let biased = ((bits >> 23) & 0xff) as i32;
if bits >> 31 != 0 || !(1..=254).contains(&biased) {
return None;
}
let significand = (1 << 23) | (bits & 0x007f_ffff);
Some((u64::from(significand), biased - 127 - 23))
}
let (a, b) = (f64::from(a), f64::from(b));
let exact = if add { a + b } else { a * b };
let result = exact as f32;
if !result.is_normal() || f64::from(result) != exact {
return Err(format!("{offset:#x}: float result not exact binary32"));
let operand_error = || format!("{offset:#x}: float outside positive normal domain");
let (a, scale_a) = unpack(a_bits).ok_or_else(operand_error)?;
let (b, scale_b) = unpack(b_bits).ok_or_else(operand_error)?;
let result_error = || format!("{offset:#x}: float result not exact normal binary32");
let (integer, scale) = if add {
let scale = scale_a.min(scale_b);
// A nonzero operand at least 24 exponents lower is strictly
// less than one ULP of the larger operand and cannot sum exactly.
if scale_a.abs_diff(scale_b) >= 24 {
return Err(result_error());
}
((a << (scale_a - scale)) + (b << (scale_b - scale)), scale)
} else {
// Two 24-bit significands multiply exactly in an unsigned 64-bit word.
(a * b, scale_a + scale_b)
};
let leading = integer.ilog2();
let trailing = integer.trailing_zeros();
let exponent = scale + leading as i32;
let significant_width = leading - trailing + 1;
if significant_width > 24 || !(-126..=127).contains(&exponent) {
return Err(result_error());
}
Ok(result.to_bits())
let normalized = ((integer >> trailing) << (24 - significant_width)) as u32;
Ok((((exponent + 127) as u32) << 23) | (normalized & 0x007f_ffff))
}
fn decode(code: &[u8]) -> Result<Vec<(usize, Insn)>, String> {
@@ -210,6 +227,9 @@ fn decode(code: &[u8]) -> Result<Vec<(usize, Insn)>, String> {
let mut offset = 0;
while offset < code.len() {
let (insn, len) = decode_one(code, offset)?;
if matches!(insn, Insn::End) && offset + len != code.len() {
return Err(format!("{offset:#x}: code after s_endpgm"));
}
program.push((offset, insn));
offset += len;
}
@@ -229,27 +249,21 @@ fn decode_one(code: &[u8], offset: usize) -> Result<(Insn, usize), String> {
let first = word(code, offset)?;
let fail = |detail: &str| format!("{offset:#x}: {detail}");
// Opcode masks and values are the AMD RDNA 2 ISA encoding fields.
if first & 0xfffc_0000 == 0xe030_0000 {
// The synthetic ABI permits only idxen with zero offsets. Only the
// data VGPR varies across each complete eight-byte encoding.
if matches!(first, 0xe030_2000 | 0xe070_2000) {
let load = first == 0xe030_2000;
let expected = if load { 0x8000_0000 } else { 0x8001_0000 };
let second = word(code, offset + 4)?;
let (data, index, resource) = mubuf(second).ok_or_else(|| fail("bad MUBUF load form"))?;
if second & 0xffff_00ff != expected {
return Err(fail("buffer operand outside synthetic ABI"));
}
let data = (second >> 8) as u8;
return Ok((
Insn::Load {
data,
index,
resource,
},
8,
));
}
if first & 0xfffc_0000 == 0xe070_0000 {
let second = word(code, offset + 4)?;
let (data, index, resource) = mubuf(second).ok_or_else(|| fail("bad MUBUF store form"))?;
return Ok((
Insn::Store {
data,
index,
resource,
if load {
Insn::Load(data)
} else {
Insn::Store(data)
},
8,
));
@@ -278,6 +292,9 @@ fn decode_one(code: &[u8], offset: usize) -> Result<(Insn, usize), String> {
}
if first & 0xff80_ff00 == 0xbe80_0300 {
let dst = ((first >> 16) & 0x7f) as u8;
if dst > 105 {
return Err(fail("SOP1 destination is outside the normal SGPR bank"));
}
let (src, len) = scalar_source(code, offset, first as u8)?;
return Ok((Insn::SMov(dst, src), len));
}
@@ -340,16 +357,6 @@ fn decode_one(code: &[u8], offset: usize) -> Result<(Insn, usize), String> {
Err(fail("unsupported opcode"))
}
fn mubuf(second: u32) -> Option<(u8, u8, u8)> {
if second & 0xffe0_0000 != 0x8000_0000 {
return None;
}
let index = second as u8;
let data = (second >> 8) as u8;
let resource = ((second >> 16) & 0x1f) as u8 * 4;
(resource <= 102).then_some((data, index, resource))
}
fn vector_source(selector: u32) -> Option<Src> {
match selector {
128..=192 => Some(Src::Imm(selector - 128)),
+176 -1
View File
@@ -5,10 +5,24 @@ mod independent_ref;
#[cfg(test)]
mod review {
use super::independent_ref;
use xenora_shader::{Architecture, compile};
const FIXTURE: &[u8] = include_bytes!("../../fixtures/rdna2/add.bin");
fn words(code: &[u32]) -> Vec<u8> {
code.iter().copied().flat_map(u32::to_le_bytes).collect()
}
fn verify(code: &[u8], input: &[u32], expected: Option<&[u32]>) {
let compiled = compile(Architecture::Gfx1030, code);
let reference = xenora_ref::execute(code, input);
let independent = independent_ref::execute(code, input);
assert_eq!(compiled.is_ok(), expected.is_some(), "{compiled:?}");
assert_eq!(reference.as_deref().ok(), expected, "{reference:?}");
assert_eq!(independent.as_deref().ok(), expected, "{independent:?}");
}
fn check(input: &[u32]) {
let expected: Vec<_> = input
.iter()
@@ -128,7 +142,6 @@ mod review {
#[test]
fn second_interpreter_agrees_with_reference_on_boundary_and_random_inputs() {
use super::independent_ref;
let fixtures: [(&[u8], &str); 3] = [
(include_bytes!("../../fixtures/rdna2/add.bin"), "add"),
(
@@ -173,4 +186,166 @@ mod review {
assert_eq!(actual, expected, "fixture {name}");
}
}
#[test]
fn binary32_boundaries_follow_exact_significand_arithmetic() {
const ADD: u32 = 0x0602_0702;
const MUL: u32 = 0x1002_0702;
let input = [0, 0x0040_0000, u32::MAX];
let one = 0x3f80_0000;
let min_normal = 0x0080_0000;
let max_normal = 0x7f7f_ffff;
for (op, a, b, expected) in [
(ADD, one, 0x3400_0000, Some(0x3f80_0001)), // 1 + 2^-23
(ADD, 0x3f7f_ffff, 0x3380_0000, Some(one)), // (1 - 2^-24) + 2^-24
(ADD, min_normal, min_normal, Some(0x0100_0000)), // 2^-125
(ADD, one, 0x3380_0000, None), // Midpoint 1 + 2^-24
(ADD, one, min_normal, None), // Absorbed in binary64 if computed in host FP
(ADD, max_normal, max_normal, None), // Overflow
(MUL, 0x3fc0_0000, 0x3fc0_0000, Some(0x4010_0000)), // (3/2)^2 = 9/4
(MUL, 0x7e80_0000, min_normal, Some(one)), // 2^126 × 2^-126
(MUL, max_normal, one, Some(max_normal)),
(MUL, 0x4580_0800, 0x4580_0800, None), // 4097² = 16,785,409, an odd integer
(MUL, min_normal, 0x3f00_0000, None), // 2^-127 is subnormal
(MUL, max_normal, 0x4000_0000, None), // Overflow
(ADD, 0, one, None), // Positive zero
(ADD, one, 0x8000_0000, None), // Negative zero
(ADD, 0xbf80_0000, 0x4000_0000, None), // Result normal, operand negative
(ADD, 0x4000_0000, 0xbf80_0000, None), // Same result, other operand negative
(ADD, one, 1, None), // Smallest positive subnormal
(MUL, 1, 0x7e80_0000, None), // Subnormal operand would yield exact normal 2^-23
(MUL, 0x7e80_0000, 1, None),
(ADD, one, 0x7f80_0000, None), // Infinity
(MUL, 0xff80_0000, one, None), // Negative infinity
(ADD, one, 0x7fc0_0001, None), // Quiet NaN with payload
(MUL, 0x7f80_0001, one, None), // Signaling NaN with payload
] {
// Force literal moves into v2 and v3. VOP2 writes v1, the existing
// store source. The exact words were cross-checked with gfx1030 llvm-mc.
let mut code = words(&[0x7e04_02ff, a, 0x7e06_02ff, b, op]);
code.extend_from_slice(&FIXTURE[28..]);
let expected = expected.map(|word| [word; 3]);
verify(
&code,
&input,
expected.as_ref().map(|values| values.as_slice()),
);
}
}
#[test]
fn vector_register_renaming_and_in_place_add_preserve_known_answers() {
let input = [0, 1, 0xedcb_a988, 0x8000_0000, u32::MAX];
let expected = [0x1234_5678, 0x1234_5679, 0, 0x9234_5678, 0x1234_5677];
let renamed = words(&[
0xe030_2000,
0x8000_ff00, // Load v255 instead of v1.
0xbf8c_3f70,
0x7f00_02ff,
0x1234_5678, // Move the literal to v128.
0xd525_00ff,
0x0203_01ff, // Add v255, v255, v128.
0x7ffc_03ff, // Copy v255 to v254 before storing.
0xe070_2000,
0x8001_fe00, // Store v254.
0xbbfd_0000,
0xbf81_0000,
]);
verify(FIXTURE, &input, Some(&expected));
verify(&renamed, &input, Some(&expected));
}
#[test]
fn scalar_register_copy_and_literal_comparison_select_both_edges() {
let input = [0, u32::MAX];
for (literal, expected) in [(0xffff_fff0, [1, 1]), (0xffff_fff1, [2, 2])] {
let mut code = words(&[
0xbee9_03d0, // s_mov_b32 s105, -16
0xbe89_0369, // s_mov_b32 s9, s105
0xbf06_ff09,
literal, // s_cmp_eq_u32 s9, lit(<word>)
0xbf84_0002, // Skip the next move and branch if unequal.
0x7e02_0281, // v_mov_b32_e32 v1, 1
0xbf82_0001, // Skip the unequal case's move.
0x7e02_0282, // v_mov_b32_e32 v1, 2
]);
code.extend_from_slice(&FIXTURE[28..]);
verify(&code, &input, Some(&expected));
for end in 0..code.len() {
verify(&code[..end], &input, None);
}
}
}
#[test]
fn skipped_code_still_has_to_obey_the_fixture_layout_and_bindings() {
for bad_prefix in [
&[0xbf82_0001u32, 0xbf81_0000][..], // Early termination.
&[0xbf82_0001, 0xbeea_0380], // Reserved VCC_LO instead of normal SGPR.
&[0xbf82_0002, 0xe030_3000, 0x8000_0100], // Unsupported OFFEN with IDXEN.
&[0xbf82_0002, 0xe030_2000, 0x8000_0101], // v1 instead of v0 as index.
&[0xbf82_0002, 0xe030_2000, 0x8001_0100], // Load the wrong buffer.
&[0xbf82_0002, 0xe070_2000, 0x8000_0100], // Store to the input buffer.
] {
let mut code = words(bad_prefix);
code.extend_from_slice(FIXTURE);
verify(&code, &[1], None);
}
// A well-formed but unreachable move need not have an initialized source.
let mut skipped_move = words(&[0xbf82_0001, 0x7e02_03ff]);
skipped_move.extend_from_slice(FIXTURE);
verify(&skipped_move, &[1], Some(&[0x1234_5679]));
}
#[test]
fn reachable_vector_writes_respect_pending_loads_and_the_index_register() {
let mut pending = FIXTURE.to_vec();
pending.splice(8..8, 0x7e02_0281_u32.to_le_bytes()); // Move 1 to pending v1.
verify(&pending, &[1], None);
let mut overwrites_index = FIXTURE.to_vec();
overwrites_index[20] = 0; // Change the VOP3 add's destination from v1 to v0.
verify(&overwrites_index, &[1], None);
}
#[test]
fn rejects_overlapping_reads_even_if_the_later_read_would_supply_the_output() {
let code = words(&[
0xe030_2000,
0x8000_0100, // Load into v1 without waiting.
0xe030_2000,
0x8000_0200, // Load into v2 while v1 is pending.
0xbf8c_3f70,
0xe070_2000,
0x8001_0200, // Store v2, leaving v1 unused.
0xbbfd_0000,
0xbf81_0000,
]);
verify(&code, &[0x8765_4321], None);
}
#[test]
fn rejects_a_second_store_and_requires_waiting_for_a_following_load() {
for (at, extra) in [
(36, &FIXTURE[28..36]), // Second store before the original store wait.
(40, &FIXTURE[28..40]), // Second store and wait after a completed output.
(40, &FIXTURE[..8]), // Load after the completed output, without a load wait.
] {
let mut code = FIXTURE.to_vec();
code.splice(at..at, extra.iter().copied());
verify(&code, &[1], None);
}
}
#[test]
fn distinguishes_descriptor_and_ordinary_scalar_registers() {
for (mov, expected) in [
(0xbe87_0381, None), // s_mov_b32 s7, 1 writes a reserved descriptor.
(0xbe88_0381, Some([0x1234_5679])), // s8 sits at the boundary.
(0xbe89_0381, Some([0x1234_5679])), // s9 is an ordinary scalar.
] {
let mut code = words(&[mov]);
code.extend_from_slice(FIXTURE);
verify(&code, &[1], expected.as_ref().map(|words| words.as_slice()));
}
}
}