test: the hot pieces' split and -O1 against -O2 compute the same, game-free #1142

Open
Marcuss2 wants to merge 1 commit from Marcuss2/Longshot:test/exactness-hot-split into main
Contributor

Type: test · Risk: low · Tested on: Linux (game-free checks only; nothing here runs the game) · Needs: none

Why

Two codegen changes are being prepared for the build and neither may change what the game computes:

  1. The hot pieces split. In a build that carries an A64_HOT_FUNCS list, code_hot*.c holds the hot functions together
    at RX_HOT_OPT (-O2). One of them, f_81b8c000, is a 4.79 MB translation unit that takes 346 s. The lifted chunks
    already have the fix (LONGSHOT_SPLIT_GIANTS, nx2/split_giants.py: a function of MIN_KB (256 KB) or more is cut at its
    top-level labels into pieces plus a dispatcher); the hot pieces' flags (nx2/build.py hot_fl) never got it. split-giants
    is adding it, which takes a from-scratch build from 7:13 to 3:17.
  2. More code at -O2. Now that builds are cheap, more chunk code may be compiled at -O2 instead of -O1 with the light
    passes (build.LIGHT_FLAGS), and that must not change the computed result either.

Neither change is worth landing on a hunch. The split mechanism's own exactness is already proven by
tests/test_split_giants.py; what was missing is (a) the same proof down the hot pieces' path at -O2, and (b) that
raising the level from -O1 + light passes to -O2 computes the same thing. That is this PR: a second check that reuses
that harness rather than writing one.

What changed

tests/test_opt_level_exactness.py (new, one file, no production code touched):

  • Hot + split (hot_split_check). A giant lifter-shaped function (test_split_giants.big_source, 416 KB, past
    split_giants.MIN_KB) is compiled twice through nx2/build.py's compile_one, exactly as the build compiles
    code_hot_0.c:

    • the reference: the whole function at the hot pieces' flags (the chunk flags with -O2, built the way build.py's
      hot_fl is);
    • the one under test: the same function with split_giants.FLAG, so compile_one compiles split_giants' copy — cut at
      top-level labels into static __attribute__((noinline)) pieces and a dispatcher under the function's own name. The check
      also asserts the object really holds the pieces (s_00002000_) and that compile_one removed the split copy.

    Both objects go into test_split_giants' DRIVER, which runs them from 300 random Ctx/guest-memory states and compares
    every byte of the context, the whole guest window, the page marks, the calls out (each with a hash of the context), the
    setjmp resumes and the interrupt polls.

  • -O1 with LIGHT_FLAGS vs -O2 (opt_level_check). The same function (240 blocks, 161 KB) is compiled into two programs —
    one translation unit at -O1 + build.LIGHT_FLAGS, one at -O2, each linked with the harness's driver at the harness's
    own flags. The driver (DIGEST, derived from test_split_giants.DRIVER's text so the guest model, page marks, event log
    and host setjmp/longjmp are the same) runs one function from the same 300 states and prints an FNV-1a 64 digest of the final
    context bytes, every guest-memory byte, the page marks, the event log, the polls, the setjmp resumes and the setjmp stack's
    depth. The two executables' lines must be equal, and the check also requires the poll and event counts to be non-zero so a
    digest cannot match because nothing ran. A compiler that does not take LIGHT_FLAGS (-opt-disable is LLVM 22's;
    build.light_flags_work) still gets the -O1 against -O2 comparison and says so in its output.

  • It is discovered by tests/run_all.py on its own (tests/test_*.py), and declares RUN_ALL_ARGS = ["--cc", "clang"] so the
    runner skips it where clang is missing and --strict fails it instead, like tests/test_split_giants.py.

tests/test_split_giants.py, nx2/build.py and tests/test_lifted_flags_safe.py are untouched.

Measurements

Verdict: nothing to measure: this PR adds a game-free check and changes no code the game runs; the check's own run, and the full suite's, are in Testing.

Flags and settings

None: a test only, no switch, menu row, ini key or build flag.

Testing

Tested: on this PC (Linux, no GPU needed):

Check This PR @ 825e022b
python -I -B tests/test_opt_level_exactness.py --cc clang OK, 3.7 s (13.0 s in the full run, 32 at once)
python -I -B tests/run_all.py (Linux) 587 passed, 17 failed, 74 skipped in 75 s

The exactness lines the check prints:

