cpu: add dedicated cpu_x87_exp_log_aot lifter for F2XM1, FYL2X, and FYL2XP1 #2415

Merged
Ammmae0x merged 3 commits from upstream-pr/2423 into main 2026-11-25 20:22:50 +00:00
Ammmae0x commented 2026-11-25 16:18:29 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Ammmae0x on 2026-11-25T16:18:29Z.


Change

Add a dedicated standalone x87 exponential/logarithmic AOT lifter (tools/cpu_x87_exp_log_aot.py) for F2XM1, FYL2X, and FYL2XP1, with a source-built MASM differential fixture (tests/cpu/x87_exp_log_aot.{asm,def}), verification suite (tests/cpu/x87_exp_log_aot_check.py), and CTest registration (cpu_aot_x87_exp_log in CMakeLists.txt). Disjoint from PR #1663 (tools/x87_lower.py, tools/x87_soft.h, and tests/cpu/x87_*.py are untouched).

  • Portable 80-bit extended-precision software core (BigF 128-bit integer arithmetic): lifts straight-line leaf functions (void lifted_<name>(word rcx, word rdx, word r8)) with zero host float/double/long double, <cmath>, or SSE instructions, avoiding MSVC 64-bit long double truncation and guaranteeing complete host MXCSR (DAZ/FTZ) isolation without clobbering MXCSR.
  • Supported x87 instructions and tested domains:
    • F2XM1: 2^ST(0) - 1 on the Intel SDM domain [-1, +1]; exact on +-0 (F2XM1(-0.0) == -0.0), +1, -1; <= 1 ULP vs arbitrary-precision 80-digit Decimal reference (observed max 0 ULP) and <= 1 ULP vs native x87 (observed max 1 ULP).
    • FYL2X: ST(1) * log2(ST(0)) with stack pop for x > 0 plus SDM special cases (#Z (ZE) on x == +-0 with finite nonzero y, #IA (IE) on negative x, (+-0, +-0), (+inf, +-0), (1, +-inf)).
    • FYL2XP1: ST(1) * log2(ST(0) + 1) with stack pop on the Intel SDM domain [-(1 - sqrt(2)/2), +(1 - sqrt(2)/2)] (plus lifted-only spec checks for x == -1 #Z (ZE) and x < -1 #IA (IE), where hardware behavior outside the SDM domain is undefined).
    • Bounded leaf x87 stack/control/status transport over flat zero-displacement [rcx|rdx|r8]: fld m32/m64/m80, fld1, fldz, fst m32/m64, fstp m32/m64/m80/st(0), fnstsw ax (+ mov word ptr [r8], ax), fldcw m16, fnstcw m16, fninit, and terminal ret.
  • Hardware fidelity: models FCW rounding modes (RN/RD/RU/RZ), FCW precision control (PC 24/53/64, preserved across fldcw/fnstcw and not truncating transcendental results per Intel SDM Vol. 1 8.1.5.2), sNaN quieting + #IA (IE), unnormals -> indefinite + #IA, #DE/#OE/#UE/#PE status flags, and stack depth/pop semantics.
  • Fail-closed rejections: rejects FSIN/FCOS/FSINCOS/FPTAN/FPATAN, stack overflow/underflow, non-empty x87 stack at ret, XMM/YMM/ZMM/VEX/EVEX, prefixes (including WAIT/9B), non-flat/displaced/indexed/non-arg memory, stores outside [r8], undefined ax reads, branches, missing ret, and trailing instructions after ret.

Verification

Verified on commit 65489770 (based on upstream/main 7092683a) in both dev (Debug) and release (/O2) presets (baseline x87, 0 skips):

  • cmake --build --preset dev --target cpu_x87_exp_log_aot_original cpu_x87_exp_log_aot_original_lifted cpu_x87_exp_log_aot_altered cpu_x87_exp_log_aot_altered_lifted -> exit 0.
  • ctest --preset dev -R "^cpu_aot_x87_exp_log$" -E "cpu_native_archive_" --output-on-failure -V -> 1/1 Passed (0.32s): 6 x87 exp/log sequences accepted; 37 rejection controls passed; 847 differential/FCW/status/special cases matched (max ULP vs Decimal ref=0, vs native x87=1); 36 MXCSR DAZ/FTZ isolation checks passed; 6 mutant controls + 5 altered-build controls caught.
  • cmake --build --preset release --target cpu_x87_exp_log_aot_original cpu_x87_exp_log_aot_original_lifted cpu_x87_exp_log_aot_altered cpu_x87_exp_log_aot_altered_lifted -> exit 0.
  • ctest --preset release -R "^cpu_aot_x87_exp_log$" -E "cpu_native_archive_" --output-on-failure -V -> 1/1 Passed (0.33s): identical 6/37/847 (max ULP ref=0, nat=1)/36/6+5 results.
  • FORM_COVERAGE_RECORD (both dev and release): 14 recorded forms (f2xm1,fld,fld1,fldcw,fldz,fninit,fnstcw,fnstsw,fst,fstp,fyl2x,fyl2xp1,mov,ret).
  • out/pe-env/Scripts/python.exe -B tests/form_coverage_check.py -> form coverage checks passed (exit 0).
  • out/pe-env/Scripts/python.exe -B tests/docs_links_check.py -> Self-test passed. Checked 19 Markdown files and 464 links. (exit 0).
  • out/pe-env/Scripts/python.exe -B tests/bidi_controls_check.py -> Self-test passed. Checked 1727 tracked source, script and build/CI files: no bidirectional controls. (exit 0).
  • Spot mutation audit on tools/cpu_x87_exp_log_aot.py: 8/8 mutations killed across translator guards (FSIN trig rejection, non-empty stack at ret, store-outside-r8, displaced memory) and rebuilt C++ semantics (F2XM1(-0.0) sign, FYL2X #Z, FYL2XP1 #Z, FCW rounding control).

Evidence and follow-up

All fixtures (tests/cpu/x87_exp_log_aot.asm, .def, _check.py) are source-built under the repository MIT license with ; coverage: record cpu_aot_x87_exp_log and ALTER_X87_EXP_LOG altered-build controls; no external binaries or game files are used. Contributors can build and run the test with ctest --preset dev -R "^cpu_aot_x87_exp_log$" -V (or --preset release).

Checklist

  • This pull request covers one reviewable behavior.
  • I included the exact command and result for every check I ran.
  • I considered a negative control or failure case for a new fixture.
  • I updated README/docs when a capability or build requirement changed.
  • I did not include game files, dumps, distribution links or secrets.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6608718330 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2423). Originally posted by [Ammmae0x](https://github.com/Ammmae0x) on 2026-11-25T16:18:29Z. --- ## Change Add a dedicated standalone x87 exponential/logarithmic AOT lifter (`tools/cpu_x87_exp_log_aot.py`) for `F2XM1`, `FYL2X`, and `FYL2XP1`, with a source-built MASM differential fixture (`tests/cpu/x87_exp_log_aot.{asm,def}`), verification suite (`tests/cpu/x87_exp_log_aot_check.py`), and CTest registration (`cpu_aot_x87_exp_log` in `CMakeLists.txt`). Disjoint from PR #1663 (`tools/x87_lower.py`, `tools/x87_soft.h`, and `tests/cpu/x87_*.py` are untouched). - **Portable 80-bit extended-precision software core (`BigF` 128-bit integer arithmetic)**: lifts straight-line leaf functions (`void lifted_<name>(word rcx, word rdx, word r8)`) with zero host `float`/`double`/`long double`, `<cmath>`, or SSE instructions, avoiding MSVC 64-bit `long double` truncation and guaranteeing complete host MXCSR (`DAZ`/`FTZ`) isolation without clobbering MXCSR. - **Supported x87 instructions and tested domains**: - `F2XM1`: `2^ST(0) - 1` on the Intel SDM domain `[-1, +1]`; exact on `+-0` (`F2XM1(-0.0) == -0.0`), `+1`, `-1`; `<= 1 ULP` vs arbitrary-precision 80-digit `Decimal` reference (observed max `0 ULP`) and `<= 1 ULP` vs native x87 (observed max `1 ULP`). - `FYL2X`: `ST(1) * log2(ST(0))` with stack pop for `x > 0` plus SDM special cases (`#Z (ZE)` on `x == +-0` with finite nonzero `y`, `#IA (IE)` on negative `x`, `(+-0, +-0)`, `(+inf, +-0)`, `(1, +-inf)`). - `FYL2XP1`: `ST(1) * log2(ST(0) + 1)` with stack pop on the Intel SDM domain `[-(1 - sqrt(2)/2), +(1 - sqrt(2)/2)]` (plus lifted-only spec checks for `x == -1` `#Z (ZE)` and `x < -1` `#IA (IE)`, where hardware behavior outside the SDM domain is undefined). - Bounded leaf x87 stack/control/status transport over flat zero-displacement `[rcx|rdx|r8]`: `fld m32/m64/m80`, `fld1`, `fldz`, `fst m32/m64`, `fstp m32/m64/m80/st(0)`, `fnstsw ax` (+ `mov word ptr [r8], ax`), `fldcw m16`, `fnstcw m16`, `fninit`, and terminal `ret`. - **Hardware fidelity**: models FCW rounding modes (`RN/RD/RU/RZ`), FCW precision control (`PC 24/53/64`, preserved across `fldcw`/`fnstcw` and not truncating transcendental results per Intel SDM Vol. 1 8.1.5.2), sNaN quieting + `#IA (IE)`, unnormals -> indefinite + `#IA`, `#DE`/`#OE`/`#UE`/`#PE` status flags, and stack depth/pop semantics. - **Fail-closed rejections**: rejects `FSIN`/`FCOS`/`FSINCOS`/`FPTAN`/`FPATAN`, stack overflow/underflow, non-empty x87 stack at `ret`, XMM/YMM/ZMM/VEX/EVEX, prefixes (including `WAIT`/`9B`), non-flat/displaced/indexed/non-arg memory, stores outside `[r8]`, undefined `ax` reads, branches, missing `ret`, and trailing instructions after `ret`. ## Verification Verified on commit `65489770` (based on `upstream/main` `7092683a`) in both `dev` (Debug) and `release` (`/O2`) presets (baseline x87, 0 skips): - `cmake --build --preset dev --target cpu_x87_exp_log_aot_original cpu_x87_exp_log_aot_original_lifted cpu_x87_exp_log_aot_altered cpu_x87_exp_log_aot_altered_lifted` -> exit 0. - `ctest --preset dev -R "^cpu_aot_x87_exp_log$" -E "cpu_native_archive_" --output-on-failure -V` -> `1/1 Passed (0.32s)`: `6 x87 exp/log sequences accepted; 37 rejection controls passed; 847 differential/FCW/status/special cases matched (max ULP vs Decimal ref=0, vs native x87=1); 36 MXCSR DAZ/FTZ isolation checks passed; 6 mutant controls + 5 altered-build controls caught`. - `cmake --build --preset release --target cpu_x87_exp_log_aot_original cpu_x87_exp_log_aot_original_lifted cpu_x87_exp_log_aot_altered cpu_x87_exp_log_aot_altered_lifted` -> exit 0. - `ctest --preset release -R "^cpu_aot_x87_exp_log$" -E "cpu_native_archive_" --output-on-failure -V` -> `1/1 Passed (0.33s)`: identical `6/37/847 (max ULP ref=0, nat=1)/36/6+5` results. - `FORM_COVERAGE_RECORD` (both `dev` and `release`): 14 recorded forms (`f2xm1,fld,fld1,fldcw,fldz,fninit,fnstcw,fnstsw,fst,fstp,fyl2x,fyl2xp1,mov,ret`). - `out/pe-env/Scripts/python.exe -B tests/form_coverage_check.py` -> `form coverage checks passed` (exit 0). - `out/pe-env/Scripts/python.exe -B tests/docs_links_check.py` -> `Self-test passed. Checked 19 Markdown files and 464 links.` (exit 0). - `out/pe-env/Scripts/python.exe -B tests/bidi_controls_check.py` -> `Self-test passed. Checked 1727 tracked source, script and build/CI files: no bidirectional controls.` (exit 0). - Spot mutation audit on `tools/cpu_x87_exp_log_aot.py`: 8/8 mutations killed across translator guards (`FSIN` trig rejection, non-empty stack at `ret`, store-outside-`r8`, displaced memory) and rebuilt C++ semantics (`F2XM1(-0.0)` sign, `FYL2X` `#Z`, `FYL2XP1` `#Z`, FCW rounding control). ## Evidence and follow-up All fixtures (`tests/cpu/x87_exp_log_aot.asm`, `.def`, `_check.py`) are source-built under the repository MIT license with `; coverage: record cpu_aot_x87_exp_log` and `ALTER_X87_EXP_LOG` altered-build controls; no external binaries or game files are used. Contributors can build and run the test with `ctest --preset dev -R "^cpu_aot_x87_exp_log$" -V` (or `--preset release`). ## Checklist - [x] This pull request covers one reviewable behavior. - [x] I included the exact command and result for every check I ran. - [x] I considered a negative control or failure case for a new fixture. - [x] I updated README/docs when a capability or build requirement changed. - [x] I did not include game files, dumps, distribution links or secrets. AI-assisted.
upstream-sync closed this pull request 2026-11-25 21:00:54 +00:00
tedin7 commented 2026-11-25 21:00:54 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T20:22:03Z.

Review: COMMENTED


Review of head 6bbf4a62 (comment only, no approval).

Checked:

  • Scope: 5 files, new standalone lifter plus MASM fixture and check. Does not touch x87_lower.py, x87_soft.h or tests/cpu/x87_*.py. No other open or merged PR covers F2XM1/FYL2X/FYL2XP1 (searched all states).
  • The new test cpu_aot_x87_exp_log compares the lifted code with native x87 and with a Decimal reference, and also covers MXCSR isolation, FCW rounding, status-word flags and built-in mutants (check_mutants). That guards the new behavior with real values, not string checks.
  • CMake follows the sibling cpu_aot_x87_trig pattern (original and altered variants, exports list).
  • It makes no claim about game startup.

Commands run locally:

  • git diff --check origin/main...HEAD: clean
  • python3 tests/docs_links_check.py: pass
  • python3 tests/bidi_controls_check.py: pass
  • python3 -m py_compile on the lifter and the check: pass
  • gh pr update-branch (head moved to 6bbf4a62; the PR's own diff is unchanged), CI green on the new head
  • Win2025 dev and release: cpu_aot_x87_exp_log passed in both (receipt in the next comment)

Not done: the in-test mutants only run on Windows, so I did not mutate the lifter on Linux.

No blocking findings.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6064408241 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2423#pullrequestreview-6064408241). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T20:22:03Z. **Review:** COMMENTED --- Review of head 6bbf4a62 (comment only, no approval). Checked: - Scope: 5 files, new standalone lifter plus MASM fixture and check. Does not touch `x87_lower.py`, `x87_soft.h` or `tests/cpu/x87_*.py`. No other open or merged PR covers F2XM1/FYL2X/FYL2XP1 (searched all states). - The new test `cpu_aot_x87_exp_log` compares the lifted code with native x87 and with a Decimal reference, and also covers MXCSR isolation, FCW rounding, status-word flags and built-in mutants (`check_mutants`). That guards the new behavior with real values, not string checks. - CMake follows the sibling `cpu_aot_x87_trig` pattern (original and altered variants, exports list). - It makes no claim about game startup. Commands run locally: - `git diff --check origin/main...HEAD`: clean - `python3 tests/docs_links_check.py`: pass - `python3 tests/bidi_controls_check.py`: pass - `python3 -m py_compile` on the lifter and the check: pass - `gh pr update-branch` (head moved to 6bbf4a62; the PR's own diff is unchanged), CI green on the new head - Win2025 dev and release: `cpu_aot_x87_exp_log` passed in both (receipt in the next comment) Not done: the in-test mutants only run on Windows, so I did not mutate the lifter on Linux. No blocking findings. AI-assisted; commands listed were executed locally.
tedin7 commented 2026-11-25 21:01:30 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T20:22:04Z.


Win2025 WARP receipt for head 6bbf4a62 after updating with main.

Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit 6bbf4a6222b3c6d99825c748b2ee2dfc9c34c171:

  • Debug (--preset dev):
    • Build (cmake --build --preset dev --target cpu_x87_exp_log_aot_altered cpu_x87_exp_log_aot_altered_lifted cpu_x87_exp_log_aot_original cpu_x87_exp_log_aot_original_lifted -- -j 2): 4.11s (configure 2.00s)
    • Test (ctest --preset dev -R 'cpu_aot_x87_exp_log' --parallel 6 --no-tests=error --output-on-failure): 1/1 passed (0.59s: cpu_aot_x87_exp_log 0.44s)
  • Release /O2 (--preset release):
    • Build (cmake --build --preset release --target cpu_x87_exp_log_aot_altered cpu_x87_exp_log_aot_altered_lifted cpu_x87_exp_log_aot_original cpu_x87_exp_log_aot_original_lifted -- -j 2): 1.59s (configure 2.66s)
    • Test (ctest --preset release -R 'cpu_aot_x87_exp_log' --parallel 6 --no-tests=error --output-on-failure): 1/1 passed (0.44s: cpu_aot_x87_exp_log 0.34s)
  • sccache: 0/4 hits; wall 19.4s

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7173564679 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2423#issuecomment-7173564679). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T20:22:04Z. --- Win2025 WARP receipt for head 6bbf4a62 after updating with main. Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit `6bbf4a6222b3c6d99825c748b2ee2dfc9c34c171`: - **Debug (`--preset dev`)**: - Build (`cmake --build --preset dev --target cpu_x87_exp_log_aot_altered cpu_x87_exp_log_aot_altered_lifted cpu_x87_exp_log_aot_original cpu_x87_exp_log_aot_original_lifted -- -j 2`): `4.11s` (configure `2.00s`) - Test (`ctest --preset dev -R 'cpu_aot_x87_exp_log' --parallel 6 --no-tests=error --output-on-failure`): **1/1 passed** (`0.59s`: `cpu_aot_x87_exp_log` `0.44s`) - **Release `/O2` (`--preset release`)**: - Build (`cmake --build --preset release --target cpu_x87_exp_log_aot_altered cpu_x87_exp_log_aot_altered_lifted cpu_x87_exp_log_aot_original cpu_x87_exp_log_aot_original_lifted -- -j 2`): `1.59s` (configure `2.66s`) - Test (`ctest --preset release -R 'cpu_aot_x87_exp_log' --parallel 6 --no-tests=error --output-on-failure`): **1/1 passed** (`0.44s`: `cpu_aot_x87_exp_log` `0.34s`) - `sccache`: 0/4 hits; wall `19.4s` AI-assisted; commands listed were executed locally.
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!2415
No description provided.