From fee956293dafd9bb6234bd0002e4c2ce3f238499 Mon Sep 17 00:00:00 2001 From: ates Date: Wed, 25 Nov 2026 07:52:19 +0300 Subject: [PATCH 1/3] Add the verified CPU/loader coverage map Document what the CPU and loader tests verify, per operation family, in docs/testing/cpu-coverage.md: the declared-form inventory (213 operations, 403 forms, 498 opcode slots from the validated registry), the per-operation engine split (93 native-lowered, 120 shared-semantic, with the conditional width and encoding gates), a per-artifact evidence table with exact pass counts from one full workspace gate run on Apple M5, the reconciliation of the eight operations covered by model tests instead of the assembly-fixture corpus, and a recorded note that three advisory qa cpu-inventory unsupported-catalog rows are stale against the implemented and tested forms. Also updates the docs/README.md description line and adds the CHANGELOG entry under [Unreleased]. Closes #154. Signed-off-by: ates --- CHANGELOG.md | 1 + docs/README.md | 2 +- docs/testing/cpu-coverage.md | 164 +++++++++++++++++++++++++++++++++-- 3 files changed, 161 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e407bd8..caf1e53 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,6 +40,7 @@ remains unsupported. - Added a Python 3 fallback for `timeout` in `scripts/test-gpu.sh`, so the native Metal suite runs on stock macOS without GNU coreutils while preserving bounded execution and the usual timeout exit status. ### Added +- Added a verified CPU/loader coverage map to `docs/testing/cpu-coverage.md` (#154): the declared-form inventory (213 operations, 403 forms, 498 opcode slots from the validated registry), the per-operation engine split (93 native-lowered, 120 shared-semantic, with the width and encoding gates that keep some forms on the helper path), a per-artifact evidence table with exact pass counts from one full `cargo test --locked --workspace` run on Apple M5 (971 passed, 0 failed, 35 ignored; ignored tests are Metal-gated, a manual timing profile or the known DBT self-modifying defect), the reconciliation of the eight operations covered by model tests rather than the assembly-fixture corpus, and a recorded note that the advisory `qa cpu-inventory` unsupported-catalog rows for RCL/RCR/SHLD/SHRD, string instructions and atomics/fences are stale against the implemented and tested forms. Local documentation evidence only; no runtime change; not independently reviewed. - The gfx1030 identification benchmark fixture now runs as an ordinary integration test, so workspace tests check LLVM-derived names, families, lengths and byte boundaries without invoking a timing run. - Added a CPU benchmark for gfx1030 metadata identification (#173). It verifies instruction boundaries on a mixed-family stream assembled with LLVM and reports first-pass and repeated-pass throughput. - Added a Win64 ABI regression showing that a service may write the caller-allocated shadow space. Existing negative controls cover nonvolatile XMM-register corruption; the unchanged-home-slot test now describes its handler rather than implying an ABI preservation requirement. diff --git a/docs/README.md b/docs/README.md index 3f623cc..4fbccdc 100644 --- a/docs/README.md +++ b/docs/README.md @@ -48,7 +48,7 @@ Historical phase checkpoints retain their original evidence scope. - [Testing and acceptance index](testing/README.md) — Entry point for test procedures, evidence and review records. - [AMD RDNA2 desktop GPU (gfx1030) form acceptance](testing/shader-form-acceptance.md) — Independence, command, log and promotion rules for fixture-verified instruction forms. - [Engineering progress](progress.md) — Verification commands, metric definitions, and open release gates. -- [CPU test runtime and shard selection](testing/cpu-coverage.md) — Measured CPU gate cost and deterministic test-target shards. +- [CPU test runtime, shards and coverage map](testing/cpu-coverage.md) — Measured CPU gate cost, deterministic test-target shards, and a verified per-operation CPU/loader coverage map with exact test evidence. - [Test inventory comparison](testing/test-inventory.md) — Detect missing or newly ignored Cargo tests across commits. - [Persistent resource and translated rendering acceptance](testing/x9-acceptance.md) — Pinned upstream tests, native ARM64 results and unsupported cases. - [Baseline acceptance](testing/phase-02-baseline.md), [Phase 01 assurance](testing/phase01-assurance.md), and [independent reviews](testing/review-log.md) — Candidate-specific results and release findings. diff --git a/docs/testing/cpu-coverage.md b/docs/testing/cpu-coverage.md index 96b8558..7909776 100644 --- a/docs/testing/cpu-coverage.md +++ b/docs/testing/cpu-coverage.md @@ -1,9 +1,10 @@ -# CPU test runtime and shard selection +# CPU test runtime, shards and coverage map -This page records what the CPU test gate costs and describes -`scripts/cpu-tests.sh`, which splits that gate into deterministic shards. The -shards are a convenience for local iteration and parallel runners. They do not -replace any gate: `cargo test --locked --workspace` stays the full CPU gate, and +This page records what the CPU test gate costs, describes +`scripts/cpu-tests.sh`, which splits that gate into deterministic shards, and +maps which x86-64 and loader behavior the tests verify. The shards are a +convenience for local iteration and parallel runners. They do not replace any +gate: `cargo test --locked --workspace` stays the full CPU gate, and `scripts/test-gpu.sh` stays the GPU gate. ## What counts as a CPU test @@ -96,3 +97,156 @@ than the full gate, because each target pays Cargo start-up. different commits are not comparable. - The experiment workspace `experiments/x1` is outside the selection. CI runs it separately. + +# CPU and loader coverage map + +This map inventories what the CPU and loader tests verify, per operation +family, with the exact evidence commands and counts behind every number. It is +documentation of verified state, not a compatibility claim, and it contains no +percentages: every figure below is a count that a recorded command produced on +one machine. The behavioral rules behind the map (how forms are declared, what +"implemented" means, which forms are rejected on purpose) are documented in +[docs/cpu/instruction-registry.md](../cpu/instruction-registry.md) and are not +repeated here except where the map adds evidence. + +## Method and revision + +All commands ran on Apple M5, macOS 26.6.2, native arm64, Rust +`1.100.0-aarch64-apple-darwin` (the revision CI pins), `CARGO_BUILD_JOBS=2`, +one run, on the branch holding this change, based on upstream `main` at +`d26af53` (2026-11-25). Recorded evidence commands: + +```sh +python3 crates/loader/generate_x86.py validate # 213 operations, 403 forms, 498 opcode slots +python3 crates/loader/generate_x86.py --check # x86_table.rs is fresh +PYTHONPATH=scripts python3 -m qa cpu-inventory # advisory partitions, cross-checked below +cargo test --locked --workspace # 113 result lines: 971 passed, 0 failed, 35 ignored +``` + +The registry numbers are the generator's own count, not a hand count. The +advisory `qa cpu-inventory` output was cross-checked against the code before +use, and one stale row is called out under "Intentionally rejected forms". +Ignored tests are not passes; every ignore in the run is a Metal-gated test +(run by `scripts/test-gpu.sh`), a manual timing profile, or the one known DBT +defect test, named below. + +## Declared instruction inventory + +`crates/loader/x86/instructions.toml` declares the decodable x86-64 surface. +`generate_x86.py validate` reports **213 operations, 403 forms, 498 opcode +slots** at this revision. By opcode map the slots split 235 one-byte and 263 +`0F`; by mandatory prefix 352 none, 107 `66`, 16 `F2`, 23 `F3`; by operand size +96 byte (`b`), 139 variable 16/32/64 (`v`), 160 XMM 16-byte (`x`), 58 no +operand (`n`), 22 32/64-only (`y`), 23 64-bit (`q`). + +A declared form is decodable, not implemented. A form counts as supported only +when it has semantics and fixture evidence. The fixture half is enforced: +`every_declared_form_is_executed_by_a_fixture` in +`crates/loader/tests/x86_integer.rs` decodes every line of the three assembly +corpora (`tests/x86/integer.txt`, `vector.txt`, `float.txt`) and fails if any +declared form is never executed. It lists the operations that are covered +elsewhere instead (control flow and exits, `LDMXCSR`, and the +`MOVS`/`STOS`/`CLD`/`STD` string family, which need their own memory layout and +are covered form by form in `tests/cpu_rep.rs` and the loop tests). + +## Engine path per operation + +Every one of the 213 operations runs in exactly one primary path in the native +DBT: **93 are lowered to ARM64** by `is_native` in +`crates/loader/src/dbt.rs`, and **120 use the shared interpreter semantics** +through a helper call, counted in `DbtMetrics::interpreter_fallbacks`. +`SYSCALL` is decoded but the DBT refuses to translate it (`is_translatable`), +so it ends translated execution. The conditional gates inside `is_native` +matter when reading the split: + +- `ADD`, `SUB`, `CMP`, `AND`, `OR`, `XOR`, `TEST`, `INC`, `DEC`, `NEG`, `NOT` + and `CMOV` are native only at 32- and 64-bit width; 8- and 16-bit forms use + the shared semantics. +- `ADC` and `SBB` are native only for register and immediate operands; a memory + destination stays on the helper path. +- `BT` is native only in the `0F A3` register-index form; the `0F BA` + immediate-index form can write memory and stays on the helper path. +- `BSF` and `BSR` are native at 16/32/64-bit width. +- `POP` is native only in the opcode-register form. + +`tests/x86_integer.rs` asserts the split both ways for every fixture: native +forms must never call the helper, and helper forms always must. The interpreter +runs all 213 operations through the shared semantics. + +## Test evidence by artifact + +Counts are from the full gate run recorded above (target name, tests run, +passed/ignored). Expectation sources are named so independence can be judged. + +| Artifact (under `crates/loader/tests/`) | Expectations derived from | Run result | +| --- | --- | --- | +| `x86_integer.rs` + `x86/integer.txt` (1230 fixture lines) | LLVM-assembled encodings; byte-level references written from the SDM/APM operation text, independent of the production semantics | 16 passed, 0 failed | +| `x86_vector.rs` + `x86/vector.txt` (374 lines) | same method, SSE2 packed forms | 9 passed | +| `x86_float.rs` + `x86/float.txt` (172), `x86/float_vectors.txt` (6824), `x86/float_reference.py` | exact-fraction reference computed by script, following SDM Vol. 1 floating-point rules | 9 passed | +| `cpu_known_answers.rs` (50 tests, 1019 case lines) | Intel SDM and AMD APM sections cited per case; both engines run each case | 49 passed, 1 ignored | +| `movsxd.rs` | SDM operation text; modular arithmetic in the test; LLVM-assembled encodings | 9 passed | +| `x86_atomic.rs` | SDM LOCK/XADD/CMPXCHG rules; both compare outcomes, unaligned operands, faults | 5 passed | +| `x86_carry_chain.rs` | widening `u128`/`i128` reference arithmetic on 256-bit chains | 8 passed | +| `x86_prefix_length.rs` | SDM prefix and length rules | 8 passed | +| `cpu_loop.rs` | a loop-model reference over every count, match point and budget | 3 passed | +| `cpu_rep.rs` | a byte-array model over every MOVS/STOS form, direction and count, plus step accounting and faults | 7 passed | +| `cpu_features.rs` | CPUID feature-bit pairing per the SDM; each reported bit requires the feature's fixtures, each commonly-tested unreported bit requires a refused witness | 4 passed | +| `cpu_differential.rs` | interpreter and DBT must agree on shared fixtures | 5 passed | +| `arm64_encodings.rs` | LLVM encodings for the assembler's emitted ARM64 | 3 passed | +| `memory_page_boundaries.rs`, `memory_validation.rs` | mapping/permission/boundary contracts | 8 + 9 passed | +| `generated_conformance.rs`, `bootstrap.rs`, `gate_a1.rs`, `gate_a2.rs`, `indirect_control.rs`, `bswap.rs`, `dbt_render.rs`, `process_exit.rs` | per-file documented contracts (generated conformance vectors, startup gates, control flow) | all passed except one Metal-gated ignore in `dbt_render.rs` | + +The one ignore in `cpu_known_answers.rs` is +`defect_dbt_executes_modified_code_after_a_jump`, the known DBT defect that +keeps a translated block after the guest rewrites its code, tracked by issue +#79. It stays ignored at this revision until the cache-identity fix lands. The +loader package's remaining ignores in the run are Metal-gated tests (run by +`scripts/test-gpu.sh`) and one manual TLS timing profile; none is counted as a +pass. + +## Operations covered by model tests instead of the fixture corpus + +The mnemonic-level fixture scan behind the advisory +`PYTHONPATH=scripts python3 -m qa cpu-inventory` reports no assembly-text +fixture for eight operations: `cld`, `std`, `jrcxz`, `loop`, `loope`, +`loopne`, `movs`, `stos`. That is by design, not a gap: those operations need +their own memory layout or counter model and are covered form by form in +`tests/cpu_rep.rs` (MOVS/STOS/REP, the direction flag set by `STD` and cleared +by `CLD`) and `tests/cpu_loop.rs` (LOOP/LOOPE/LOOPNE, JRCXZ on zero RCX). The +declared-form enforcement test exempts exactly these families with a comment +saying so, and it still requires every other declared form to appear in the +corpora. + +## Intentionally rejected forms + +The rejection list with its scope rules (LOCK limited to the memory forms of +XADD and CMPXCHG, every x87 instruction except FNINIT, +LODS/CMPS/SCAS/REPE/REPNE, MMX, RCP/RSQRT approximations, SSE3 and later, +VEX, address-size overrides, 16-bit stack/branch forms, 16-bit BSWAP and +MOVSXD, bit tests of memory by register index, CMPXCHG8B/16B, and the DBT +refusing raw SYSCALL) is maintained in +[docs/cpu/instruction-registry.md](../cpu/instruction-registry.md) and is +tested by refusal cases inside the files above; this map does not duplicate it. + +One advisory-tool discrepancy is recorded for its owner: the hand-written +`unsupported_catalog` in `scripts/qa/cpu_inventory.py` lists "RCL/RCR/SHLD/ +SHRD", "string instructions" and "atomics/fences", which is stale against the +code and tests at this revision — RCL/RCR/SHLD/SHRD are declared registry +forms with implemented semantics (`x86_exec.rs`), 21 RCL and 16 SHLD/SHRD +known-answer cases, and 72 SHLD/SHRD assembly fixtures; MOVS/STOS and the +LOCK forms of XADD/CMPXCHG and the fences are supported within the documented +scope. The catalog is advisory only and does not feed any gate. + +## Map limitations + +- Every count is pinned to the revision, host and single run named above. +- The fixture evidence is mnemonic-level where it comes from the assembly + corpora: it proves every declared form executes somewhere, not that every + encoding variant of a form has its own expected-value case. The known-answer + files carry the per-case expectations; their case lines are counted, not + audited one by one here. +- The native/shared partition is read from `is_native` at this revision and + asserted by the fixtures; it is not a promise for other revisions. +- Nothing here was compared with x86 hardware, no compatibility percentage is + implied, and this is local documentation evidence, not independent + acceptance. From b40bbae1da9128955be31fcf26ef50b5eb8f3e8c Mon Sep 17 00:00:00 2001 From: ates Date: Wed, 25 Nov 2026 08:05:10 +0300 Subject: [PATCH 2/3] Refresh the coverage map at merged main b2654e9 The branch now contains main b2654e9, which includes the merged DBT cache-identity pull and the migration-benchmark checks, so the map pins its single gate run to that revision: the former self-modifying-code defect test executes and passes in both DBT engines (cpu_known_answers 50 passed, 0 ignored) and the workspace gate reports 116 result lines with 1015 passed, 0 failed and 34 ignored. The ignore taxonomy in the map names all three kinds from their own messages: Metal-gated, LLVM-gated (gfx1030 AMDGPU target) and manual timing runs. Signed-off-by: ates --- docs/testing/cpu-coverage.md | 52 ++++++++++++++++++++---------------- 1 file changed, 29 insertions(+), 23 deletions(-) diff --git a/docs/testing/cpu-coverage.md b/docs/testing/cpu-coverage.md index 650d4c8..236b004 100644 --- a/docs/testing/cpu-coverage.md +++ b/docs/testing/cpu-coverage.md @@ -113,22 +113,25 @@ repeated here except where the map adds evidence. All commands ran on Apple M5, macOS 26.6.2, native arm64, Rust `1.100.0-aarch64-apple-darwin` (the revision CI pins), `CARGO_BUILD_JOBS=2`, -in one run against source at `d26af53` (2026-11-25). The table below -preserves the counts from that revision. Recorded evidence commands: +one run, on the branch holding this change, based on upstream `main` at +`b2654e9` (2026-11-25, including the merged DBT cache-identity fix). +Recorded evidence commands: ```sh python3 crates/loader/generate_x86.py validate # 213 operations, 403 forms, 498 opcode slots python3 crates/loader/generate_x86.py --check # x86_table.rs is fresh PYTHONPATH=scripts python3 -m qa cpu-inventory # advisory partitions, cross-checked below -cargo test --locked --workspace # 113 result lines: 971 passed, 0 failed, 35 ignored +cargo test --locked --workspace # 116 result lines: 1015 passed, 0 failed, 34 ignored ``` The registry numbers are the generator's own count, not a hand count. The advisory `qa cpu-inventory` output was cross-checked against the code before use, and one stale row is called out under "Intentionally rejected forms". -Ignored tests are not passes; every ignore in the run is a Metal-gated test -(run by `scripts/test-gpu.sh`), a manual timing profile, or the one known DBT -defect test, named below. +Ignored tests are not passes; at this revision every ignore is one of three +kinds, each named by its own ignore message: a Metal-gated test (run by +`scripts/test-gpu.sh`), an LLVM-gated test (`requires LLVM with the gfx1030 +AMDGPU target`, five of them), or a manual timing/profile run that demands an +idle host (three of them). ## Declared instruction inventory @@ -151,21 +154,21 @@ are covered form by form in `tests/cpu_rep.rs` and the loop tests). ## Engine path per operation -Of the 213 declared operations, **93 have an ARM64 lowering** for at least -one form and **119 use the shared interpreter semantics for every translated -form**. Calls to those semantics count toward -`DbtMetrics::interpreter_fallbacks`. The remaining operation, `SYSCALL`, -decodes but `is_translatable` refuses it in the DBT. For operations with an -ARM64 lowering, `is_native` in `crates/loader/src/dbt.rs` applies these -form-specific rules: +Every one of the 213 operations runs in exactly one primary path in the native +DBT: **93 are lowered to ARM64** by `is_native` in +`crates/loader/src/dbt.rs`, and **120 use the shared interpreter semantics** +through a helper call, counted in `DbtMetrics::interpreter_fallbacks`. +`SYSCALL` is decoded but the DBT refuses to translate it (`is_translatable`), +so it ends translated execution. The conditional gates inside `is_native` +matter when reading the split: - `ADD`, `SUB`, `CMP`, `AND`, `OR`, `XOR`, `TEST`, `INC`, `DEC`, `NEG`, `NOT` and `CMOV` are native only at 32- and 64-bit width; 8- and 16-bit forms use the shared semantics. - `ADC` and `SBB` are native only for register and immediate operands; a memory destination stays on the helper path. -- `BT` is native only in the `0F A3` register-index form. The `0F BA /4` - immediate-index form uses the helper and can read a memory operand. +- `BT` is native only in the `0F A3` register-index form; the `0F BA` + immediate-index form can write memory and stays on the helper path. - `BSF` and `BSR` are native at 16/32/64-bit width. - `POP` is native only in the opcode-register form. @@ -183,7 +186,7 @@ passed/ignored). Expectation sources are named so independence can be judged. | `x86_integer.rs` + `x86/integer.txt` (1230 fixture lines) | LLVM-assembled encodings; byte-level references written from the SDM/APM operation text, independent of the production semantics | 16 passed, 0 failed | | `x86_vector.rs` + `x86/vector.txt` (374 lines) | same method, SSE2 packed forms | 9 passed | | `x86_float.rs` + `x86/float.txt` (172), `x86/float_vectors.txt` (6824), `x86/float_reference.py` | exact-fraction reference computed by script, following SDM Vol. 1 floating-point rules | 9 passed | -| `cpu_known_answers.rs` (50 tests, 1019 case lines) | Intel SDM and AMD APM sections cited per case; both engines run each case | 49 passed, 1 ignored | +| `cpu_known_answers.rs` (50 tests, 1019 case lines) | Intel SDM and AMD APM sections cited per case; both engines run each case | 50 passed, 0 ignored | | `movsxd.rs` | SDM operation text; modular arithmetic in the test; LLVM-assembled encodings | 9 passed | | `x86_atomic.rs` | SDM LOCK/XADD/CMPXCHG rules; both compare outcomes, unaligned operands, faults | 5 passed | | `x86_carry_chain.rs` | widening `u128`/`i128` reference arithmetic on 256-bit chains | 8 passed | @@ -196,13 +199,16 @@ passed/ignored). Expectation sources are named so independence can be judged. | `memory_page_boundaries.rs`, `memory_validation.rs` | mapping/permission/boundary contracts | 8 + 9 passed | | `generated_conformance.rs`, `bootstrap.rs`, `gate_a1.rs`, `gate_a2.rs`, `indirect_control.rs`, `bswap.rs`, `dbt_render.rs`, `process_exit.rs` | per-file documented contracts (generated conformance vectors, startup gates, control flow) | all passed except one Metal-gated ignore in `dbt_render.rs` | -At `d26af53`, the one ignore in `cpu_known_answers.rs` was -`defect_dbt_executes_modified_code_after_a_jump`, the known DBT defect that -kept a translated block after the guest rewrote its code. The cache -revalidation change in [PR #269](https://github.com/MacosPorters/betterxen/pull/269) -restored the test as `dbt_executes_modified_code_after_a_jump`. The other -loader ignores in the recorded run were Metal-gated tests and one manual TLS -timing profile. +The former defect test `defect_dbt_executes_modified_code_after_a_jump` — +`dbt_executes_modified_code_after_a_jump` since the fix — used to be the one +ignored test in `cpu_known_answers.rs`, recording that the DBT kept a stale +translation after the guest rewrites its code. The cache-identity change has +merged (issue #79, pull #269), and in this run the test executes and passes in +both DBT engines, so the target reports 50 passed and 0 ignored. The loader +package's +remaining ignores are the Metal-gated tests named above plus three manual +timing/profile runs (TLS template, relocation, warm data memory); none is +counted as a pass. ## Operations covered by model tests instead of the fixture corpus From 84f561b12b122905762e610448af76cb2123619c Mon Sep 17 00:00:00 2001 From: ates Date: Wed, 25 Nov 2026 16:14:50 +0300 Subject: [PATCH 3/3] Fix the documented known-answer count command Signed-off-by: ates --- docs/testing/cpu-coverage.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/docs/testing/cpu-coverage.md b/docs/testing/cpu-coverage.md index 7821696..4a90989 100644 --- a/docs/testing/cpu-coverage.md +++ b/docs/testing/cpu-coverage.md @@ -209,9 +209,7 @@ with the following command. This excludes section directives, format comments and Rust match arms. ```sh -rg -c '^[a-zA-Z0-9_]+:.* =>' crates/loader/tests/cpu_known_answers.rs -]* =>[^ -]*$' crates/loader/tests/cpu_known_answers.rs +rg -c '^[A-Za-z0-9_]+:.*=>' crates/loader/tests/cpu_known_answers.rs ``` The cache revalidation change in [PR #269](https://github.com/MacosPorters/betterxen/pull/269)