diff options
| author | Hagb (Junyu Guo 郭俊余) <hagb_green@qq.com> | 2025-01-08 22:34:15 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-01-08 15:34:15 +0100 |
| commit | 653a67c8addcb980ce10a27765e582c972f8d69c (patch) | |
| tree | 98ac1036f34b2810a1f41a6126827445f7774fd4 /src/emu/x87emu_setround.h | |
| parent | b99893d1c3506524103eebc2e4497a8be14cd6d0 (diff) | |
| download | box64-653a67c8addcb980ce10a27765e582c972f8d69c.tar.gz box64-653a67c8addcb980ce10a27765e582c972f8d69c.zip | |
Port rounding of some x87 instructions from Box86 (#2242)
* Port rounding of some x87 instructions from Box86 Ported from https://github.com/ptitSeb/box86/pull/951. The original pull request and this commit also contain some improvements on precision of `F2XM1` and `FYL2XP1`. * Run fpu_rounding test with dynarec only for ARM64 They have been implemented on dynarec only for ARM64.
Diffstat (limited to 'src/emu/x87emu_setround.h')
| -rw-r--r-- | src/emu/x87emu_setround.h | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/emu/x87emu_setround.h b/src/emu/x87emu_setround.h new file mode 100644 index 00000000..4791c3ea --- /dev/null +++ b/src/emu/x87emu_setround.h @@ -0,0 +1,29 @@ +#ifndef __SETROUND_H__ +#define __SETROUND_H__ +#pragma STDC FENV_ACCESS ON +#include <fenv.h> +#include <stdint.h> +#include "x64emu.h" +#include "x64emu_private.h" +// set the rounding mode to the emulator's one, and return the old one +static inline int fpu_setround(x64emu_t* emu) { + int ret = fegetround(); + int rounding_direction; + switch (emu->cw.f.C87_RD) { + case ROUND_Nearest: + rounding_direction = FE_TONEAREST; + break; + case ROUND_Down: + rounding_direction = FE_DOWNWARD; + break; + case ROUND_Up: + rounding_direction = FE_UPWARD; + break; + case ROUND_Chop: + rounding_direction = FE_TOWARDZERO; + break; + } + fesetround(rounding_direction); + return ret; +} +#endif \ No newline at end of file |