Skip to content

X86 FPU fixes - #792

Draft
mrexodia wants to merge 14 commits into
lifting-bits:masterfrom
LLVMParty:bo2-x86-fpu-fixes
Draft

mrexodia wants to merge 14 commits into
lifting-bits:masterfrom
LLVMParty:bo2-x86-fpu-fixes

Conversation

@mrexodia

@mrexodia mrexodia commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Based on work in: https://github.com/adrbn/bo2-mac

A few patches were taken as-is, the rest based on X87/MMX instructions used in the game executables. Note that this breaks the “ABI” regarding intrinsics used and exception/rounding mode state, but it’s necessary to be able to use X87 correctly for this recompilation project.

For future reference: https://github.com/mrexodia/agent-scratch/tree/claude/trusting-hopper-mkoj3i this is a liberally-licensed software implementation of X87 I used for testing in another project.

adrbn and others added 14 commits November 13, 2026 15:56
XED produces POPA_16 for the 16-bit operand form. POPA_32 did not match
that form; POPAD_32 remains separate.
Match both destination operands emitted by the decoder and retain the
upper lanes from the old destination for register and memory sources.
Set bit 6 and clear bits 7 and 13-15. Native regressions are in patch 0009.
Use explicit ties-to-even for RC=00. Update C1 by magnitude and accumulate
precision/invalid flags. Check signed conversion bounds before FP-to-int casts
to avoid LLVM poison, retain FISTTP truncation, and use an exclusive BCD bound.
This does not implement unmasked exception delivery or all unsupported encodings.
FLDCW preserves the guest PC field. FNSTCW and STMXCSR store guest control
state without replacing it with the host environment. Arithmetic precision
emulation and MXCSR reserved-bit exceptions remain separate issues.
Select x87 RC or MXCSR RC and restore the caller mode. Compile semantics
with constrained floating-point operations. Native regressions are in 0009.
Reset abridged tags and TOP. Rotate the logical x87 view while retaining the
physical MMX view. Intel native FXSAVE/EMMS/FXSAVE probes confirm TOP reset and
physical data preservation; do not fake an undefined-f80 aggregate ABI.
Use the existing assembly suite and runner for controls, rounding, POPA,
CVTPI2PS and EMMS. Add opt-in raw-register, status and tag checks.
Preserve sticky IE and inspect both operands with the ext80 SNaN classifier.
Cover all ten register comparison forms in the native assembly suite.
Comparison C1 remains excluded from these regressions.
LLVM 17/18 reject inlining strict-FP semantics into non-strict lifted functions. This leaves internal calls behind and makes the installed lifter abort when moving the trace to its output module.
Keep real CALL/RET opcodes in the lifted input. Use four-byte stack operations in the long-mode reference, with equal sequence extents so return-PC offsets match. Preserve the full-stack comparison.
@CLAassistant

CLAassistant commented Nov 14, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@mrexodia
mrexodia marked this pull request as draft November 20, 2026 10:52
@mrexodia

Copy link
Copy Markdown
Contributor Author

Converted to draft because it has performance implications that need further investigation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants