Compare at the destination width when lowering CMP #82

Merged
Vonsek merged 2 commits from upstream-pr/83 into main 2026-11-21 16:24:11 +00:00
Vonsek commented 2026-11-21 15:41:11 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Vonsek on 2026-11-21T15:41:11Z.


Change

lower() in tools/ffx_version_query.py emitted CMP as a comparison against the raw iced immediate. iced reports 8-bit immediates sign-extended to 32 or 16 bits as 64-bit values, so cmp ecx,-1 became static_cast<uint32_t>(rcx) == 18446744073709551615ull: the zero flag could never be set and the carry flag was always set. Any je/jae/cmovbe after a cmp r32,-N took the wrong path. CMP now casts both operands to the destination width, matching the existing ADD/SUB/AND handling and the imm8 masking in cpu_leaf_aot.

The cpu_aot_heap_layout fixture gains an index_guard export (cmp ecx,-1 / je, cmp ecx,-3 / jae) that the native and lifted libraries must agree on.

Verification

On Linux, the fixture DLL was assembled with llvm-ml -m64 and linked with lld-link /dll /noentry, then tests/cpu/heap_layout.py emit ran and the lifted C++ was built with g++:

  • before: AssertionError: lifted.so: index guard returned 0xfffffffd for 0xfffffffd
  • after: all lifted heap_layout checks pass, and the cpu_aot_version_query lifted fixture still passes through the same pipeline.

Windows: ctest --preset dev --no-tests=error -R '^cpu_aot_heap_layout$' -V at f59e684 on Windows 11 build 26200.9974, VS Build Tools 2022 17.14 (MSVC 14.44.35207), Windows SDK 10.0.26100, Python 3.12, RTX 5080 (driver 32.0.16.1692): passed, with ML64 and MSVC building the native and lifted libraries. The Windows CI job also passed: https://github.com/R0Y00/Xbox2Windows/actions/runs/44920496026.

Evidence and follow-up

The new fixture function is original source in tests/cpu/heap_layout.asm (MIT). No game files were used. The lowerer is shared by the FidelityFX device-init, create-context and provider-loop translations, so regenerating those outputs picks up the corrected comparison. Whether the pinned package images contain a cmp r32,-N on these paths has not been checked.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6530893508 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/83). Originally posted by [Vonsek](https://github.com/Vonsek) on 2026-11-21T15:41:11Z. --- ## Change `lower()` in `tools/ffx_version_query.py` emitted CMP as a comparison against the raw iced immediate. iced reports 8-bit immediates sign-extended to 32 or 16 bits as 64-bit values, so `cmp ecx,-1` became `static_cast<uint32_t>(rcx) == 18446744073709551615ull`: the zero flag could never be set and the carry flag was always set. Any `je`/`jae`/`cmovbe` after a `cmp r32,-N` took the wrong path. CMP now casts both operands to the destination width, matching the existing ADD/SUB/AND handling and the imm8 masking in `cpu_leaf_aot`. The `cpu_aot_heap_layout` fixture gains an `index_guard` export (`cmp ecx,-1` / `je`, `cmp ecx,-3` / `jae`) that the native and lifted libraries must agree on. ## Verification On Linux, the fixture DLL was assembled with `llvm-ml -m64` and linked with `lld-link /dll /noentry`, then `tests/cpu/heap_layout.py emit` ran and the lifted C++ was built with g++: - before: `AssertionError: lifted.so: index guard returned 0xfffffffd for 0xfffffffd` - after: all lifted heap_layout checks pass, and the `cpu_aot_version_query` lifted fixture still passes through the same pipeline. Windows: `ctest --preset dev --no-tests=error -R '^cpu_aot_heap_layout$' -V` at f59e684 on Windows 11 build 26200.9974, VS Build Tools 2022 17.14 (MSVC 14.44.35207), Windows SDK 10.0.26100, Python 3.12, RTX 5080 (driver 32.0.16.1692): passed, with ML64 and MSVC building the native and lifted libraries. The Windows CI job also passed: https://github.com/R0Y00/Xbox2Windows/actions/runs/44920496026. ## Evidence and follow-up The new fixture function is original source in `tests/cpu/heap_layout.asm` (MIT). No game files were used. The lowerer is shared by the FidelityFX device-init, create-context and provider-loop translations, so regenerating those outputs picks up the corrected comparison. Whether the pinned package images contain a `cmp r32,-N` on these paths has not been checked.
upstream-sync closed this pull request 2026-11-24 06:41:15 +00:00
R0Y00 commented 2026-11-24 06:47:35 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-21T15:46:32Z.


Thanks for the CMP width fix. #88 touched the same lowerer. Please sync with main, rerun the native/lifted regression, and mark ready when the results agree.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7065133284 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/83#issuecomment-7065133284). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-21T15:46:32Z. --- Thanks for the CMP width fix. #88 touched the same lowerer. Please sync with main, rerun the native/lifted regression, and mark ready when the results agree.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
R0Y00/Xbox2Windows!82
No description provided.