mirror of
https://github.com/TheBozos/BozoEngine.git
synced 2026-12-01 07:38:19 -10:00
VU0 programs: round toward zero through MXCSR directly, not std::fegetround / std::fesetround
The C runtime's calls set the x87 control word too (__mingw_setfp, _controlfp): ~2% of the game thread in a 1P match (1,570 programs a frame). The host's float arithmetic is SSE's, so MXCSR's rounding bits alone give the same results. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
24292a623e
commit
70217841b5
1 file changed
+7
-3
@@ -12,6 +12,7 @@
|
||||
#include "bozo/libs/libraries.h"
|
||||
|
||||
#include <cfenv>
|
||||
#include <xmmintrin.h>
|
||||
#include <cmath>
|
||||
#include <cstring>
|
||||
|
||||
@@ -21,11 +22,14 @@ namespace bozo::libs
|
||||
{
|
||||
// ---- VU0 arithmetic --------------------------------------------------------------------------------------
|
||||
|
||||
// The host's float arithmetic is SSE's (x86-64): its rounding control, MXCSR bits 13-14 (11: toward zero), set
|
||||
// directly. std::fesetround did the same plus the x87 control word, through the C runtime's calls: ~2% of the
|
||||
// game thread in a 1P match (a few thousand programs a frame).
|
||||
struct TowardZero
|
||||
{
|
||||
int saved = std::fegetround();
|
||||
TowardZero() { std::fesetround(FE_TOWARDZERO); }
|
||||
~TowardZero() { std::fesetround(saved); }
|
||||
unsigned saved = _mm_getcsr();
|
||||
TowardZero() { _mm_setcsr(saved | 0x6000u); }
|
||||
~TowardZero() { _mm_setcsr(saved); }
|
||||
};
|
||||
|
||||
uint32_t bits(float f)
|
||||
|
||||
Reference in new issue
Block a user