WIP: perf(lift): A64_FLAG_FUSE=1, a compare fused with the branch or select that reads it (lift time, off) #1980

Draft
siantm wants to merge 3 commits from siantm/Longshot:perf/lift-flag-fuse into main
Contributor

Summary

The parts of a local branch's flag fusion that neither main's local flags (A64_LOCAL_FLAGS) nor #1871 (A64_SUB_V,
open) have, beside both: a B.cond, CSEL-family or CCMP reading flags set earlier in the same label-free run compares the
compare's operands (a CCMP's immediate NZCV as a constant), and ADDS/CMN write V with __builtin_add_overflow. A
subtraction's V is left to main or #1871: the fused runs recognise both texts. FCMP is main's. Functions that keep
their context (the ones the patches name) get the kit's text. A lift-time A64_ switch: it changes the lift key. See
#1871. From b2c4c7eb and 94e68f79.

With the review (futondestroyer, BeanBot): a run is fused only where it costs no fast float op (four float ops, a CMP
and four more stay one region the switch off makes, left unfused; eight each side become two regions of eight around
the fused CMP); the functions that keep their context with main's locals (spliced code, an entry above the first block,
the patches' addresses, the ones no play ran) keep it whenever fusion is on (guest_locals.keep_context); with lifter
comments a fused site shows the guest's word; the lift prints the fused reads, the runs left for a fast float region and
the regions and ops. The test takes test_fpx_sticky.py's compiler selection and fails without a compiler.

Read first: nx2/flag_fuse.py, install_plain in nx2/guest_locals.py, tests/test_flag_fuse.py.

Testing

