Skip to content

[INTERP] Honor MXCSR rounding mode in SSE/AVX operations - #4408

Open
yzewei wants to merge 1 commit into
ptitSeb:mainfrom
yzewei:fix-interp-mxcsr-rounding
Open

yzewei wants to merge 1 commit into
ptitSeb:mainfrom
yzewei:fix-interp-mxcsr-rounding

Conversation

@yzewei

@yzewei yzewei commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

The interpreter implements many SSE and AVX instructions using host floating-point operations without synchronizing with the guest's MXCSR.RC. mxcsr_setround() has been added to save the host rounding mode and temporarily apply the rounding mode selected by the guest's MXCSR (similar to x87_setround()). Regression tests for the interpreter have also been added, covering all four MXCSR rounding modes and a representative set of scalar, packed, conversion, AVX, and FMA instructions.

@ptitSeb ptitSeb left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really like the coding style (with the break inside the braces of the case...

@ptitSeb
ptitSeb requested a review from ksco September 17, 2026 08:17
@yzewei

yzewei commented Sep 17, 2026

Copy link
Copy Markdown
Contributor Author

I don't really like the coding style (with the break inside the braces of the case...

I can modify it.= . =

The interpreter implements a number of SSE and AVX instructions using
host floating-point operations, but did not apply the guest MXCSR.RC
before performing them. As a result, directed rounding modes could
produce results using the host's previous rounding mode.

Add mxcsr_setround() to save the host rounding mode and temporarily
apply the rounding mode selected by the guest MXCSR. Use it around the
affected SSE and AVX arithmetic, horizontal, dot-product, conversion,
and FMA interpreter paths, restoring the original host mode afterward.

Add an interpreter regression test covering all four MXCSR rounding
modes and representative scalar, packed, conversion, AVX, and FMA
instructions. Force the test through the interpreter so that a dynarec
path cannot hide interpreter rounding errors.

Signed-off-by: Zewei Yang <yangzewei@loongson.cn>
@yzewei
yzewei force-pushed the fix-interp-mxcsr-rounding branch from 9fa54db to 947238a Compare September 17, 2026 08:22
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.

2 participants