hot + split at -O2 (compile_one): 0 of 300 states differ, 0 setjmp resumes
o2: a9b2174883bfa16c states 300 polls 71 events 3978 resumes 0
o1: a9b2174883bfa16c states 300 polls 71 events 3978 resumes 0
opt_level_exactness: OK

The two levels' objects are genuinely different code, so the matching digest is not a comparison of the same object:
74784 bytes at -O2 against 78704 bytes at -O1 + LIGHT_FLAGS for the same 161 KB source (sha1 b4b8bc945164 vs
8c1ee83319cf).

The 17 failures are the known environmental ones that also fail on main @ 71b1edd8:
test_audio_output_devices, test_bug_report, test_bug_report_defaults, test_crt_options,
test_dlss_feature_size, test_failed_compile_keeps_objects, test_guest_imported, test_hardware_report,
test_linux_preflight, test_linux_update, test_make_game_cache, test_missing_nup, test_mods_size_table,
test_pending_guest_import, test_run_all_changed, test_vk_occlusion_queries, test_walk_key.

What the two checks do and do not prove, plainly:

  • Proven: for a made-up function in the lifter's shapes, on this host and compiler (clang 23.1.5, x86-64-v3/native), the
    hot pieces compiled at -O2 and cut at their labels by split_giants compute exactly what the whole -O2 function
    computes — every register, every guest byte it writes, every page mark, every call, every setjmp resume and every interrupt
    poll, from 300 random states. And -O1 with the light passes and -O2 compute the same thing over the same 300 states.
  • Not proven: a real game function (the emitter check in tests/test_split_giants.py covers the real lifter's output, not
    this one); the FP shapes (this function is the integer and guest-memory shapes; no FP helper is called); that
    nx2/build.py's hot_fl actually carries the split flag on its own (the flag-surface check on the split PR covers that —
    this test passes the flag itself, so it does not fail on main for the missing flag and is not a replacement for that
    check); other compilers and CPUs.
  • Needs a game run: nothing in this PR. The changes it supports (split hot pieces, more -O2) each need their own game run
    before they land, which is theirs to do, not this test's.

Not tested: the game and any GPU path: this PR adds no code the game runs.

Must be tested: None.

Risks

What could break: nothing the game runs; a new check in the suite (3-13 s) only. If split_giants or the flags change, this
check fails, which is its job.

Turning it off: revert the commit.

Compatibility: Nothing changes.

Checklist

Everyone

  • One topic.
  • The title is a Conventional Commit (type(scope): description) of the status line's type.
  • Why gives the reason plainly and links the issues that fit (no issue covers this pre-landing evidence; the split and
    opt-budget work is tracked on the team board).
  • Measurements has a verdict, or one line saying why there is nothing to measure.
  • Testing names what was tested, what wasn't, and what must still be tested, where and how.
  • Rebased on current main (71b1edd8).
  • python -I -B tests/run_all.py passes (the 17 failures that also fail on main are named above).
  • No game files, dumps, build output or generated files.
  • third_party/ untouched (a new folder with a PROVENANCE.md instead).
  • The license is OK: GPL-3.0-or-later, nothing incompatible and nothing decompiled.