Tested: Windows 11, i7-9700, RTX 4060, llvm-mingw clang 23.1.5, Python 3.14.7 (the Builder's); game-free checks
only. This change has not run in the game on this PC yet, with the switch on or off (Still to test). Each check ran in
a hidden console of its own, through the PC's job queue, on this branch rebased onto main @ f1f2dc5b:

  • python -I -B tests/test_flag_fuse.py on 4a0a99b8 (job fb2-1980-1; the head 647f17c4 differs from it only in
    tests/test_entry_below_locals.py and tests/test_locals_ran_only.py; no --cc: the Builder's llvm-mingw clang
    and clang++ through LONGSHOT_MINGW): exit 0, "formulas: 4000576 operand pairs x 4 ops, 0 mismatches", "lifted: 2805300 runs of
    3117 functions, 0 mismatches", "flag fuse: ok (3117 lifted cases)"; the ff cases' fast float ops the same in every
    build ("off: 84 regions, 1344 float ops", "on: 154 regions, 1344 float ops", the same on over #1871's V, and with
    main's locals off and on); "driver: keep_context with only A64_FLAG_FUSE on; plan(): 4001 classifications for 4000
    setters".
  • The same at the test commit (633f9ad3, the review's cases before their fix, same job): exit 1 at its first new check, "ff4_b0
    (on) was fused, cutting a fast float region" (the test stops at its first failure, so the later new checks did not
    run there).
  • python -I -B tests/run_all.py --strict --changed origin/main on the head 647f17c4 (job fb2-1980-2; 8 at once): 30
    passed (test_flag_fuse.py, test_fpx_sticky.py, test_entry_below_locals.py, test_locals_ran_only.py among
    them), 7 failed, 1 skipped. The 7 are the checks this description already named as failing on main @ 2e1f6c32 too
    (test_dev_packs.py, test_libc_hooks.py, test_lift_cache.py, test_linux_preflight.py,
    test_make_game_ngx.py, test_oot_shadow_fit.py, test_sdiv_overflow.py); not run on main @ f1f2dc5b in this
    round. On 4a0a99b8 (job fb2-1980-1) test_entry_below_locals.py and test_locals_ran_only.py failed too: they read
    the exclusions in nx2/lift.py's text, now in guest_locals.keep_context; the head updates them.

Still to test:

  • Windows 11, this PC (i7-9700, RTX 4060): main @ f1f2dc5b and this head built twice, A64_FLAG_FUSE unset and =1
    (each a re-lift: dev.py ab --env cannot switch it), the same save and warmed route, two or more interleaved runs
    each: game-thread CPU time, average FPS, 1% lows, median and p99 frame times; clean lift, compile and link time,
    executable size and peak build memory off and on; the lift's "flag fusion" line (fused reads, runs left for a fast
    float region, fast float regions and ops), expecting the same game and frame times within the runs' spread or better
    (by hand, queued with the opener)
  • Linux: python3 -I -B tests/test_flag_fuse.py, expecting it to pass (by hand)

Measurements

Verdict: A64_FLAG_FUSE ships off: an experiment, not measured in play yet (Still to test: pending); only its
game-free test has run, which shows the fused code exact and, in its fast float cases, no fast float op lost.

Setup: Windows 11, i7-9700, llvm-mingw clang 23.1.5; tests/test_flag_fuse.py through the PC's job queue (fb2-1980-1),
this PR on main @ f1f2dc5b; the Before column is an earlier queue job's, on the first version of the test

Before: main @ 51f5f9da (the test file copied in) After: this PR @ 647f17c4
tests/test_flag_fuse.py fails (no flag_fuse) 3117 lifted functions, 0 mismatches; formulas, 0 mismatches; ff cases 1344 fast float ops off and on

Risks

A wrong fused condition would send game logic down the wrong branch; the test runs about 3,000 lifted functions with it
on (over suyu's V, over #1871's, with main's locals) against off. Off by default. The lift's own sources change, so the
first build after this PR lifts the game again even with the switch unset. An executable built with A64_FLAG_FUSE=1
keeps the fused code until it is rebuilt with the switch unset (or a matching off build is used): the switch is a
lift-time one, part of the lift key; nothing a player keeps (saves, longshot_options.ini, runtime caches) changes.

Checklist

Ready for review

  • One topic, on current main; the title is a Conventional Commit.
  • Tested on my own PC, in the game for a change the game runs, as Testing says.
  • mise run test passes (any failure that also fails on main is named).
  • Measured against main, or Measurements says why there is nothing to measure.
  • No game files, build output or hand-edited generated files; third_party/ untouched; nothing GPL-incompatible.

When it applies

  • A check under tests/ that reads changed source is updated, not weakened.
  • Docs updated.
  • AI assistance recorded with Assisted-by: / Co-Authored-By: trailers.

Ready to merge

  • Everything in Still to test has run, its results in Tested.
  • Tier 1 hardware it can affect is tested (docs/dev/standards.md, "Hardware tiers").
  • Approved in review, every comment answered.
  • CI passes on the head; on current main, measured again or a comment says why the numbers still hold.
## Summary The parts of a local branch's flag fusion that neither main's local flags (`A64_LOCAL_FLAGS`) nor #1871 (`A64_SUB_V`, open) have, beside both: a B.cond, CSEL-family or CCMP reading flags set earlier in the same label-free run compares the compare's operands (a CCMP's immediate NZCV as a constant), and ADDS/CMN write V with `__builtin_add_overflow`. A subtraction's V is left to main or #1871: the fused runs recognise both texts. FCMP is main's. Functions that keep their context (the ones the patches name) get the kit's text. A lift-time `A64_` switch: it changes the lift key. See #1871. From b2c4c7eb and 94e68f79. With the review (futondestroyer, BeanBot): a run is fused only where it costs no fast float op (four float ops, a CMP and four more stay one region the switch off makes, left unfused; eight each side become two regions of eight around the fused CMP); the functions that keep their context with main's locals (spliced code, an entry above the first block, the patches' addresses, the ones no play ran) keep it whenever fusion is on (`guest_locals.keep_context`); with lifter comments a fused site shows the guest's word; the lift prints the fused reads, the runs left for a fast float region and the regions and ops. The test takes `test_fpx_sticky.py`'s compiler selection and fails without a compiler. Read first: `nx2/flag_fuse.py`, `install_plain` in `nx2/guest_locals.py`, `tests/test_flag_fuse.py`. ## Testing **Tested:** Windows 11, i7-9700, RTX 4060, llvm-mingw clang 23.1.5, Python 3.14.7 (the Builder's); game-free checks only. This change has not run in the game on this PC yet, with the switch on or off (Still to test). Each check ran in a hidden console of its own, through the PC's job queue, on this branch rebased onto `main` @ f1f2dc5b: - `python -I -B tests/test_flag_fuse.py` on 4a0a99b8 (job fb2-1980-1; the head 647f17c4 differs from it only in `tests/test_entry_below_locals.py` and `tests/test_locals_ran_only.py`; no `--cc`: the Builder's llvm-mingw clang and clang++ through `LONGSHOT_MINGW`): exit 0, "formulas: 4000576 operand pairs x 4 ops, 0 mismatches", "lifted: 2805300 runs of 3117 functions, 0 mismatches", "flag fuse: ok (3117 lifted cases)"; the ff cases' fast float ops the same in every build ("off: 84 regions, 1344 float ops", "on: 154 regions, 1344 float ops", the same on over #1871's V, and with main's locals off and on); "driver: keep_context with only A64_FLAG_FUSE on; plan(): 4001 classifications for 4000 setters". - The same at the test commit (633f9ad3, the review's cases before their fix, same job): exit 1 at its first new check, "ff4_b0 (on) was fused, cutting a fast float region" (the test stops at its first failure, so the later new checks did not run there). - `python -I -B tests/run_all.py --strict --changed origin/main` on the head 647f17c4 (job fb2-1980-2; 8 at once): 30 passed (`test_flag_fuse.py`, `test_fpx_sticky.py`, `test_entry_below_locals.py`, `test_locals_ran_only.py` among them), 7 failed, 1 skipped. The 7 are the checks this description already named as failing on `main` @ 2e1f6c32 too (`test_dev_packs.py`, `test_libc_hooks.py`, `test_lift_cache.py`, `test_linux_preflight.py`, `test_make_game_ngx.py`, `test_oot_shadow_fit.py`, `test_sdiv_overflow.py`); not run on `main` @ f1f2dc5b in this round. On 4a0a99b8 (job fb2-1980-1) `test_entry_below_locals.py` and `test_locals_ran_only.py` failed too: they read the exclusions in `nx2/lift.py`'s text, now in `guest_locals.keep_context`; the head updates them. **Still to test:** - Windows 11, this PC (i7-9700, RTX 4060): `main` @ f1f2dc5b and this head built twice, `A64_FLAG_FUSE` unset and `=1` (each a re-lift: `dev.py ab --env` cannot switch it), the same save and warmed route, two or more interleaved runs each: game-thread CPU time, average FPS, 1% lows, median and p99 frame times; clean lift, compile and link time, executable size and peak build memory off and on; the lift's "flag fusion" line (fused reads, runs left for a fast float region, fast float regions and ops), expecting the same game and frame times within the runs' spread or better (by hand, queued with the opener) - Linux: `python3 -I -B tests/test_flag_fuse.py`, expecting it to pass (by hand) ## Measurements **Verdict:** `A64_FLAG_FUSE` ships off: an experiment, not measured in play yet (Still to test: pending); only its game-free test has run, which shows the fused code exact and, in its fast float cases, no fast float op lost. Setup: Windows 11, i7-9700, llvm-mingw clang 23.1.5; `tests/test_flag_fuse.py` through the PC's job queue (fb2-1980-1), this PR on `main` @ f1f2dc5b; the Before column is an earlier queue job's, on the first version of the test | | Before: main @ 51f5f9da (the test file copied in) | After: this PR @ 647f17c4 | |---|---|---| | `tests/test_flag_fuse.py` | fails (no `flag_fuse`) | 3117 lifted functions, 0 mismatches; formulas, 0 mismatches; ff cases 1344 fast float ops off and on | ## Risks A wrong fused condition would send game logic down the wrong branch; the test runs about 3,000 lifted functions with it on (over suyu's V, over #1871's, with main's locals) against off. Off by default. The lift's own sources change, so the first build after this PR lifts the game again even with the switch unset. An executable built with `A64_FLAG_FUSE=1` keeps the fused code until it is rebuilt with the switch unset (or a matching off build is used): the switch is a lift-time one, part of the lift key; nothing a player keeps (saves, `longshot_options.ini`, runtime caches) changes. ## Checklist ### Ready for review - [x] One topic, on current `main`; the title is a Conventional Commit. - [ ] Tested on my own PC, in the game for a change the game runs, as Testing says. - [ ] `mise run test` passes (any failure that also fails on `main` is named). - [ ] Measured against `main`, or Measurements says why there is nothing to measure. - [x] No game files, build output or hand-edited generated files; `third_party/` untouched; nothing GPL-incompatible. ### When it applies - [x] A check under `tests/` that reads changed source is updated, not weakened. - [x] Docs updated. - [x] AI assistance recorded with `Assisted-by:` / `Co-Authored-By:` trailers. ### Ready to merge - [ ] Everything in Still to test has run, its results in Tested. - [ ] Tier 1 hardware it can affect is tested (docs/dev/standards.md, "Hardware tiers"). - [ ] Approved in review, every comment answered. - [ ] CI passes on the head; on current `main`, measured again or a comment says why the numbers still hold.
perf(lift): A64_FLAG_FUSE=1, a compare fused with the branch or select that reads it (lift time, off)
Some checks failed
PR description / Description follows the template (pull_request_target) Successful in 5s
Website / Website on Cloudflare (pull_request_target) Has been skipped
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
CI / Website build and checks (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
Website / Website on Cloudflare (pull_request) Has been cancelled
bf18139e65
The forms of the branch's flag fusion that neither main's local flags nor #1871 (A64_SUB_V, open) have, beside both:
a B.cond, CSEL-family or CCMP that reads flags set earlier in the same label-free run reads the compare's operands
(block locals _ffa/_ffb; a CCMP's read of a CCMP before it is a select of the compare and its immediate NZCV's
constant), so the compiler emits CMP+Jcc/CMOVcc and the flag bytes are stored only where other code reads them; and
ADDS/CMN/CCMN write V with __builtin_add_overflow (one SETO) instead of the sign-bit formula, which #1871 (subtractions
only) leaves. A subtraction's V text is left as main has it, or as #1871 writes it: the fused runs recognise both.
FCMP is left to main (A64_LOCAL_FLAGS already writes its flags in the text). Functions that keep their context
(Lifter.no_local: the ones the patches name, and with nx2/ran_funcs.txt those play did not run) get the kit's text as
before: guest_locals.install_plain installs flag_fuse between its plain text and its wrappers. Fused sites stay out of
fastfp's fast float regions (94e68f79's fix). Off by default (A64_FLAG_FUSE unset: the lift is main's); an A64_
variable, so it is in the lift key.

tests/test_flag_fuse.py with tests/flag_fuse_test.c: the fused conditions and the ADD V against suyu's formulas on edge
and random operands; ~3,000 hand-encoded lifted functions run with the switch off against on, on over #1871's
subtraction V, and on with main's locals, from the same states; every integer compare case must be fused; a function
in no_local keeps the kit's text.

From b2c4c7eb and 94e68f79 on exp/x86-asm-sync (on by default there, before main's locals and #1871 existed; its
measurements were against a lift without locals and are not repeated here). References #1871.

Assisted-by: Claude Code
BeanBot left a comment

Recommendation: Request changes. Flag fusion can remove an entire fast-float region, and the fixture can report a pass on Windows without compiling anything. The reported runs show fixture equivalence on an earlier base. The in-game gain and clean-build cost are still unproven.

The lifter can feed integer compare operands directly into branches and selects and use the compiler’s overflow builtin for ADD. That could save guest CPU work and flag stores. It adds a text-rewriting pass that interacts with flag liveness, game patches, and fast-float region formation. Players get the existing generated code with the switch unset, though the new lift sources change the translation cache key.

@fix will do (13)

  1. L1 (its part an edit can do) nx2/flag_fuse.py:315: Skip fusion at sites where it would break an otherwise profitable fast-float region. Add a four-plus-four fixture and report how many fast-float operations and regions each build retains.
  2. L2 nx2/lift.py:210: With A64_FLAG_FUSE=1 and both local switches set to 0, the lift skips keep_not_ran and keep_spliced. (more on the line)
  3. L3 (minor) nx2/flag_fuse.py:177: A label-free stretch of setters with no flag reader is scanned again from every setter. (more on the line)
  4. L4 tests/test_flag_fuse.py:272: Compiler discovery misses a supported Windows setup. (more on the line)
  5. L5 tests/test_flag_fuse.py:293: The fixture inherits switches that change the paths it exercises. (more on the line)
  6. L6 tests/test_flag_fuse.py:233: The ADD test would still pass if the production op_text wrapper stopped calling native_text. (more on the line)
  7. L7 (minor) tests/test_flag_fuse.py:224: The locals-on variant is compared with an off build that disables both local switches. (more on the line)
  8. L8 (minor) tests/test_flag_fuse.py:171: The conditional-compare fixtures use one CCMP or CCMN at a time. (more on the line)
  9. L9 tests/flag_fuse_test.c:55: The Windows driver opens a Python-generated absolute temp path using narrow argv and fopen. (more on the line)
  10. L10 (minor) tests/flag_fuse_test.c:57: The driver accepts any number of edge values read. (more on the line)
  11. L11 (its part an edit can do): Add the fused-read and retained fast-float operation counts to the A/B report so a timing change can be attributed to either path.
  12. L12 (its part an edit can do) nx2/flag_fuse.py:302: Resolve the switch once per lift process and bypass the new hooks when it is off. Report lift and compile separately so either cost is visible.
  13. L13 (minor): Risks says unsetting the switch rolls it back and caches stay the same. An executable already built with fusion keeps running that code. Say to unset it before rebuilding or reuse a matching off build, and distinguish the changed translation key from player saves, settings and runtime caches.

For the author (3) (a run, a measurement or a decision)

  • L1 nx2/flag_fuse.py:315: Measure what fusion costs fast-float code. (more on the line)
  • L11 (minor): Measure the in-game gain against the merge base. Compare main and this head with the switch off and on, at the same save, scene, settings and build type, with at least two interleaved runs per variant. Report game-thread CPU time, average FPS, 1% lows, and median and p99 frame times. Cover the affected Tier 1 configurations, including RADV and Steam Deck, before choosing the default.
  • L12 (minor) nx2/flag_fuse.py:302: Report clean lift, compile and link time, emitted C and executable size, and peak build memory with the switch off and on against the merge base. (more on the line)

Checks: Still running: PR description / Description follows the template (pull_request_target), CI / Conventional Commit title (pull_request), CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request), CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request), CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request), CI / Workflow lint (actionlint) (pull_request), CI / Website build and checks (pull_request), Guide screenshots / Guide images and local UI source review (pull_request), Third-party parts / As their notes say (pull_request), Third-party parts / The same as upstream (pull_request).

