aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--dyngen-exec.h11
-rw-r--r--target-i386/cpu.h14
-rw-r--r--target-i386/exec.h70
-rw-r--r--target-i386/helper.c78
-rw-r--r--target-i386/op.c49
-rw-r--r--target-i386/ops_sse.h126
-rw-r--r--target-sparc/cpu.h3
-rw-r--r--target-sparc/op_helper.c18
-rw-r--r--vl.c1
9 files changed, 139 insertions, 231 deletions
diff --git a/dyngen-exec.h b/dyngen-exec.h
index d8ecc02ffb..9b39f59b56 100644
--- a/dyngen-exec.h
+++ b/dyngen-exec.h
@@ -62,17 +62,6 @@ extern int fprintf(FILE *, const char *, ...);
extern int printf(const char *, ...);
#undef NULL
#define NULL 0
-#if defined(_BSD) && !defined(__APPLE__)
-#include <ieeefp.h>
-
-#define FE_TONEAREST FP_RN
-#define FE_DOWNWARD FP_RM
-#define FE_UPWARD FP_RP
-#define FE_TOWARDZERO FP_RZ
-#define fesetround(x) fpsetround(x)
-#else
-#include <fenv.h>
-#endif
#ifdef __i386__
#define AREG0 "ebp"
diff --git a/target-i386/cpu.h b/target-i386/cpu.h
index 154d8bfdae..ce65c34306 100644
--- a/target-i386/cpu.h
+++ b/target-i386/cpu.h
@@ -36,6 +36,8 @@
#include "cpu-defs.h"
+#include "softfloat.h"
+
#if defined(__i386__) && !defined(CONFIG_SOFTMMU)
#define USE_CODE_COPY
#endif
@@ -332,14 +334,14 @@ enum {
CC_OP_NB,
};
-#if (defined(__i386__) || defined(__x86_64__)) && !defined(_BSD)
+#ifdef FLOATX80
#define USE_X86LDOUBLE
#endif
#ifdef USE_X86LDOUBLE
-typedef long double CPU86_LDouble;
+typedef floatx80 CPU86_LDouble;
#else
-typedef double CPU86_LDouble;
+typedef float64 CPU86_LDouble;
#endif
typedef struct SegmentCache {
@@ -354,8 +356,8 @@ typedef union {
uint16_t _w[8];
uint32_t _l[4];
uint64_t _q[2];
- float _s[4];
- double _d[2];
+ float32 _s[4];
+ float64 _d[2];
} XMMReg;
typedef union {
@@ -441,6 +443,7 @@ typedef struct CPUX86State {
} fpregs[8];
/* emulator internal variables */
+ float_status fp_status;
CPU86_LDouble ft0;
union {
float f;
@@ -449,6 +452,7 @@ typedef struct CPUX86State {
int64_t i64;
} fp_convert;
+ float_status sse_status;
uint32_t mxcsr;
XMMReg xmm_regs[CPU_NB_REGS];
XMMReg xmm_t0;
diff --git a/target-i386/exec.h b/target-i386/exec.h
index c4e59c4235..137774f5a3 100644
--- a/target-i386/exec.h
+++ b/target-i386/exec.h
@@ -139,44 +139,6 @@ extern int loglevel;
#include "cpu.h"
#include "exec-all.h"
-/* XXX: add a generic FPU library */
-
-static inline double float32_to_float64(float a)
-{
- return a;
-}
-
-static inline float float64_to_float32(double a)
-{
- return a;
-}
-
-#if defined(__powerpc__)
-/* better to call an helper on ppc */
-float int32_to_float32(int32_t a);
-double int32_to_float64(int32_t a);
-#else
-static inline float int32_to_float32(int32_t a)
-{
- return (float)a;
-}
-
-static inline double int32_to_float64(int32_t a)
-{
- return (double)a;
-}
-#endif
-
-static inline float int64_to_float32(int64_t a)
-{
- return (float)a;
-}
-
-static inline double int64_to_float64(int64_t a)
-{
- return (double)a;
-}
-
typedef struct CCTable {
int (*compute_all)(void); /* return all the flags */
int (*compute_c)(void); /* return the C flag */
@@ -358,9 +320,11 @@ static inline void stfl(target_ulong ptr, float v)
#ifdef USE_X86LDOUBLE
/* use long double functions */
-#define lrint lrintl
-#define llrint llrintl
-#define fabs fabsl
+#define floatx_to_int32 floatx80_to_int32
+#define floatx_to_int64 floatx80_to_int64
+#define floatx_abs floatx80_abs
+#define floatx_chs floatx80_chs
+#define floatx_round_to_int floatx80_round_to_int
#define sin sinl
#define cos cosl
#define sqrt sqrtl
@@ -370,17 +334,14 @@ static inline void stfl(target_ulong ptr, float v)
#define atan2 atan2l
#define floor floorl
#define ceil ceill
-#define rint rintl
-#endif
-
-#if !defined(_BSD)
-extern int lrint(CPU86_LDouble x);
-extern int64_t llrint(CPU86_LDouble x);
#else
-#define lrint(d) ((int)rint(d))
-#define llrint(d) ((int)rint(d))
+#define floatx_to_int32 float64_to_int32
+#define floatx_to_int64 float64_to_int64
+#define floatx_abs float64_abs
+#define floatx_chs float64_chs
+#define floatx_round_to_int float64_round_to_int
#endif
-extern CPU86_LDouble fabs(CPU86_LDouble x);
+
extern CPU86_LDouble sin(CPU86_LDouble x);
extern CPU86_LDouble cos(CPU86_LDouble x);
extern CPU86_LDouble sqrt(CPU86_LDouble x);
@@ -390,7 +351,6 @@ extern CPU86_LDouble tan(CPU86_LDouble x);
extern CPU86_LDouble atan2(CPU86_LDouble, CPU86_LDouble);
extern CPU86_LDouble floor(CPU86_LDouble x);
extern CPU86_LDouble ceil(CPU86_LDouble x);
-extern CPU86_LDouble rint(CPU86_LDouble x);
#define RC_MASK 0xc00
#define RC_NEAR 0x000
@@ -400,13 +360,6 @@ extern CPU86_LDouble rint(CPU86_LDouble x);
#define MAXTAN 9223372036854775808.0
-#ifdef __arm__
-/* we have no way to do correct rounding - a FPU emulator is needed */
-#define FE_DOWNWARD FE_TONEAREST
-#define FE_UPWARD FE_TONEAREST
-#define FE_TOWARDZERO FE_TONEAREST
-#endif
-
#ifdef USE_X86LDOUBLE
/* only for x86 */
@@ -596,6 +549,7 @@ float approx_rsqrt(float a);
float approx_rcp(float a);
double helper_sqrt(double a);
int fpu_isnan(double a);
+void update_fp_status(void);
extern const uint8_t parity_table[256];
extern const uint8_t rclw_table[32];
diff --git a/target-i386/helper.c b/target-i386/helper.c
index 53b85d3aaa..64cb51ab53 100644
--- a/target-i386/helper.c
+++ b/target-i386/helper.c
@@ -2541,13 +2541,11 @@ void helper_fbld_ST0_A0(void)
void helper_fbst_ST0_A0(void)
{
- CPU86_LDouble tmp;
int v;
target_ulong mem_ref, mem_end;
int64_t val;
- tmp = rint(ST0);
- val = (int64_t)tmp;
+ val = floatx_to_int64(ST0, &env->fp_status);
mem_ref = A0;
mem_end = mem_ref + 9;
if (val < 0) {
@@ -2740,29 +2738,7 @@ void helper_fsincos(void)
void helper_frndint(void)
{
- CPU86_LDouble a;
-
- a = ST0;
-#ifdef __arm__
- switch(env->fpuc & RC_MASK) {
- default:
- case RC_NEAR:
- asm("rndd %0, %1" : "=f" (a) : "f"(a));
- break;
- case RC_DOWN:
- asm("rnddm %0, %1" : "=f" (a) : "f"(a));
- break;
- case RC_UP:
- asm("rnddp %0, %1" : "=f" (a) : "f"(a));
- break;
- case RC_CHOP:
- asm("rnddz %0, %1" : "=f" (a) : "f"(a));
- break;
- }
-#else
- a = rint(a);
-#endif
- ST0 = a;
+ ST0 = floatx_round_to_int(ST0, &env->fp_status);
}
void helper_fscale(void)
@@ -3263,25 +3239,43 @@ float approx_rcp(float a)
return 1.0 / a;
}
-/* XXX: find a better solution */
-double helper_sqrt(double a)
+void update_fp_status(void)
{
- return sqrt(a);
-}
+ int rnd_type;
-/* XXX: move that to another file */
-#if defined(__powerpc__)
-/* better to call an helper on ppc */
-float int32_to_float32(int32_t a)
-{
- return (float)a;
-}
-
-double int32_to_float64(int32_t a)
-{
- return (double)a;
-}
+ /* set rounding mode */
+ switch(env->fpuc & RC_MASK) {
+ default:
+ case RC_NEAR:
+ rnd_type = float_round_nearest_even;
+ break;
+ case RC_DOWN:
+ rnd_type = float_round_down;
+ break;
+ case RC_UP:
+ rnd_type = float_round_up;
+ break;
+ case RC_CHOP:
+ rnd_type = float_round_to_zero;
+ break;
+ }
+ set_float_rounding_mode(rnd_type, &env->fp_status);
+#ifdef FLOATX80
+ switch((env->fpuc >> 8) & 3) {
+ case 0:
+ rnd_type = 32;
+ break;
+ case 2:
+ rnd_type = 64;
+ break;
+ case 3:
+ default:
+ rnd_type = 80;
+ break;
+ }
+ set_floatx80_rounding_precision(rnd_type, &env->fp_status);
#endif
+}
#if !defined(CONFIG_USER_ONLY)
diff --git a/target-i386/op.c b/target-i386/op.c
index dc0dceadfd..bbc2b19aed 100644
--- a/target-i386/op.c
+++ b/target-i386/op.c
@@ -1598,26 +1598,6 @@ CCTable cc_table[CC_OP_NB] = {
functions comes from the LGPL'ed x86 emulator found in the Willows
TWIN windows emulator. */
-#if defined(__powerpc__)
-extern CPU86_LDouble copysign(CPU86_LDouble, CPU86_LDouble);
-
-/* correct (but slow) PowerPC rint() (glibc version is incorrect) */
-double qemu_rint(double x)
-{
- double y = 4503599627370496.0;
- if (fabs(x) >= y)
- return x;
- if (x < 0)
- y = -y;
- y = (x + y) - y;
- if (y == 0.0)
- y = copysign(y, x);
- return y;
-}
-
-#define rint qemu_rint
-#endif
-
/* fp load FT0 */
void OPPROTO op_flds_FT0_A0(void)
@@ -1866,7 +1846,7 @@ void OPPROTO op_fist_ST0_A0(void)
int val;
d = ST0;
- val = lrint(d);
+ val = floatx_to_int32(d, &env->fp_status);
if (val != (int16_t)val)
val = -32768;
stw(A0, val);
@@ -1883,7 +1863,7 @@ void OPPROTO op_fistl_ST0_A0(void)
int val;
d = ST0;
- val = lrint(d);
+ val = floatx_to_int32(d, &env->fp_status);
stl(A0, val);
FORCE_RET();
}
@@ -1898,7 +1878,7 @@ void OPPROTO op_fistll_ST0_A0(void)
int64_t val;
d = ST0;
- val = llrint(d);
+ val = floatx_to_int64(d, &env->fp_status);
stq(A0, val);
FORCE_RET();
}
@@ -2101,12 +2081,12 @@ void OPPROTO op_fdivr_STN_ST0(void)
/* misc FPU operations */
void OPPROTO op_fchs_ST0(void)
{
- ST0 = -ST0;
+ ST0 = floatx_chs(ST0);
}
void OPPROTO op_fabs_ST0(void)
{
- ST0 = fabs(ST0);
+ ST0 = floatx_abs(ST0);
}
void OPPROTO op_fxam_ST0(void)
@@ -2251,25 +2231,8 @@ void OPPROTO op_fnstcw_A0(void)
void OPPROTO op_fldcw_A0(void)
{
- int rnd_type;
env->fpuc = lduw(A0);
- /* set rounding mode */
- switch(env->fpuc & RC_MASK) {
- default:
- case RC_NEAR:
- rnd_type = FE_TONEAREST;
- break;
- case RC_DOWN:
- rnd_type = FE_DOWNWARD;
- break;
- case RC_UP:
- rnd_type = FE_UPWARD;
- break;
- case RC_CHOP:
- rnd_type = FE_TOWARDZERO;
- break;
- }
- fesetround(rnd_type);
+ update_fp_status();
}
void OPPROTO op_fclex(void)
diff --git a/target-i386/ops_sse.h b/target-i386/ops_sse.h
index 8472a34d35..be1d68bfb7 100644
--- a/target-i386/ops_sse.h
+++ b/target-i386/ops_sse.h
@@ -654,10 +654,10 @@ void OPPROTO op_ ## name ## ps (void)\
Reg *d, *s;\
d = (Reg *)((char *)env + PARAM1);\
s = (Reg *)((char *)env + PARAM2);\
- d->XMM_S(0) = F(d->XMM_S(0), s->XMM_S(0));\
- d->XMM_S(1) = F(d->XMM_S(1), s->XMM_S(1));\
- d->XMM_S(2) = F(d->XMM_S(2), s->XMM_S(2));\
- d->XMM_S(3) = F(d->XMM_S(3), s->XMM_S(3));\
+ d->XMM_S(0) = F(32, d->XMM_S(0), s->XMM_S(0));\
+ d->XMM_S(1) = F(32, d->XMM_S(1), s->XMM_S(1));\
+ d->XMM_S(2) = F(32, d->XMM_S(2), s->XMM_S(2));\
+ d->XMM_S(3) = F(32, d->XMM_S(3), s->XMM_S(3));\
}\
\
void OPPROTO op_ ## name ## ss (void)\
@@ -665,15 +665,15 @@ void OPPROTO op_ ## name ## ss (void)\
Reg *d, *s;\
d = (Reg *)((char *)env + PARAM1);\
s = (Reg *)((char *)env + PARAM2);\
- d->XMM_S(0) = F(d->XMM_S(0), s->XMM_S(0));\
+ d->XMM_S(0) = F(32, d->XMM_S(0), s->XMM_S(0));\
}\
void OPPROTO op_ ## name ## pd (void)\
{\
Reg *d, *s;\
d = (Reg *)((char *)env + PARAM1);\
s = (Reg *)((char *)env + PARAM2);\
- d->XMM_D(0) = F(d->XMM_D(0), s->XMM_D(0));\
- d->XMM_D(1) = F(d->XMM_D(1), s->XMM_D(1));\
+ d->XMM_D(0) = F(64, d->XMM_D(0), s->XMM_D(0));\
+ d->XMM_D(1) = F(64, d->XMM_D(1), s->XMM_D(1));\
}\
\
void OPPROTO op_ ## name ## sd (void)\
@@ -681,16 +681,16 @@ void OPPROTO op_ ## name ## sd (void)\
Reg *d, *s;\
d = (Reg *)((char *)env + PARAM1);\
s = (Reg *)((char *)env + PARAM2);\
- d->XMM_D(0) = F(d->XMM_D(0), s->XMM_D(0));\
+ d->XMM_D(0) = F(64, d->XMM_D(0), s->XMM_D(0));\
}
-#define FPU_ADD(a, b) (a) + (b)
-#define FPU_SUB(a, b) (a) - (b)
-#define FPU_MUL(a, b) (a) * (b)
-#define FPU_DIV(a, b) (a) / (b)
-#define FPU_MIN(a, b) (a) < (b) ? (a) : (b)
-#define FPU_MAX(a, b) (a) > (b) ? (a) : (b)
-#define FPU_SQRT(a, b) helper_sqrt(b)
+#define FPU_ADD(size, a, b) float ## size ## _add(a, b, &env->sse_status)
+#define FPU_SUB(size, a, b) float ## size ## _sub(a, b, &env->sse_status)
+#define FPU_MUL(size, a, b) float ## size ## _mul(a, b, &env->sse_status)
+#define FPU_DIV(size, a, b) float ## size ## _div(a, b, &env->sse_status)
+#define FPU_MIN(size, a, b) (a) < (b) ? (a) : (b)
+#define FPU_MAX(size, a, b) (a) > (b) ? (a) : (b)
+#define FPU_SQRT(size, a, b) float ## size ## _sqrt(b, &env->sse_status)
SSE_OP_S(add, FPU_ADD)
SSE_OP_S(sub, FPU_SUB)
@@ -710,8 +710,8 @@ void OPPROTO op_cvtps2pd(void)
s = (Reg *)((char *)env + PARAM2);
s0 = s->XMM_S(0);
s1 = s->XMM_S(1);
- d->XMM_D(0) = float32_to_float64(s0);
- d->XMM_D(1) = float32_to_float64(s1);
+ d->XMM_D(0) = float32_to_float64(s0, &env->sse_status);
+ d->XMM_D(1) = float32_to_float64(s1, &env->sse_status);
}
void OPPROTO op_cvtpd2ps(void)
@@ -719,8 +719,8 @@ void OPPROTO op_cvtpd2ps(void)
Reg *d, *s;
d = (Reg *)((char *)env + PARAM1);
s = (Reg *)((char *)env + PARAM2);
- d->XMM_S(0) = float64_to_float32(s->XMM_D(0));
- d->XMM_S(1) = float64_to_float32(s->XMM_D(1));
+ d->XMM_S(0) = float64_to_float32(s->XMM_D(0), &env->sse_status);
+ d->XMM_S(1) = float64_to_float32(s->XMM_D(1), &env->sse_status);
d->Q(1) = 0;
}
@@ -729,7 +729,7 @@ void OPPROTO op_cvtss2sd(void)
Reg *d, *s;
d = (Reg *)((char *)env + PARAM1);
s = (Reg *)((char *)env + PARAM2);
- d->XMM_D(0) = float32_to_float64(s->XMM_S(0));
+ d->XMM_D(0) = float32_to_float64(s->XMM_S(0), &env->sse_status);
}
void OPPROTO op_cvtsd2ss(void)
@@ -737,7 +737,7 @@ void OPPROTO op_cvtsd2ss(void)
Reg *d, *s;
d = (Reg *)((char *)env + PARAM1);
s = (Reg *)((char *)env + PARAM2);
- d->XMM_S(0) = float64_to_float32(s->XMM_D(0));
+ d->XMM_S(0) = float64_to_float32(s->XMM_D(0), &env->sse_status);
}
/* integer to float */
@@ -745,10 +745,10 @@ void OPPROTO op_cvtdq2ps(void)
{
XMMReg *d = (XMMReg *)((char *)env + PARAM1);
XMMReg *s = (XMMReg *)((char *)env + PARAM2);
- d->XMM_S(0) = int32_to_float32(s->XMM_L(0));
- d->XMM_S(1) = int32_to_float32(s->XMM_L(1));
- d->XMM_S(2) = int32_to_float32(s->XMM_L(2));
- d->XMM_S(3) = int32_to_float32(s->XMM_L(3));
+ d->XMM_S(0) = int32_to_float32(s->XMM_L(0), &env->sse_status);
+ d->XMM_S(1) = int32_to_float32(s->XMM_L(1), &env->sse_status);
+ d->XMM_S(2) = int32_to_float32(s->XMM_L(2), &env->sse_status);
+ d->XMM_S(3) = int32_to_float32(s->XMM_L(3), &env->sse_status);
}
void OPPROTO op_cvtdq2pd(void)
@@ -758,49 +758,49 @@ void OPPROTO op_cvtdq2pd(void)
int32_t l0, l1;
l0 = (int32_t)s->XMM_L(0);
l1 = (int32_t)s->XMM_L(1);
- d->XMM_D(0) = int32_to_float64(l0);
- d->XMM_D(1) = int32_to_float64(l1);
+ d->XMM_D(0) = int32_to_float64(l0, &env->sse_status);
+ d->XMM_D(1) = int32_to_float64(l1, &env->sse_status);
}
void OPPROTO op_cvtpi2ps(void)
{
XMMReg *d = (Reg *)((char *)env + PARAM1);
MMXReg *s = (MMXReg *)((char *)env + PARAM2);
- d->XMM_S(0) = int32_to_float32(s->MMX_L(0));
- d->XMM_S(1) = int32_to_float32(s->MMX_L(1));
+ d->XMM_S(0) = int32_to_float32(s->MMX_L(0), &env->sse_status);
+ d->XMM_S(1) = int32_to_float32(s->MMX_L(1), &env->sse_status);
}
void OPPROTO op_cvtpi2pd(void)
{
XMMReg *d = (Reg *)((char *)env + PARAM1);
MMXReg *s = (MMXReg *)((char *)env + PARAM2);
- d->XMM_D(0) = int32_to_float64(s->MMX_L(0));
- d->XMM_D(1) = int32_to_float64(s->MMX_L(1));
+ d->XMM_D(0) = int32_to_float64(s->MMX_L(0), &env->sse_status);
+ d->XMM_D(1) = int32_to_float64(s->MMX_L(1), &env->sse_status);
}
void OPPROTO op_cvtsi2ss(void)
{
XMMReg *d = (Reg *)((char *)env + PARAM1);
- d->XMM_S(0) = int32_to_float32(T0);
+ d->XMM_S(0) = int32_to_float32(T0, &env->sse_status);
}
void OPPROTO op_cvtsi2sd(void)
{
XMMReg *d = (Reg *)((char *)env + PARAM1);
- d->XMM_D(0) = int32_to_float64(T0);
+ d->XMM_D(0) = int32_to_float64(T0, &env->sse_status);
}
#ifdef TARGET_X86_64
void OPPROTO op_cvtsq2ss(void)
{
XMMReg *d = (Reg *)((char *)env + PARAM1);
- d->XMM_S(0) = int64_to_float32(T0);
+ d->XMM_S(0) = int64_to_float32(T0, &env->sse_status);
}
void OPPROTO op_cvtsq2sd(void)
{
XMMReg *d = (Reg *)((char *)env + PARAM1);
- d->XMM_D(0) = int64_to_float64(T0);
+ d->XMM_D(0) = int64_to_float64(T0, &env->sse_status);
}
#endif
@@ -809,18 +809,18 @@ void OPPROTO op_cvtps2dq(void)
{
XMMReg *d = (XMMReg *)((char *)env + PARAM1);
XMMReg *s = (XMMReg *)((char *)env + PARAM2);
- d->XMM_L(0) = lrint(s->XMM_S(0));
- d->XMM_L(1) = lrint(s->XMM_S(1));
- d->XMM_L(2) = lrint(s->XMM_S(2));
- d->XMM_L(3) = lrint(s->XMM_S(3));
+ d->XMM_L(0) = float32_to_int32(s->XMM_S(0), &env->sse_status);
+ d->XMM_L(1) = float32_to_int32(s->XMM_S(1), &env->sse_status);
+ d->XMM_L(2) = float32_to_int32(s->XMM_S(2), &env->sse_status);
+ d->XMM_L(3) = float32_to_int32(s->XMM_S(3), &env->sse_status);
}
void OPPROTO op_cvtpd2dq(void)
{
XMMReg *d = (XMMReg *)((char *)env + PARAM1);
XMMReg *s = (XMMReg *)((char *)env + PARAM2);
- d->XMM_L(0) = lrint(s->XMM_D(0));
- d->XMM_L(1) = lrint(s->XMM_D(1));
+ d->XMM_L(0) = float64_to_int32(s->XMM_D(0), &env->sse_status);
+ d->XMM_L(1) = float64_to_int32(s->XMM_D(1), &env->sse_status);
d->XMM_Q(1) = 0;
}
@@ -828,41 +828,41 @@ void OPPROTO op_cvtps2pi(void)
{
MMXReg *d = (MMXReg *)((char *)env + PARAM1);
XMMReg *s = (XMMReg *)((char *)env + PARAM2);
- d->MMX_L(0) = lrint(s->XMM_S(0));
- d->MMX_L(1) = lrint(s->XMM_S(1));
+ d->MMX_L(0) = float32_to_int32(s->XMM_S(0), &env->sse_status);
+ d->MMX_L(1) = float32_to_int32(s->XMM_S(1), &env->sse_status);
}
void OPPROTO op_cvtpd2pi(void)
{
MMXReg *d = (MMXReg *)((char *)env + PARAM1);
XMMReg *s = (XMMReg *)((char *)env + PARAM2);
- d->MMX_L(0) = lrint(s->XMM_D(0));
- d->MMX_L(1) = lrint(s->XMM_D(1));
+ d->MMX_L(0) = float64_to_int32(s->XMM_D(0), &env->sse_status);
+ d->MMX_L(1) = float64_to_int32(s->XMM_D(1), &env->sse_status);
}
void OPPROTO op_cvtss2si(void)
{
XMMReg *s = (XMMReg *)((char *)env + PARAM1);
- T0 = (int32_t)lrint(s->XMM_S(0));
+ T0 = float32_to_int32(s->XMM_S(0), &env->sse_status);
}
void OPPROTO op_cvtsd2si(void)
{
XMMReg *s = (XMMReg *)((char *)env + PARAM1);
- T0 = (int32_t)lrint(s->XMM_D(0));
+ T0 = float64_to_int32(s->XMM_D(0), &env->sse_status);
}
#ifdef TARGET_X86_64
void OPPROTO op_cvtss2sq(void)
{
XMMReg *s = (XMMReg *)((char *)env + PARAM1);
- T0 = llrint(s->XMM_S(0));
+ T0 = float32_to_int64(s->XMM_S(0), &env->sse_status);
}
void OPPROTO op_cvtsd2sq(void)
{
XMMReg *s = (XMMReg *)((char *)env + PARAM1);
- T0 = llrint(s->XMM_D(0));
+ T0 = float64_to_int64(s->XMM_D(0), &env->sse_status);
}
#endif
@@ -871,18 +871,18 @@ void OPPROTO op_cvttps2dq(void)
{
XMMReg *d = (XMMReg *)((char *)env + PARAM1);
XMMReg *s = (XMMReg *)((char *)env + PARAM2);
- d->XMM_L(0) = (int32_t)s->XMM_S(0);
- d->XMM_L(1) = (int32_t)s->XMM_S(1);
- d->XMM_L(2) = (int32_t)s->XMM_S(2);
- d->XMM_L(3) = (int32_t)s->XMM_S(3);
+ d->XMM_L(0) = float32_to_int32_round_to_zero(s->XMM_S(0), &env->sse_status);
+ d->XMM_L(1) = float32_to_int32_round_to_zero(s->XMM_S(1), &env->sse_status);
+ d->XMM_L(2) = float32_to_int32_round_to_zero(s->XMM_S(2), &env->sse_status);
+ d->XMM_L(3) = float32_to_int32_round_to_zero(s->XMM_S(3), &env->sse_status);
}
void OPPROTO op_cvttpd2dq(void)
{
XMMReg *d = (XMMReg *)((char *)env + PARAM1);
XMMReg *s = (XMMReg *)((char *)env + PARAM2);
- d->XMM_L(0) = (int32_t)s->XMM_D(0);
- d->XMM_L(1) = (int32_t)s->XMM_D(1);
+ d->XMM_L(0) = float64_to_int32_round_to_zero(s->XMM_D(0), &env->sse_status);
+ d->XMM_L(1) = float64_to_int32_round_to_zero(s->XMM_D(1), &env->sse_status);
d->XMM_Q(1) = 0;
}
@@ -890,41 +890,41 @@ void OPPROTO op_cvttps2pi(void)
{
MMXReg *d = (MMXReg *)((char *)env + PARAM1);
XMMReg *s = (XMMReg *)((char *)env + PARAM2);
- d->MMX_L(0) = (int32_t)(s->XMM_S(0));
- d->MMX_L(1) = (int32_t)(s->XMM_S(1));
+ d->MMX_L(0) = float32_to_int32_round_to_zero(s->XMM_S(0), &env->sse_status);
+ d->MMX_L(1) = float32_to_int32_round_to_zero(s->XMM_S(1), &env->sse_status);
}
void OPPROTO op_cvttpd2pi(void)
{
MMXReg *d = (MMXReg *)((char *)env + PARAM1);
XMMReg *s = (XMMReg *)((char *)env + PARAM2);
- d->MMX_L(0) = (int32_t)(s->XMM_D(0));
- d->MMX_L(1) = (int32_t)(s->XMM_D(1));
+ d->MMX_L(0) = float64_to_int32_round_to_zero(s->XMM_D(0), &env->sse_status);
+ d->MMX_L(1) = float64_to_int32_round_to_zero(s->XMM_D(1), &env->sse_status);
}
void OPPROTO op_cvttss2si(void)
{
XMMReg *s = (XMMReg *)((char *)env + PARAM1);
- T0 = (int32_t)(s->XMM_S(0));
+ T0 = float32_to_int32_round_to_zero(s->XMM_S(0), &env->sse_status);
}
void OPPROTO op_cvttsd2si(void)
{
XMMReg *s = (XMMReg *)((char *)env + PARAM1);
- T0 = (int32_t)(s->XMM_D(0));
+ T0 = float64_to_int32_round_to_zero(s->XMM_D(0), &env->sse_status);
}
#ifdef TARGET_X86_64
void OPPROTO op_cvttss2sq(void)
{
XMMReg *s = (XMMReg *)((char *)env + PARAM1);
- T0 = (int64_t)(s->XMM_S(0));
+ T0 = float32_to_int64_round_to_zero(s->XMM_S(0), &env->sse_status);
}
void OPPROTO op_cvttsd2sq(void)
{
XMMReg *s = (XMMReg *)((char *)env + PARAM1);
- T0 = (int64_t)(s->XMM_D(0));
+ T0 = float64_to_int64_round_to_zero(s->XMM_D(0), &env->sse_status);
}
#endif
diff --git a/target-sparc/cpu.h b/target-sparc/cpu.h
index b07e2afcf4..67a6e3e465 100644
--- a/target-sparc/cpu.h
+++ b/target-sparc/cpu.h
@@ -15,6 +15,8 @@
#include "cpu-defs.h"
+#include "softfloat.h"
+
/*#define EXCP_INTERRUPT 0x100*/
/* trap definitions */
@@ -150,6 +152,7 @@ typedef struct CPUSPARCState {
/* temporary float registers */
float ft0, ft1, ft2;
double dt0, dt1, dt2;
+ float_status fp_status;
#if defined(TARGET_SPARC64)
target_ulong t0, t1, t2;
#endif
diff --git a/target-sparc/op_helper.c b/target-sparc/op_helper.c
index 9cb3de49ac..40ab90156e 100644
--- a/target-sparc/op_helper.c
+++ b/target-sparc/op_helper.c
@@ -1,5 +1,3 @@
-#include <math.h>
-#include <fenv.h>
#include "exec.h"
//#define DEBUG_MMU
@@ -24,17 +22,17 @@ void do_fitod(void)
void do_fabss(void)
{
- FT0 = fabsf(FT1);
+ FT0 = float32_abs(FT1);
}
void do_fsqrts(void)
{
- FT0 = sqrtf(FT1);
+ FT0 = float32_sqrt(FT1, &env->fp_status);
}
void do_fsqrtd(void)
{
- DT0 = sqrt(DT1);
+ DT0 = float64_sqrt(DT1, &env->fp_status);
}
void do_fcmps (void)
@@ -252,20 +250,22 @@ void helper_rett()
void helper_ldfsr(void)
{
+ int rnd_mode;
switch (env->fsr & FSR_RD_MASK) {
case FSR_RD_NEAREST:
- fesetround(FE_TONEAREST);
+ rnd_mode = float_round_nearest_even;
break;
case FSR_RD_ZERO:
- fesetround(FE_TOWARDZERO);
+ rnd_mode = float_round_to_zero;
break;
case FSR_RD_POS:
- fesetround(FE_UPWARD);
+ rnd_mode = float_round_up;
break;
case FSR_RD_NEG:
- fesetround(FE_DOWNWARD);
+ rnd_mode = float_round_down;
break;
}
+ set_float_rounding_mode(rnd_mode, &env->fp_status);
}
void cpu_get_fp64(uint64_t *pmant, uint16_t *pexp, double f)
diff --git a/vl.c b/vl.c
index a815a50fa8..9f8b8a6b99 100644
--- a/vl.c
+++ b/vl.c
@@ -2271,6 +2271,7 @@ int cpu_load(QEMUFile *f, void *opaque, int version_id)
}
env->fpuc = fpuc;
+ /* XXX: restore FPU round state */
env->fpstt = (fpus >> 11) & 7;
env->fpus = fpus & ~0x3800;
fptag ^= 0xff;