about summary refs log tree commit diff stats
path: root/src/emu/x87emu_setround.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/emu/x87emu_setround.h')
-rw-r--r--src/emu/x87emu_setround.h29
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