More: does it help, other systems, switches, what was read

Does it help: Unproven. The author reports zero mismatches across 4,000,576 operand pairs for each of four operations and 2,731,500 lifted comparisons across 3,035 fixtures on Windows at 5ff77c6f. The copied test on main stopped at a missing module. There are no game frame-time, CPU-time, or clean-build measurements against 6e1521a70a.

Other systems: Fusion changes guest CPU code on both Windows and Linux, including Steam Deck, independently of GPU vendor. It can change fast-float regions, emitted C size, and compiler work. The lift key includes the switch and the new module. The Windows Builder and Linux AppImage package the module through their existing source lists. No renderer, shader, save, audio, input, or runtime API files changed. Game patches depend on preserving specific emitted text. Both forked and spawned emission paths were traced in source, and fixture evidence covers direct emission.

Switches: A64_FLAG_FUSE is a build-only A/B switch, off when unset, empty, 0, false, off, or no. The build table documents it, and the A64_ prefix puts it in the lift key. Build-only switches belong in that table. Off limits exposure during the experiment. The measurements required to choose a shipping default are pending.

Reviewed: bf18139e65 against 6e1521a70a: Read all six changed files, the commit and diff, AGENTS.md, CONTRIBUTING.md, the Forgejo PR template, and docs/dev/standards.md. Read the relevant sections of the kit translator and emitter, local flag analysis, fast-float regions, lift workers, patch matching, giant splitting, build cache, packaging, and the test runner. Reviewed the supplied test report and CI status. No matching in-tree run record, docs/review-checklist.md, or sibling Tooling checkout was available. Generated C and the historical experiment runs were unavailable for inspection.; nothing run (a code review).

Checked and fine:

  • The W and X formulas use unsigned arithmetic for wraparound and width-specific signed comparisons. Both CCMP paths initialize the selector before a later fused condition uses it.
  • The planner stops at labels, address gaps and unsupported flag accesses. Liveness preserves flags for ordinary readers and outgoing control flow. The original function body is restored in finally.
  • Emit workers own their lifter state and merge counters in the parent. No new shared runtime state or thread-local allocation was added.
  • One focused Conventional Commit with an Assisted-by trailer. The instruction fixtures are hand-authored. The diff contains no game data, generated files, SDKs, third-party edits, or interface changes requiring an API version bump.
  • The fixture builds and runs temporary local files as described, with no download or installation. git diff --check passed.

Testing: Read-only review. No builds, tests, or project scripts were run here. The author reports 30 passes, seven failures also present on the earlier base, and one skip in the changed-file Windows suite. The full suite, Linux fixture, and in-game runs remain outstanding. The supplied head checks are still running and list no head-only failure.

Overlaps and merge order: #1871 changes subtraction V and shares the lifter integration. No required merge order is evident. The fixture substitutes its two formula strings, so rebase whichever lands second and verify the actual combined pass ordering, flag behavior, and timings. Forgejo reports this head as unmergeable without supplying conflict details.


Automated code review by BeanBot (gpt-6.2-sol), on the pull request's opening. Nothing was run; a maintainer decides.

**Recommendation: Request changes.** Flag fusion can remove an entire fast-float region, and the fixture can report a pass on Windows without compiling anything. The reported runs show fixture equivalence on an earlier base. The in-game gain and clean-build cost are still unproven. The lifter can feed integer compare operands directly into branches and selects and use the compiler’s overflow builtin for ADD. That could save guest CPU work and flag stores. It adds a text-rewriting pass that interacts with flag liveness, game patches, and fast-float region formation. Players get the existing generated code with the switch unset, though the new lift sources change the translation cache key. **`@fix` will do (13)** 1. **L1** (its part an edit can do) `nx2/flag_fuse.py:315`: Skip fusion at sites where it would break an otherwise profitable fast-float region. Add a four-plus-four fixture and report how many fast-float operations and regions each build retains. 2. **L2** `nx2/lift.py:210`: With A64_FLAG_FUSE=1 and both local switches set to 0, the lift skips keep_not_ran and keep_spliced. (more on the line) 3. **L3** (minor) `nx2/flag_fuse.py:177`: A label-free stretch of setters with no flag reader is scanned again from every setter. (more on the line) 4. **L4** `tests/test_flag_fuse.py:272`: Compiler discovery misses a supported Windows setup. (more on the line) 5. **L5** `tests/test_flag_fuse.py:293`: The fixture inherits switches that change the paths it exercises. (more on the line) 6. **L6** `tests/test_flag_fuse.py:233`: The ADD test would still pass if the production op_text wrapper stopped calling native_text. (more on the line) 7. **L7** (minor) `tests/test_flag_fuse.py:224`: The locals-on variant is compared with an off build that disables both local switches. (more on the line) 8. **L8** (minor) `tests/test_flag_fuse.py:171`: The conditional-compare fixtures use one CCMP or CCMN at a time. (more on the line) 9. **L9** `tests/flag_fuse_test.c:55`: The Windows driver opens a Python-generated absolute temp path using narrow argv and fopen. (more on the line) 10. **L10** (minor) `tests/flag_fuse_test.c:57`: The driver accepts any number of edge values read. (more on the line) 11. **L11** (its part an edit can do): Add the fused-read and retained fast-float operation counts to the A/B report so a timing change can be attributed to either path. 12. **L12** (its part an edit can do) `nx2/flag_fuse.py:302`: Resolve the switch once per lift process and bypass the new hooks when it is off. Report lift and compile separately so either cost is visible. 13. **L13** (minor): Risks says unsetting the switch rolls it back and caches stay the same. An executable already built with fusion keeps running that code. Say to unset it before rebuilding or reuse a matching off build, and distinguish the changed translation key from player saves, settings and runtime caches. **For the author (3)** (a run, a measurement or a decision) - **L1** `nx2/flag_fuse.py:315`: Measure what fusion costs fast-float code. (more on the line) - **L11** (minor): Measure the in-game gain against the merge base. Compare main and this head with the switch off and on, at the same save, scene, settings and build type, with at least two interleaved runs per variant. Report game-thread CPU time, average FPS, 1% lows, and median and p99 frame times. Cover the affected Tier 1 configurations, including RADV and Steam Deck, before choosing the default. - **L12** (minor) `nx2/flag_fuse.py:302`: Report clean lift, compile and link time, emitted C and executable size, and peak build memory with the switch off and on against the merge base. (more on the line) **Checks:** Still running: `PR description / Description follows the template (pull_request_target)`, `CI / Conventional Commit title (pull_request)`, `CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request)`, `CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request)`, `CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request)`, `CI / Workflow lint (actionlint) (pull_request)`, `CI / Website build and checks (pull_request)`, `Guide screenshots / Guide images and local UI source review (pull_request)`, `Third-party parts / As their notes say (pull_request)`, `Third-party parts / The same as upstream (pull_request)`. <details> <summary>More: does it help, other systems, switches, what was read</summary> **Does it help:** Unproven. The author reports zero mismatches across 4,000,576 operand pairs for each of four operations and 2,731,500 lifted comparisons across 3,035 fixtures on Windows at 5ff77c6f. The copied test on main stopped at a missing module. There are no game frame-time, CPU-time, or clean-build measurements against 6e1521a70a32. **Other systems:** Fusion changes guest CPU code on both Windows and Linux, including Steam Deck, independently of GPU vendor. It can change fast-float regions, emitted C size, and compiler work. The lift key includes the switch and the new module. The Windows Builder and Linux AppImage package the module through their existing source lists. No renderer, shader, save, audio, input, or runtime API files changed. Game patches depend on preserving specific emitted text. Both forked and spawned emission paths were traced in source, and fixture evidence covers direct emission. **Switches:** A64_FLAG_FUSE is a build-only A/B switch, off when unset, empty, 0, false, off, or no. The build table documents it, and the A64_ prefix puts it in the lift key. Build-only switches belong in that table. Off limits exposure during the experiment. The measurements required to choose a shipping default are pending. **Reviewed:** bf18139e65d5 against 6e1521a70a32: Read all six changed files, the commit and diff, AGENTS.md, CONTRIBUTING.md, the Forgejo PR template, and docs/dev/standards.md. Read the relevant sections of the kit translator and emitter, local flag analysis, fast-float regions, lift workers, patch matching, giant splitting, build cache, packaging, and the test runner. Reviewed the supplied test report and CI status. No matching in-tree run record, docs/review-checklist.md, or sibling Tooling checkout was available. Generated C and the historical experiment runs were unavailable for inspection.; nothing run (a code review). **Checked and fine:** - The W and X formulas use unsigned arithmetic for wraparound and width-specific signed comparisons. Both CCMP paths initialize the selector before a later fused condition uses it. - The planner stops at labels, address gaps and unsupported flag accesses. Liveness preserves flags for ordinary readers and outgoing control flow. The original function body is restored in finally. - Emit workers own their lifter state and merge counters in the parent. No new shared runtime state or thread-local allocation was added. - One focused Conventional Commit with an Assisted-by trailer. The instruction fixtures are hand-authored. The diff contains no game data, generated files, SDKs, third-party edits, or interface changes requiring an API version bump. - The fixture builds and runs temporary local files as described, with no download or installation. git diff --check passed. **Testing:** Read-only review. No builds, tests, or project scripts were run here. The author reports 30 passes, seven failures also present on the earlier base, and one skip in the changed-file Windows suite. The full suite, Linux fixture, and in-game runs remain outstanding. The supplied head checks are still running and list no head-only failure. **Overlaps and merge order:** #1871 changes subtraction V and shares the lifter integration. No required merge order is evident. The fixture substitutes its two formula strings, so rebase whichever lands second and verify the actual combined pass ordering, flag behavior, and timings. Forgejo reports this head as unmergeable without supplying conflict details. </details> --- <sub>Automated code review by BeanBot (gpt-6.2-sol), on the pull request's opening. Nothing was run; a maintainer decides.</sub>
nx2/flag_fuse.py Outdated
@ -0,0 +174,4 @@
j += 1
if last:
runs.append(run[:last])
i = run[last - 1][0] + 1 if last else i + 1
Member

