Repository navigation
series: cut FPCR writes at ARM64EC transitions, keep AFP on (0013, 0014) - #12
Open
utkarshdalal wants to merge 2 commits into
Open
utkarshdalal wants to merge 2 commits into
utkarshdalal wants to merge 2 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Two patches that cut the FPCR writes FEX makes on every switch between emulated x86 code and native ARM64EC code (Wine, DXVK). AFP stays on by default where the CPU supports it, and floating-point results don't change.
SERIES_VERSIONgoes to 8.ExitFunctionEC(Source/Windows/ARM64EC/Module.S) cleared FPCR.NEP and AH on every exit to native code with an unconditionalmsr. It now checks first and skips the write when both bits are already clear.Why
On an 8 Elite, an FPCR write that changes a bit costs about 8 ns (2 per round trip). Reading FPCR and branching costs nothing measurable. On the 8 Gen 2 the same writes cost under 2 ns, and NEP/AH are not implemented there.
In A Hat in Time on an AYN Odin 3 (8 Elite), the entry write and the exit write took about 26% of the main thread's cycles.
How 0014 stays correct
UsesHostFPModeproperty, built from IR.json and failing closed:VF*vector op, FP conversions, FP compares (FCmp,Select,Float_ToGPR_*), and the rounding-mode ops, which save and restore the whole FPCR.UsesHostFPModefield in IR.json.fadd,fabs,fcmeq,scvtf/ucvtfandfcvt. It does not changefmov(any form),ins, loads, integer scalar SIMD (add,cmeq,shl,abs,sqadd,sqxtn,addp),fcsel,addv/umaxv,pmullorsha1h.Targetlabel, which every entry passes: dispatcher lookups, block links, call-ret returns (they land on the return block's entry point, beforeTarget), and jumps inside the multiblock.mrs,tbnzon NEP, and only if clearorr+msr. It doesn't touch NZCV.FillStaticRegs, unchanged).SpillStaticRegsskips its FPCR write when NEP, AH and FIZ are already clear. It checks withand+cbz, so NZCV is untouched before it gets saved.FEX_EXP_EAGERAFP=1makes the entry set the bits again, as before.Results (AYN Odin 3, Snapdragon 8 Elite)
Correctness. An x86-64 test program calls a native import (
QueryPerformanceCounter,GetLastError, ...) between FP operations:minss/maxss/minps/maxpswith NaN and ±0, denormals, conversions, comparisons, double and packed ops, and switches MXCSR between FTZ-only and FTZ+DAZ.7556e233fe8b6de37556e233fe8b6de3FEX_EXP_EAGERAFP=17556e233fe8b6de3FEX_HOSTFEATURES=disableafp0ced81a8a5c63803The lazy build matches the current results bit for bit. Disabling AFP changes them, which is why AFP stays on.
A Hat in Time, title screen. 60 fps cap, Proton 11.0-2 arm64ec-6, same FEX 2611-gn-6 base with only the DLL swapped, simpleperf over 15 s:
msr15.3%, exitmsr11.1%msr2.4%, then block guards at ≤1.5% eachThe writes that remain are the necessary ones: FP code on both sides of a native call. The title screen rendered the same in both runs. These are single runs on a warm device (about 90 °C), and cycles are less frequency-sensitive than time, but this is not a gameplay benchmark.
Checks
apply.shon a cleanFEX-2611, and the result is identical to the tree built and tested above.