cpu: lower FPREM and FPREM1 in the checked x87 entry #886
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/893"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from R0Y00/Xbox2Windows. Originally posted by denn0x on 2026-11-23T16:17:00Z.
Refs #406
Adds
fpremandfprem1to the checked x87 entry, following the scope proposed in this #406 comment and thefldcwprecedent. The fixed profile still rejects both instructions.Behavior
st(0) - q * st(1). q is the quotient of the magnitudes, truncated byfpremand rounded to nearest-even byfprem1. C0, C3 and C1 become bits 2, 1 and 0 of q, and C2 becomes 0. Neither instruction reads the control word. The helper isx87_premintools/x87_soft.h.fpremandfprem1, until the next x87 instruction. It stays unknown afterfxamand every other instruction, as #627 set it.reject(status)for both:fnstsw, because the status bits after it are not given. Withoutfnstswthe NaN value is kept.fprem; fnstsw ax; sahf; jp backis accepted. In an accepted run C2 is always 0, so the back edge is translated but never taken.This branch was rebased onto #627. That PR covered
ftst,ficomandfxambefore my stacked branches for those opened, so this branch does not include them.Measurements
Commit
bcc1068onca0cc0e. AMD Ryzen 7 7700 (AMD64 Family 25 Model 97 Stepping 2), Windows 11 build 26300, MSVC x64,devpreset.Fractionmodel in the checked translation. The check covers the status, the output block and its guards, and*result.nopartial4104,nonan5225,d63431,truncate13374,tieup867,halfnear472,qswap5498 andzerosign1211.fpremandfprem1in the fixed profile;fpremwith one value;fprem1on an empty stack;test ah, 80h(the busy bit) afterfprem;faddbetweenfpremandfnstsw; a push inside the fmod loop; and a return with the status word in AX. It translates 4:test ah, 02h(C1) afterfprem1;sahf; je(C3) afterfprem; the fmod loop; andfpremwithoutfnstsw.Wider checks on the same commit:
ctest --preset dev --no-tests=error -R '^cpu_aot_x87': 20/20 pass.ctest --preset dev --no-tests=error -j 8): 442 passed, 19 capability skips and 4 failures out of 465.offscreen_checkandpixel_aot, which this change does not touch:dxr_opacity_hardware,gpu_alias_lookup_writes_hardwareandpixel_aot_comparisons_hardware. They failed the same way in a full run without this change at1e8c6a6.dxr_opacity_hardwareis the result already recorded for this adapter.bvh_differential_warp, failed under-j 8. It passed 3 of 3 times when run alone on this branch, and also passes alone onca0cc0e.ca0cc0e: the 318cpu_*.cppfiles generated from fixtures that exist onmainwere compared. 177 are byte-identical. 139 differ only in the embeddedx87_soft.htext, which gainsx87_prem, and in theaot_source_sha256line. The remaining 2,cpu_exe_image_selectorandcpu_image_data_lifted, embed hashes of natively built images, which vary with the build directory.form_coverage_check,docs_links_checkandbidi_controls_checkpass.docs/experiments.mdrecords the fixture and the two new checked-entry statuses.Two observations on this processor are not modelled, and the checked entry rejects both cases. A partial step leaves an exponent difference of 32 + (D mod 32) and clears C0, C1 and C3. After a NaN result, C0 and C3 keep their previous values and C1 and C2 are cleared. Intel measurements from the probe in the #406 comment would show whether a follow-up can model them.
AI-assisted (Claude Code).
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-23T16:27:01Z.
Independent Intel result at
bcc1068(GenuineIntel Family 6 Model 183 Stepping 1, Windows x64, MSVC 19.51). Debug and Release each passed thecpu_aot_x87_fpremcheck. The 35,698 comparable native cases matched the model, with C2 set in the 2,119 single-step partial cases. All eight mutations were detected. This run covers the checked profile and does not identify the native partial-reduction remainder or the unspecified NaN status bits.