L3 (minor): A label-free stretch of setters with no flag reader is scanned again from every setter. A 10,000-setter stretch takes about 50 million classifications instead of 10,000. Track the current setter and the last consumer in one forward pass, discarding captures that a later setter overwrites before any read.

**L3** (minor): A label-free stretch of setters with no flag reader is scanned again from every setter. A 10,000-setter stretch takes about 50 million classifications instead of 10,000. Track the current setter and the last consumer in one forward pass, discarding captures that a later setter overwrites before any read.
nx2/flag_fuse.py Outdated
@ -0,0 +299,4 @@
a64_lift.COND_READS.append(0)
base_op_text = a64_lift.op_text
def op_text(text, fpx):
Member

L12 (minor): Report clean lift, compile and link time, emitted C and executable size, and peak build memory with the switch off and on against the merge base. The off path still checks the environment per translated text and installs the eligibility wrapper. The on path scans bodies and can change the amount of C and fast-float code compiled.

**L12** (minor): Report clean lift, compile and link time, emitted C and executable size, and peak build memory with the switch off and on against the merge base. The off path still checks the environment per translated text and installs the eligibility wrapper. The on path scans bodies and can change the amount of C and fast-float code compiled.
nx2/flag_fuse.py Outdated
@ -0,0 +312,4 @@
# it, the run's other instructions still in regions, which nest inside its block)
base_eligible = fastfp.ff_eligible
def ff_eligible(text, stores=None):
Member

L1: Measure what fusion costs fast-float code. Four eligible scalar FP operations, a CMP, four more FP operations, and a B.cond form one eight-operation region before fusion. Excluding the fused CMP leaves two runs below the default threshold. The fixtures keep at least eight operations on one side and only check that some region survives.

**L1**: Measure what fusion costs fast-float code. Four eligible scalar FP operations, a CMP, four more FP operations, and a B.cond form one eight-operation region before fusion. Excluding the fused CMP leaves two runs below the default threshold. The fixtures keep at least eight operations on one side and only check that some region survives.
nx2/lift.py Outdated
@ -206,2 +207,4 @@
if a64_lift.local_regs() or a64_lift.local_flags() or flag_fuse.enabled(): # (flag fusion leaves them alone too)
print("locals: %d functions that hold an address the patches name kept in the context" % (
local_regs.keep_mentioned(L, oot_patches.mentioned_addresses())))
if a64_lift.local_regs() or a64_lift.local_flags():
Member

L2: With A64_FLAG_FUSE=1 and both local switches set to 0, the lift skips keep_not_ran and keep_spliced. A function excluded by the default ran list can then get fused branches and the ADD rewrite, despite the stated scope. Apply those exclusions when fusion is active and exercise the lift-driver configuration in a fixture.

