LATX, fix: Synchronize SSE FCSR state in softfpu modes - #469
Conversation
f1fd052 to
5da720a
Compare
|
感谢修复! 我建议再评估一下是否有必要让这套完整的 x87/SSE FCSR owner/dirty 状态机默认作用于所有 hard-float 应用,fcsr 指令开销大,会影响性能。 这个问题在 因此建议先验证下面的矩阵:
把现有 131 个 regression case 在这些模式下分别跑一遍。 如果
这样可以避免为了少数要求严格 FP exception semantics 的应用,让所有 hard-float 浮点程序在每个 FP TB 上承担额外的 owner check / FCSR restore / state store 成本。 对于 如果最终证明 softfpu 模式能够以明显更低成本满足 NumPy/SciPy 等应用的需求,我建议优先把它作为 per-application correctness mode,而不是直接让当前完整状态机默认影响所有应用。 |
好的 我来测试一下,之前提出这个方案考虑的主要是如何在不开启SOFTFPU的情况下解决此类问题,如果SOFTFPU=1的效果比较好 可以基于SOFTFPU=1的情况去尝试轻量的完成问题的解决 |
In strict softfpu paths, x87 exceptions are maintained by SoftFloat while SSE and AVX operations still use the native FCSR. Pending native flags and the rounding mode can therefore diverge from env->mxcsr across TB, helper, save, restore, and signal boundaries. Add TB-local SSE rounding-mode preparation and merge native exception flags into MXCSR before architectural state observers. Clear or invalidate pending FCSR state after LDMXCSR and restore paths, synchronize signal frames, and preserve the host floating-point environment around x87 libm helpers. This lightweight path covers SOFTFPU=1 and SOFTFPU=2 with native x87 FAST paths disabled, without adding an x87/SSE owner state machine to hard-float execution. Signed-off-by: Zewei Yang <yangzewei@loongson.cn>
Add freestanding x86_64 guest tests for SSE and x87 exception isolation, rounding-mode restoration, CVT and CVTT status, x87 pop semantics, architectural save and restore instructions, and signal-frame MXCSR handling. Register the five suites with the existing LoongArch LAT integration framework. AVX and XSAVE cases are enabled automatically for builds that provide the corresponding translator support, while LATX_SOFTFPU remains overridable so the same tests can validate SOFTFPU=1 and SOFTFPU=2 with FAST disabled. Signed-off-by: Zewei Yang <yangzewei@loongson.cn>
5da720a to
0773977
Compare
While running the official test suite for a Python numerical computing library in the LAT environment, I discovered that when SoftFPU is enabled, native LoongArch FCSR exception flags generated by SSE/AVX instructions are not always reflected in the guest's MXCSR state. This can lead to inconsistencies or errors regarding exception flags or rounding modes across floating-point operations, architectural state observations, state restoration instructions, and signal frames.
Under the strict SoftFPU execution mode, x87 exceptions are maintained by SoftFloat in
env->fpus, while SSE/AVX operations continue to use the native FCSR:env->mxcsrprior to executing STMXCSR, FXSAVE, XSAVE, and signal frame state observations;This implementation targets the following configurations:
LATX_SOFTFPU=1;LATX_SOFTFPU=2withLATX_SOFTFPU_FAST=0.When native x87 fast paths are enabled, x87 and SSE/AVX operations once again share the native FCSR and require full cross-domain synchronization; the current fix is incompatible with this state.
New tests cover exception isolation, rounding modes, CVT/CVTT behavior, x87 stack pop semantics, FXSAVE/XSAVE restoration paths, and signal/ucontext state handling. With appropriate build environment support, AVX- and XSAVE-related test cases are automatically enabled.