about summary refs log tree commit diff stats
path: root/src/emu/x87emu_setround.h
blob: 4791c3ea8ec37fcf536a09c991993672593f3805 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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