**L2**: With A64_FLAG_FUSE=1 and both local switches set to 0, the lift skips keep_not_ran and keep_spliced. A function excluded by the default ran list can then get fused branches and the ADD rewrite, despite the stated scope. Apply those exclusions when fusion is active and exercise the lift-driver configuration in a fixture.
@ -0,0 +52,4 @@
}
int main(int argc, char **argv) {
FILE *f = fopen(argv[1], "rb");
Member

L9: The Windows driver opens a Python-generated absolute temp path using narrow argv and fopen. A temp directory containing characters outside the active code page can fail even when Python successfully wrote the file. Emit the constants into the existing generated fixture header and remove the path argument.

**L9**: The Windows driver opens a Python-generated absolute temp path using narrow argv and fopen. A temp directory containing characters outside the active code page can fail even when Python successfully wrote the file. Emit the constants into the existing generated fixture header and remove the path argument.
@ -0,0 +54,4 @@
int main(int argc, char **argv) {
FILE *f = fopen(argv[1], "rb");
if (!f) return 2;
nedge = (int)fread(edge, 8, 64, f);
Member

L10 (minor): The driver accepts any number of edge values read. An empty fixture reaches modulo by zero in pick, and a short read silently reduces the edge coverage. Compile the constants into the fixture and derive the count from the array, or require the exact count and report a read error.

**L10** (minor): The driver accepts any number of edge values read. An empty fixture reaches modulo by zero in pick, and a short read silently reduces the edge coverage. Compile the constants into the fixture and derive the count from the array, or require the exact count and report a read error.
@ -0,0 +168,4 @@
if (c1 + nzcv + k) % 3 and nzcv not in (0, 15):
continue # (every NZCV, each condition after it, a third of the rest)
ccmp = base | rm | c1 << 12 | 3 << 5 | nzcv
cases.append(("%s_%d_%d_%d" % (op, c1, nzcv, k),
Member

L8 (minor): The conditional-compare fixtures use one CCMP or CCMN at a time. They miss the stated case where a second CCMP uses the first CCMP’s fallback NZCV to decide whether to compare. Add a two-CCMP fixture with distinct fallback flags and states that exercise both paths.

**L8** (minor): The conditional-compare fixtures use one CCMP or CCMN at a time. They miss the stated case where a second CCMP uses the first CCMP’s fallback NZCV to decide whether to compare. Add a two-CCMP fixture with distinct fallback flags and states that exercise both paths.
@ -0,0 +221,4 @@
raise SystemExit("flag fuse: a64emit did not translate %s" % [hex(keys[x][1]) for x, f in zip(order, fl) if f])
out, table, used = [], [], set()
# (the switch off; on; on over #1871's subtraction V; on with main's locals: registers and flags as C locals)
modes = (("off", {"A64_FLAG_FUSE": ""}, False), ("on", {"A64_FLAG_FUSE": "1"}, False),
Member

L7 (minor): The locals-on variant is compared with an off build that disables both local switches. Add a paired off variant with main’s local registers and flags enabled so the default configuration is compared with only fusion changed.

**L7** (minor): The locals-on variant is compared with an off build that disables both local switches. Add a paired off variant with main’s local registers and flags enabled so the default configuration is compared with only fusion changed.
@ -0,0 +230,4 @@
for i, (name, _, _) in enumerate(cases):
e = 0x10000 + i * 0x100
text, _ = a64_lift.Lifter.emit_function(L, e, texts)
if mode in ("on", "subv") and not name.startswith(("label", "adcs", "fcmp", "ff_fcsel")) and \
Member

L6: The ADD test would still pass if the production op_text wrapper stopped calling native_text. The formula fixture calls native_text directly, the old ADD formula gives equivalent results, and the emitted ADD cases only check for fusion. Use a lifted ADDS or CCMN with V live at a trap and verify the overflow rewrite reaches that emitted function with fusion on, alongside the execution comparison.

**L6**: The ADD test would still pass if the production op_text wrapper stopped calling native_text. The formula fixture calls native_text directly, the old ADD formula gives equivalent results, and the emitted ADD cases only check for fusion. Use a lifted ADDS or CCMN with V live at a trap and verify the overflow rewrite reaches that emitted function with fusion on, alongside the execution comparison.
@ -0,0 +269,4 @@
p.add_argument("--cc")
p.add_argument("--cxx")
a = p.parse_args()
cc = find(a.cc, "CC", ("gcc", "cc", "clang"))
Member

L4: Compiler discovery misses a supported Windows setup. With llvm-mingw configured via LONGSHOT_MINGW and its bin directory absent from PATH, both lookups can fail and the test exits zero. The runner counts that as a pass even under --strict. Reuse the existing compiler and target selection used by test_fpx_sticky, preserve explicit overrides, and make missing compilers visible to the runner.

**L4**: Compiler discovery misses a supported Windows setup. With llvm-mingw configured via LONGSHOT_MINGW and its bin directory absent from PATH, both lookups can fail and the test exits zero. The runner counts that as a pass even under --strict. Reuse the existing compiler and target selection used by test_fpx_sticky, preserve explicit overrides, and make missing compilers visible to the runner.
@ -0,0 +290,4 @@
import dead_flags
import lift_fixes
import suyu_rt_fixes
os.environ["A64_FASTFP"] = "1" # (fast float regions as a lift has them by default)
Member

L5: The fixture inherits switches that change the paths it exercises. A64_PACKED_FLAGS=1 hides the SetFlags stores from fusion and defeats the integer cases. HOS_NO_FASTFP=1 lets the region text checks pass while the generated driver runs only the exact copies. Clear inherited lift and fast-float runtime switches before setting up the fixture’s explicit modes.

**L5**: The fixture inherits switches that change the paths it exercises. A64_PACKED_FLAGS=1 hides the SetFlags stores from fusion and defeats the integer cases. HOS_NO_FASTFP=1 lets the region text checks pass while the generated driver runs only the exact copies. Clear inherited lift and fast-float runtime switches before setting up the fixture’s explicit modes.
futondestroyer left a comment

Recommendation: Request changes. Preserve fast-float coverage and keep the documented function exclusions when fusion is enabled. The existing review identifies both changes and a compiler-discovery path that can report a fixture pass without running it. Fast-float eligibility · Function exclusions · Fixture discovery

Does it help? Unproven. The author reports zero mismatches across 4,000,576 operand pairs per operation and 2,731,500 lifted comparisons at 5ff77c6f. The source was rebased without changes, and the fixture and gameplay still need current-head evidence. The new pass targets guest CPU work and can change translation time and the amount of fast-float code. Compare main and separately built fusion-off and fusion-on executables on the same warmed route. Record the lift’s fused-read and fast-float counts alongside clean build time, size, game-thread CPU time, average FPS, 1% lows, and median and p99 frame time. dev.py ab --env launches both arms from one already-built executable, so it cannot test this switch. A/B build selection

Checked and fine. The lift key includes A64_FLAG_FUSE and the new module. Fusion defaults off and changes the CPU code emitted during the build. The liveness pass still sees unfused flag reads and exit edges, and the workers restore the original function bodies after emission.

The Linux fixture and affected Tier 1 gameplay are still outstanding. The PR remains WIP. The description check passed, and the other relevant Forge checks were pending. Beanstalk shows no plan or jobs, and its stock variants cannot enable this lift-time switch. Beanstalk

Reviewed bf18139e against 6e1521a7. Read all six changed files and traced the translator, emitters, flag liveness, function exclusions, worker setup, fast-float regions, giant-function splitting, and lift-key construction with revision-matched Graphify maps and source. A later combination with the subtraction-V experiment needs a check of the actual combined passes. This review was source-only. Subtraction-V PR

**Recommendation: Request changes.** Preserve fast-float coverage and keep the documented function exclusions when fusion is enabled. The existing review identifies both changes and a compiler-discovery path that can report a fixture pass without running it. [Fast-float eligibility](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1980#issuecomment-62578) · [Function exclusions](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1980#issuecomment-62579) · [Fixture discovery](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1980#issuecomment-62581) **Does it help?** Unproven. The author reports zero mismatches across 4,000,576 operand pairs per operation and 2,731,500 lifted comparisons at `5ff77c6f`. The source was rebased without changes, and the fixture and gameplay still need current-head evidence. The new pass targets guest CPU work and can change translation time and the amount of fast-float code. Compare `main` and separately built fusion-off and fusion-on executables on the same warmed route. Record the lift’s fused-read and fast-float counts alongside clean build time, size, game-thread CPU time, average FPS, 1% lows, and median and p99 frame time. `dev.py ab --env` launches both arms from one already-built executable, so it cannot test this switch. [A/B build selection](https://git.magicbean.dev/MagicBeanDev/Longshot/src/commit/6e1521a70a32603ed60a8263e4072625885669b7/scripts/devtools/ab.py#L651) **Checked and fine.** The lift key includes `A64_FLAG_FUSE` and the new module. Fusion defaults off and changes the CPU code emitted during the build. The liveness pass still sees unfused flag reads and exit edges, and the workers restore the original function bodies after emission. The Linux fixture and affected Tier 1 gameplay are still outstanding. The PR remains WIP. The description check passed, and the other relevant Forge checks were pending. Beanstalk shows no plan or jobs, and its stock variants cannot enable this lift-time switch. [Beanstalk](https://beanstalk.magicbean.dev/prs/1980) **Reviewed** `bf18139e` against `6e1521a7`. Read all six changed files and traced the translator, emitters, flag liveness, function exclusions, worker setup, fast-float regions, giant-function splitting, and lift-key construction with revision-matched Graphify maps and source. A later combination with the subtraction-V experiment needs a check of the actual combined passes. This review was source-only. [Subtraction-V PR](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1871)
nx2/flag_fuse.py Outdated
@ -0,0 +261,4 @@
if closes:
text = text.rstrip() + " }"
n += 1
key = w | n << 32
Member

Minor. The synthetic key is also stored as the instruction word in new_body. With lifter comments enabled, fastfp.emit_function prints that key as the guest opcode, so a first-site CMP with word eb02003f is reported as 1eb02003f. Keep the per-site text lookup separate from the opcode displayed in diagnostic output and add a comments-enabled case.

Minor. The synthetic key is also stored as the instruction word in `new_body`. With lifter comments enabled, `fastfp.emit_function` prints that key as the guest opcode, so a first-site CMP with word `eb02003f` is reported as `1eb02003f`. Keep the per-site text lookup separate from the opcode displayed in diagnostic output and add a comments-enabled case.
siantm force-pushed perf/lift-flag-fuse from bf18139e65
Some checks failed
PR description / Description follows the template (pull_request_target) Successful in 5s
Website / Website on Cloudflare (pull_request_target) Has been skipped
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
CI / Website build and checks (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
Website / Website on Cloudflare (pull_request) Has been cancelled
to 647f17c47f
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
CI / Website build and checks (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
Website / Website on Cloudflare (pull_request) Blocked by required conditions
PR description / Description follows the template (pull_request_target) Successful in 6s
beanstalk/approval waiting for a BigBean's 👍 on the request
Website / Website on Cloudflare (pull_request_target) Has been skipped
2026-11-21 04:38:12 +00:00
Compare
Author
Contributor

Pushed 647f17c4 (rebased onto main @ f1f2dc5b; the first commit unchanged), answering futondestroyer's review and BeanBot's: the review's cases as failing checks (633f9ad3) and their fixes (647f17c4): fusion no longer costs a fast float op, the context-keeping functions are excluded whenever fusion is on, a fused site's comment shows the guest's word, the fixture takes test_fpx_sticky.py's compiler selection and clears inherited switches, and the lift reports the fused reads and fast float regions. Summary, Testing, Still to test (the in-game A/B, pending with the opener), Measurements and Risks updated. A comment in nx2/flag_fuse.py and the test's docstring no longer count the game's chunks.

Pushed 647f17c4 (rebased onto `main` @ f1f2dc5b; the first commit unchanged), answering futondestroyer's review and BeanBot's: the review's cases as failing checks (633f9ad3) and their fixes (647f17c4): fusion no longer costs a fast float op, the context-keeping functions are excluded whenever fusion is on, a fused site's comment shows the guest's word, the fixture takes `test_fpx_sticky.py`'s compiler selection and clears inherited switches, and the lift reports the fused reads and fast float regions. Summary, Testing, Still to test (the in-game A/B, pending with the opener), Measurements and Risks updated. A comment in `nx2/flag_fuse.py` and the test's docstring no longer count the game's chunks.
Author
Contributor

Re #1980 (comment) (futondestroyer): all three are in 647f17c4 with their tests in 633f9ad3: a run is fused only where it costs no fast float op (four float ops, a CMP, four more stay one region of eight; eight each side fuse into two regions of eight), the documented exclusions apply whenever fusion is on (guest_locals.keep_context), and the fixture uses test_fpx_sticky.py's compiler and target selection and fails when it finds none. The lift now prints the fused reads, the runs kept for a region and the fast float regions and ops; the in-game A/B you describe (main, and separately built off and on executables, same warmed route) is pending with the opener, not run in this round.

Re https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1980#issuecomment-62891 (futondestroyer): all three are in 647f17c4 with their tests in 633f9ad3: a run is fused only where it costs no fast float op (four float ops, a CMP, four more stay one region of eight; eight each side fuse into two regions of eight), the documented exclusions apply whenever fusion is on (`guest_locals.keep_context`), and the fixture uses `test_fpx_sticky.py`'s compiler and target selection and fails when it finds none. The lift now prints the fused reads, the runs kept for a region and the fast float regions and ops; the in-game A/B you describe (main, and separately built off and on executables, same warmed route) is pending with the opener, not run in this round.
Author
Contributor

Re #1980 (comment) (futondestroyer): fixed in 647f17c4: with lifter comments on, a fused site's comment gets the guest's word back (the key stays the text lookup only), and the test emits a fused CMP with comments on and checks the comment reads f100143f, eight digits (633f9ad3). (At 633f9ad3 the test stops at its first failure, the four-plus-four case, before it reaches this check.)

Re https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1980#issuecomment-62890 (futondestroyer): fixed in 647f17c4: with lifter comments on, a fused site's comment gets the guest's word back (the key stays the text lookup only), and the test emits a fused CMP with comments on and checks the comment reads `f100143f`, eight digits (633f9ad3). (At 633f9ad3 the test stops at its first failure, the four-plus-four case, before it reaches this check.)
Author
Contributor

Re #1980 (comment) (L1): fixed in 647f17c4 as futondestroyer asked too: flag_fuse.ff_regions_off finds the regions the switch off makes, and a run whose sites would cut one into a part below A64_FASTFP_MIN ops is left unfused. The fixture adds your four-plus-four case (one region of eight, left whole and unfused) and checks every ff case keeps as many fast float ops on as off, printing each build's regions and ops (633f9ad3). At 633f9ad3 the test fails there ("ff4_b0 (on) was fused, cutting a fast float region"); with the fix every ff case keeps its 1344 fast float ops on as off ("off: 84 regions, 1344 float ops", "on: 154 regions, 1344 float ops"). The in-game cost is pending with the opener.

Re https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1980#issuecomment-62578 (L1): fixed in 647f17c4 as futondestroyer asked too: `flag_fuse.ff_regions_off` finds the regions the switch off makes, and a run whose sites would cut one into a part below `A64_FASTFP_MIN` ops is left unfused. The fixture adds your four-plus-four case (one region of eight, left whole and unfused) and checks every ff case keeps as many fast float ops on as off, printing each build's regions and ops (633f9ad3). At 633f9ad3 the test fails there ("ff4_b0 (on) was fused, cutting a fast float region"); with the fix every ff case keeps its 1344 fast float ops on as off ("off: 84 regions, 1344 float ops", "on: 154 regions, 1344 float ops"). The in-game cost is pending with the opener.
Author
Contributor

Re #1980 (comment) (L2): fixed in 647f17c4: the exclusions (spliced code, an entry above the first block, the patches' addresses, the functions no play ran) are one function, guest_locals.keep_context, which nx2/lift.py calls and which applies them when main's locals or fusion is on. The test runs it with only A64_FLAG_FUSE=1 and checks a function outside the ran list is kept and emitted unfused (633f9ad3).

Re https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1980#issuecomment-62579 (L2): fixed in 647f17c4: the exclusions (spliced code, an entry above the first block, the patches' addresses, the functions no play ran) are one function, `guest_locals.keep_context`, which `nx2/lift.py` calls and which applies them when main's locals or fusion is on. The test runs it with only `A64_FLAG_FUSE=1` and checks a function outside the ran list is kept and emitted unfused (633f9ad3).
Author
Contributor

Re #1980 (comment) (L3): fixed in 647f17c4: when plan() finds no reader before a run stops, it goes on after that stop instead of scanning again from the next setter; the test counts classify calls over a 4,000-setter stretch and requires at most three per instruction.

Re https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1980#issuecomment-62580 (L3): fixed in 647f17c4: when `plan()` finds no reader before a run stops, it goes on after that stop instead of scanning again from the next setter; the test counts `classify` calls over a 4,000-setter stretch and requires at most three per instruction.
Author
Contributor

Re #1980 (comment) (L4): fixed in 633f9ad3: the test takes tests/test_fpx_sticky.py's compiler and target_flags (--cc/--cxx, $CC/$CXX, LONGSHOT_MINGW's, PATH, the build's own) and fails, not exits 0, when it finds no C or C++ compiler. The queue run found the Builder's llvm-mingw that way, with no --cc.

Re https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1980#issuecomment-62581 (L4): fixed in 633f9ad3: the test takes `tests/test_fpx_sticky.py`'s `compiler` and `target_flags` (`--cc`/`--cxx`, `$CC`/`$CXX`, `LONGSHOT_MINGW`'s, PATH, the build's own) and fails, not exits 0, when it finds no C or C++ compiler. The queue run found the Builder's llvm-mingw that way, with no `--cc`.
Author
Contributor

Re #1980 (comment) (L5): fixed in 633f9ad3: every A64_, HOS_ and RX_ variable inherited from the shell (A64_PACKED_FLAGS, HOS_NO_FASTFP, ...) is removed before the fixture sets its own modes.

Re https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1980#issuecomment-62582 (L5): fixed in 633f9ad3: every `A64_`, `HOS_` and `RX_` variable inherited from the shell (`A64_PACKED_FLAGS`, `HOS_NO_FASTFP`, ...) is removed before the fixture sets its own modes.
Author
Contributor

Re #1980 (comment) (L6): fixed in 633f9ad3: for every ADDS and CMN case whose V is live at a BRK, the function emitted with fusion on (through the lift's op_text chain) must carry __builtin_add_overflow, beside the execution comparison.

Re https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1980#issuecomment-62583 (L6): fixed in 633f9ad3: for every ADDS and CMN case whose V is live at a BRK, the function emitted with fusion on (through the lift's `op_text` chain) must carry `__builtin_add_overflow`, beside the execution comparison.
Author
Contributor

Re #1980 (comment) (L7): fixed in 633f9ad3: a local_off build (main's locals, fusion off) is emitted beside local (locals, fusion on), and the driver runs each against the other, so only fusion differs.

Re https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1980#issuecomment-62584 (L7): fixed in 633f9ad3: a `local_off` build (main's locals, fusion off) is emitted beside `local` (locals, fusion on), and the driver runs each against the other, so only fusion differs.
Author
Contributor

Re #1980 (comment) (L8): fixed in 633f9ad3: two CCMPs in a row, each with its own immediate NZCV (pairs like 0100/0010 and 1001/0110) under several conditions, so the second decides on the first's compare or its fallback, run against the switch off.

Re https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1980#issuecomment-62585 (L8): fixed in 633f9ad3: two CCMPs in a row, each with its own immediate NZCV (pairs like 0100/0010 and 1001/0110) under several conditions, so the second decides on the first's compare or its fallback, run against the switch off.
Author
Contributor

Re #1980 (comment) (L9): fixed in 633f9ad3: the edge operands are an array in the generated flag_formulas.h; the driver takes no argument and opens no file.

Re https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1980#issuecomment-62586 (L9): fixed in 633f9ad3: the edge operands are an array in the generated `flag_formulas.h`; the driver takes no argument and opens no file.
Author
Contributor

Re #1980 (comment) (L10): fixed with L9 (633f9ad3): the count is the array's size, so there is no short read or empty fixture.

Re https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1980#issuecomment-62587 (L10): fixed with L9 (633f9ad3): the count is the array's size, so there is no short read or empty fixture.
Author
Contributor

Re #1980 (comment) (L12): the lift now prints the fused reads, the runs kept for a fast float region and the regions and ops (647f17c4). Reading the switch once per process and installing nothing when it is off is left for a later round (minor); the clean lift, compile and link times, sizes and peak memory off and on against the merge base are pending with the opener.

Re https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1980#issuecomment-62588 (L12): the lift now prints the fused reads, the runs kept for a fast float region and the regions and ops (647f17c4). Reading the switch once per process and installing nothing when it is off is left for a later round (minor); the clean lift, compile and link times, sizes and peak memory off and on against the merge base are pending with the opener.
Author
Contributor

Re #1980 (comment) (L11): the lift's report now has the fused reads and the retained fast float regions and ops with the switch on (647f17c4), so a timing change can be put on either. The in-game A/B (main, off, on; same save and scene, interleaved, frame times and lows, Tier 1 incl. RADV and the Deck) is pending with the opener.

Re https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1980#issuecomment-62589 (L11): the lift's report now has the fused reads and the retained fast float regions and ops with the switch on (647f17c4), so a timing change can be put on either. The in-game A/B (main, off, on; same save and scene, interleaved, frame times and lows, Tier 1 incl. RADV and the Deck) is pending with the opener.
Author
Contributor

Re #1980 (comment) (L13): Risks now says an executable built with fusion keeps that code until it is rebuilt with the switch unset (or a matching off build is used), and that the switch changes the lift key, not saves, settings or runtime caches.

Re https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1980#issuecomment-62589 (L13): Risks now says an executable built with fusion keeps that code until it is rebuilt with the switch unset (or a matching off build is used), and that the switch changes the lift key, not saves, settings or runtime caches.
Author
Contributor

@Beanstalk This adds a lift switch, A64_FLAG_FUSE, off by default: set, the lifter fuses a compare with the branch or select that reads its flags (nx2/flag_fuse.py, nx2/guest_locals.py). The farm cannot build with it set, so only the default build is to test: with the switch unset, the lift and its C must be main's. Please time the lift against main's and check the lifted C is the same, on a Windows PC and on a Linux PC. No game scenario is needed: unset, the game's code is main's.

@Beanstalk This adds a lift switch, A64_FLAG_FUSE, off by default: set, the lifter fuses a compare with the branch or select that reads its flags (nx2/flag_fuse.py, nx2/guest_locals.py). The farm cannot build with it set, so only the default build is to test: with the switch unset, the lift and its C must be main's. Please time the lift against main's and check the lifted C is the same, on a Windows PC and on a Linux PC. No game scenario is needed: unset, the game's code is main's.
Member

@siantm only members of BigBeans can start the farm. One of them can approve this request by reacting 👍 to it or to this comment.

@siantm only members of `BigBeans` can start the farm. One of them can approve this request by reacting 👍 to it or to this comment.
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
CI / Website build and checks (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
Website / Website on Cloudflare (pull_request) Blocked by required conditions
PR description / Description follows the template (pull_request_target) Successful in 6s
beanstalk/approval waiting for a BigBean's 👍 on the request
Website / Website on Cloudflare (pull_request_target) Has been skipped
This pull request is marked as a work in progress.
Some workflows are waiting to be reviewed.
This branch is out-of-date with the base branch
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u 'perf/lift-flag-fuse:siantm-perf/lift-flag-fuse'
git switch 'siantm-perf/lift-flag-fuse'
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
4 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!1980
No description provided.