When it applies

  • AI assistance recorded with Assisted-by: / Co-Authored-By: trailers.
  • Switches documented (none added) and shipped at their recommended value.
  • A check under tests/ that reads changed source updated in this PR, not weakened (none of the existing checks reads
    this file; tests/test_split_giants.py is reused, unmodified).
  • Docs updated (the test's docstring says what it proves and what it does not).
**Type:** test · **Risk:** low · **Tested on:** Linux (game-free checks only; nothing here runs the game) · **Needs:** none ## Why Two codegen changes are being prepared for the build and neither may change what the game computes: 1. **The hot pieces split.** In a build that carries an `A64_HOT_FUNCS` list, `code_hot*.c` holds the hot functions together at `RX_HOT_OPT` (`-O2`). One of them, `f_81b8c000`, is a 4.79 MB translation unit that takes 346 s. The lifted chunks already have the fix (`LONGSHOT_SPLIT_GIANTS`, `nx2/split_giants.py`: a function of `MIN_KB` (256 KB) or more is cut at its top-level labels into pieces plus a dispatcher); the hot pieces' flags (`nx2/build.py` `hot_fl`) never got it. `split-giants` is adding it, which takes a from-scratch build from 7:13 to 3:17. 2. **More code at -O2.** Now that builds are cheap, more chunk code may be compiled at `-O2` instead of `-O1` with the light passes (`build.LIGHT_FLAGS`), and that must not change the computed result either. Neither change is worth landing on a hunch. The split mechanism's own exactness is already proven by `tests/test_split_giants.py`; what was missing is (a) the same proof down the **hot pieces' path** at `-O2`, and (b) that **raising the level from `-O1` + light passes to `-O2`** computes the same thing. That is this PR: a second check that reuses that harness rather than writing one. ## What changed `tests/test_opt_level_exactness.py` (new, one file, no production code touched): - **Hot + split (`hot_split_check`).** A giant lifter-shaped function (`test_split_giants.big_source`, 416 KB, past `split_giants.MIN_KB`) is compiled twice through `nx2/build.py`'s `compile_one`, exactly as the build compiles `code_hot_0.c`: - the reference: the whole function at the hot pieces' flags (the chunk flags with `-O2`, built the way `build.py`'s `hot_fl` is); - the one under test: the same function with `split_giants.FLAG`, so `compile_one` compiles `split_giants`' copy — cut at top-level labels into `static __attribute__((noinline))` pieces and a dispatcher under the function's own name. The check also asserts the object really holds the pieces (`s_00002000_`) and that `compile_one` removed the split copy. Both objects go into `test_split_giants`' `DRIVER`, which runs them from 300 random `Ctx`/guest-memory states and compares every byte of the context, the whole guest window, the page marks, the calls out (each with a hash of the context), the setjmp resumes and the interrupt polls. - **-O1 with LIGHT_FLAGS vs -O2 (`opt_level_check`).** The same function (240 blocks, 161 KB) is compiled into two programs — one translation unit at `-O1` + `build.LIGHT_FLAGS`, one at `-O2`, each linked with the harness's driver at the harness's own flags. The driver (`DIGEST`, derived from `test_split_giants.DRIVER`'s text so the guest model, page marks, event log and host setjmp/longjmp are the same) runs one function from the same 300 states and prints an FNV-1a 64 digest of the final context bytes, every guest-memory byte, the page marks, the event log, the polls, the setjmp resumes and the setjmp stack's depth. The two executables' lines must be equal, and the check also requires the poll and event counts to be non-zero so a digest cannot match because nothing ran. A compiler that does not take `LIGHT_FLAGS` (`-opt-disable` is LLVM 22's; `build.light_flags_work`) still gets the `-O1` against `-O2` comparison and says so in its output. - It is discovered by `tests/run_all.py` on its own (`tests/test_*.py`), and declares `RUN_ALL_ARGS = ["--cc", "clang"]` so the runner skips it where clang is missing and `--strict` fails it instead, like `tests/test_split_giants.py`. `tests/test_split_giants.py`, `nx2/build.py` and `tests/test_lifted_flags_safe.py` are untouched. ## Measurements **Verdict:** nothing to measure: this PR adds a game-free check and changes no code the game runs; the check's own run, and the full suite's, are in Testing. ### Flags and settings None: a test only, no switch, menu row, ini key or build flag. ## Testing **Tested:** on this PC (Linux, no GPU needed): | Check | This PR @ 825e022b | |---|---| | `python -I -B tests/test_opt_level_exactness.py --cc clang` | OK, 3.7 s (13.0 s in the full run, 32 at once) | | `python -I -B tests/run_all.py` (Linux) | 587 passed, 17 failed, 74 skipped in 75 s | The exactness lines the check prints: ``` hot + split at -O2 (compile_one): 0 of 300 states differ, 0 setjmp resumes o2: a9b2174883bfa16c states 300 polls 71 events 3978 resumes 0 o1: a9b2174883bfa16c states 300 polls 71 events 3978 resumes 0 opt_level_exactness: OK ``` The two levels' objects are genuinely different code, so the matching digest is not a comparison of the same object: 74784 bytes at `-O2` against 78704 bytes at `-O1` + `LIGHT_FLAGS` for the same 161 KB source (sha1 `b4b8bc945164` vs `8c1ee83319cf`). The 17 failures are the known environmental ones that also fail on main @ 71b1edd8: `test_audio_output_devices`, `test_bug_report`, `test_bug_report_defaults`, `test_crt_options`, `test_dlss_feature_size`, `test_failed_compile_keeps_objects`, `test_guest_imported`, `test_hardware_report`, `test_linux_preflight`, `test_linux_update`, `test_make_game_cache`, `test_missing_nup`, `test_mods_size_table`, `test_pending_guest_import`, `test_run_all_changed`, `test_vk_occlusion_queries`, `test_walk_key`. What the two checks do and do not prove, plainly: - **Proven:** for a made-up function in the lifter's shapes, on this host and compiler (clang 23.1.5, x86-64-v3/native), the hot pieces compiled at `-O2` and cut at their labels by `split_giants` compute exactly what the whole `-O2` function computes — every register, every guest byte it writes, every page mark, every call, every setjmp resume and every interrupt poll, from 300 random states. And `-O1` with the light passes and `-O2` compute the same thing over the same 300 states. - **Not proven:** a real game function (the emitter check in `tests/test_split_giants.py` covers the real lifter's output, not this one); the FP shapes (this function is the integer and guest-memory shapes; no FP helper is called); that `nx2/build.py`'s `hot_fl` actually carries the split flag on its own (the flag-surface check on the split PR covers that — this test passes the flag itself, so it **does not fail on main** for the missing flag and is not a replacement for that check); other compilers and CPUs. - **Needs a game run:** nothing in this PR. The changes it supports (split hot pieces, more `-O2`) each need their own game run before they land, which is theirs to do, not this test's. **Not tested:** the game and any GPU path: this PR adds no code the game runs. **Must be tested:** None. ## Risks **What could break:** nothing the game runs; a new check in the suite (3-13 s) only. If `split_giants` or the flags change, this check fails, which is its job. **Turning it off:** revert the commit. **Compatibility:** Nothing changes. ## Checklist ### Everyone - [x] One topic. - [x] The title is a Conventional Commit (`type(scope): description`) of the status line's type. - [x] Why gives the reason plainly and links the issues that fit (no issue covers this pre-landing evidence; the split and opt-budget work is tracked on the team board). - [x] Measurements has a verdict, or one line saying why there is nothing to measure. - [x] Testing names what was tested, what wasn't, and what must still be tested, where and how. - [x] Rebased on current `main` (71b1edd8). - [x] `python -I -B tests/run_all.py` passes (the 17 failures that also fail on `main` are named above). - [x] No game files, dumps, build output or generated files. - [x] `third_party/` untouched (a new folder with a `PROVENANCE.md` instead). - [x] The license is OK: GPL-3.0-or-later, nothing incompatible and nothing decompiled. ### When it applies - [x] AI assistance recorded with `Assisted-by:` / `Co-Authored-By:` trailers. - [x] Switches documented (none added) and shipped at their recommended value. - [x] A check under `tests/` that reads changed source updated in this PR, not weakened (none of the existing checks reads this file; `tests/test_split_giants.py` is reused, unmodified). - [x] Docs updated (the test's docstring says what it proves and what it does not).
test: the hot pieces' split and -O1 against -O2 compute the same, game-free
Some checks failed
Website / Website on Cloudflare (pull_request_target) Has been skipped
PR description / Description follows the template (pull_request_target) Successful in 4s
CI / Conventional Commit title (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been cancelled
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been cancelled
CI / Workflow lint (actionlint) (pull_request) Has been cancelled
Guide screenshots / Guide images and local UI source review (pull_request) Has been cancelled
Third-party parts / As their notes say (pull_request) Has been cancelled
Third-party parts / The same as upstream (pull_request) Has been cancelled
ab31cdacfb
Two codegen changes are landing: code_hot*.c compiles a giant hot function in pieces cut at its labels, and more chunks
may go to -O2 instead of -O1 with the light passes. Neither may change what the game computes, so prove it without the
game, reusing tests/test_split_giants.py's harness (find_cc, gen_function, big_source, Programs and its driver) instead
of writing a second one.

- The hot pieces' path: a giant lifter-shaped function (test_split_giants.big_source, past split_giants.MIN_KB) is
  compiled twice through nx2/build.py's compile_one at the hot pieces' flags (the chunk flags with -O2, as build.py's
  hot_fl): once whole, and once with split_giants.FLAG so compile_one compiles split_giants' copy, cut at top-level
  labels into static noinline pieces plus a dispatcher. test_split_giants' driver links both objects and runs them from
  300 random Ctx/memory states, comparing every byte of the context, the whole guest window, the page marks, the calls
  out, the setjmp resumes and the interrupt polls.
- Raising the level: the same function at -O1 with build.LIGHT_FLAGS and at -O2 into two programs, each printing an
  FNV-1a digest of the final context, every guest-memory byte, the page marks, the event log, the polls and the setjmp
  resumes over the same 300 states. The two lines must be equal, and the polls and calls are checked to be non-zero so a
  digest cannot match because nothing ran. A compiler that does not take LIGHT_FLAGS still gets the -O1 against -O2
  comparison and says so.

What this does not prove: a real game function (tests/test_split_giants.py's emitter check covers the real lifter's
output), the FP shapes, that nx2/build.py's hot flags carry the split flag on their own, or anything about the game: a
build change still needs a game run. tests/test_opt_level_exactness.py is discovered by tests/run_all.py, and there it
is skipped when clang is missing (RUN_ALL_ARGS).

Assisted-by: DeepSeek Harness
Collaborator

Possibly related, for context:

  • PR #1140 test: the lifted code's flags stay semantics-safe when its optimization level rises — Companion test locks lifted optimization flags; this validates compiled output across levels.
Possibly related, for context: - PR #1140 test: the lifted code's flags stay semantics-safe when its optimization level rises — Companion test locks lifted optimization flags; this validates compiled output across levels.
Marcuss2 changed title from WIP: test: the hot pieces' split and -O1 against -O2 compute the same, game-free to test: the hot pieces' split and -O1 against -O2 compute the same, game-free 2026-11-16 14:58:47 +00:00
Marcuss2 force-pushed test/exactness-hot-split from ab31cdacfb
Some checks failed
Website / Website on Cloudflare (pull_request_target) Has been skipped
PR description / Description follows the template (pull_request_target) Successful in 4s
CI / Conventional Commit title (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been cancelled
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been cancelled
CI / Workflow lint (actionlint) (pull_request) Has been cancelled
Guide screenshots / Guide images and local UI source review (pull_request) Has been cancelled
Third-party parts / As their notes say (pull_request) Has been cancelled
Third-party parts / The same as upstream (pull_request) Has been cancelled
to 825e022be6
Some checks are pending
CI / Conventional Commit title (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Blocked by required conditions
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Blocked by required conditions
CI / Workflow lint (actionlint) (pull_request) Blocked by required conditions
Guide screenshots / Guide images and local UI source review (pull_request) Blocked by required conditions
Third-party parts / As their notes say (pull_request) Blocked by required conditions
Third-party parts / The same as upstream (pull_request) Blocked by required conditions
PR description / Description follows the template (pull_request_target) Successful in 4s
2026-11-16 14:59:09 +00:00
Compare
Author
Contributor

The hot pieces' flags are now built at -O2 unconditionally in the check (not from RX_HOT_OPT), so an environment that sets RX_HOT_OPT cannot change what the check compares; amended to 825e022b. Re-ran the full suite: 587 passed, 17 failed (the same known environmental failures as main @ 71b1edd8, none of them this check), 74 skipped in 59 s; tests/test_opt_level_exactness.py passes in 5.2 s.

The hot pieces' flags are now built at -O2 unconditionally in the check (not from RX_HOT_OPT), so an environment that sets RX_HOT_OPT cannot change what the check compares; amended to 825e022b. Re-ran the full suite: 587 passed, 17 failed (the same known environmental failures as main @ 71b1edd8, none of them this check), 74 skipped in 59 s; tests/test_opt_level_exactness.py passes in 5.2 s.
Some checks are pending
CI / Conventional Commit title (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Blocked by required conditions
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Blocked by required conditions
CI / Workflow lint (actionlint) (pull_request) Blocked by required conditions
Guide screenshots / Guide images and local UI source review (pull_request) Blocked by required conditions
Third-party parts / As their notes say (pull_request) Blocked by required conditions
Third-party parts / The same as upstream (pull_request) Blocked by required conditions
PR description / Description follows the template (pull_request_target) Successful in 4s
This pull request doesn't have enough approvals yet. 0 of 1 approvals granted.
Some workflows are waiting to be reviewed.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u 'test/exactness-hot-split:Marcuss2-test/exactness-hot-split'
git switch 'Marcuss2-test/exactness-hot-split'
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
MagicBeanDev/Longshot!1142
No description provided.