summaryrefslogtreecommitdiffstats
path: root/src/core/arm/skyeye_common/vfp
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/arm/skyeye_common/vfp')
-rw-r--r--src/core/arm/skyeye_common/vfp/vfp_helper.h4
-rw-r--r--src/core/arm/skyeye_common/vfp/vfpdouble.cpp42
-rw-r--r--src/core/arm/skyeye_common/vfp/vfpsingle.cpp57
3 files changed, 42 insertions, 61 deletions
diff --git a/src/core/arm/skyeye_common/vfp/vfp_helper.h b/src/core/arm/skyeye_common/vfp/vfp_helper.h
index 5e14345ce..1eba71b48 100644
--- a/src/core/arm/skyeye_common/vfp/vfp_helper.h
+++ b/src/core/arm/skyeye_common/vfp/vfp_helper.h
@@ -291,7 +291,7 @@ inline s32 vfp_single_pack(const vfp_single* s) {
return (s32)val;
}
-u32 vfp_single_normaliseround(ARMul_State* state, int sd, vfp_single* vs, u32 fpscr,
+u32 vfp_single_normaliseround(ARMul_State* state, int sd, vfp_single* vs, u32 fpscr, u32 exceptions,
const char* func);
// Double-precision
@@ -429,5 +429,5 @@ inline u32 fls(u32 x) {
u32 vfp_double_multiply(vfp_double* vdd, vfp_double* vdn, vfp_double* vdm, u32 fpscr);
u32 vfp_double_add(vfp_double* vdd, vfp_double* vdn, vfp_double* vdm, u32 fpscr);
-u32 vfp_double_normaliseround(ARMul_State* state, int dd, vfp_double* vd, u32 fpscr,
+u32 vfp_double_normaliseround(ARMul_State* state, int dd, vfp_double* vd, u32 fpscr, u32 exceptions,
const char* func);
diff --git a/src/core/arm/skyeye_common/vfp/vfpdouble.cpp b/src/core/arm/skyeye_common/vfp/vfpdouble.cpp
index e51927de5..735cf1a09 100644
--- a/src/core/arm/skyeye_common/vfp/vfpdouble.cpp
+++ b/src/core/arm/skyeye_common/vfp/vfpdouble.cpp
@@ -82,11 +82,10 @@ static void vfp_double_normalise_denormal(struct vfp_double* vd) {
}
u32 vfp_double_normaliseround(ARMul_State* state, int dd, struct vfp_double* vd, u32 fpscr,
- const char* func) {
+ u32 exceptions, const char* func) {
u64 significand, incr;
int exponent, shift, underflow;
u32 rmode;
- u32 exceptions = 0;
vfp_double_dump("pack: in", vd);
@@ -373,7 +372,8 @@ static u32 vfp_double_fsqrt(ARMul_State* state, int dd, int unused, int dm, u32
}
vdd.significand = vfp_shiftright64jamming(vdd.significand, 1);
- exceptions |= vfp_double_normaliseround(state, dd, &vdd, fpscr, "fsqrt");
+ exceptions |= vfp_double_normaliseround(state, dd, &vdd, fpscr, 0, "fsqrt");
+
return exceptions;
}
@@ -505,8 +505,7 @@ static u32 vfp_double_fcvts(ARMul_State* state, int sd, int unused, int dm, u32
else
vsd.exponent = vdm.exponent - (1023 - 127);
- exceptions |= vfp_single_normaliseround(state, sd, &vsd, fpscr, "fcvts");
- return exceptions;
+ return vfp_single_normaliseround(state, sd, &vsd, fpscr, exceptions, "fcvts");
pack_nan:
vfp_put_float(state, vfp_single_pack(&vsd), sd);
@@ -515,7 +514,6 @@ pack_nan:
static u32 vfp_double_fuito(ARMul_State* state, int dd, int unused, int dm, u32 fpscr) {
struct vfp_double vdm;
- u32 exceptions = 0;
u32 m = vfp_get_float(state, dm);
LOG_TRACE(Core_ARM11, "In %s", __FUNCTION__);
@@ -523,13 +521,11 @@ static u32 vfp_double_fuito(ARMul_State* state, int dd, int unused, int dm, u32
vdm.exponent = 1023 + 63 - 1;
vdm.significand = (u64)m;
- exceptions |= vfp_double_normaliseround(state, dd, &vdm, fpscr, "fuito");
- return exceptions;
+ return vfp_double_normaliseround(state, dd, &vdm, fpscr, 0, "fuito");
}
static u32 vfp_double_fsito(ARMul_State* state, int dd, int unused, int dm, u32 fpscr) {
struct vfp_double vdm;
- u32 exceptions = 0;
u32 m = vfp_get_float(state, dm);
LOG_TRACE(Core_ARM11, "In %s", __FUNCTION__);
@@ -537,8 +533,7 @@ static u32 vfp_double_fsito(ARMul_State* state, int dd, int unused, int dm, u32
vdm.exponent = 1023 + 63 - 1;
vdm.significand = vdm.sign ? (~m + 1) : m;
- exceptions |= vfp_double_normaliseround(state, dd, &vdm, fpscr, "fsito");
- return exceptions;
+ return vfp_double_normaliseround(state, dd, &vdm, fpscr, 0, "fsito");
}
static u32 vfp_double_ftoui(ARMul_State* state, int sd, int unused, int dm, u32 fpscr) {
@@ -925,8 +920,7 @@ static u32 vfp_double_multiply_accumulate(ARMul_State* state, int dd, int dn, in
exceptions |= vfp_double_add(&vdd, &vdn, &vdp, fpscr);
- exceptions |= vfp_double_normaliseround(state, dd, &vdd, fpscr, func);
- return exceptions;
+ return vfp_double_normaliseround(state, dd, &vdd, fpscr, exceptions, func);
}
/*
@@ -983,9 +977,7 @@ static u32 vfp_double_fmul(ARMul_State* state, int dd, int dn, int dm, u32 fpscr
vfp_double_normalise_denormal(&vdm);
exceptions |= vfp_double_multiply(&vdd, &vdn, &vdm, fpscr);
-
- exceptions |= vfp_double_normaliseround(state, dd, &vdd, fpscr, "fmul");
- return exceptions;
+ return vfp_double_normaliseround(state, dd, &vdd, fpscr, exceptions, "fmul");
}
/*
@@ -1007,8 +999,7 @@ static u32 vfp_double_fnmul(ARMul_State* state, int dd, int dn, int dm, u32 fpsc
exceptions |= vfp_double_multiply(&vdd, &vdn, &vdm, fpscr);
vdd.sign = vfp_sign_negate(vdd.sign);
- exceptions |= vfp_double_normaliseround(state, dd, &vdd, fpscr, "fnmul");
- return exceptions;
+ return vfp_double_normaliseround(state, dd, &vdd, fpscr, exceptions, "fnmul");
}
/*
@@ -1029,8 +1020,7 @@ static u32 vfp_double_fadd(ARMul_State* state, int dd, int dn, int dm, u32 fpscr
exceptions |= vfp_double_add(&vdd, &vdn, &vdm, fpscr);
- exceptions |= vfp_double_normaliseround(state, dd, &vdd, fpscr, "fadd");
- return exceptions;
+ return vfp_double_normaliseround(state, dd, &vdd, fpscr, exceptions, "fadd");
}
/*
@@ -1056,8 +1046,7 @@ static u32 vfp_double_fsub(ARMul_State* state, int dd, int dn, int dm, u32 fpscr
exceptions |= vfp_double_add(&vdd, &vdn, &vdm, fpscr);
- exceptions |= vfp_double_normaliseround(state, dd, &vdd, fpscr, "fsub");
- return exceptions;
+ return vfp_double_normaliseround(state, dd, &vdd, fpscr, exceptions, "fsub");
}
/*
@@ -1139,9 +1128,7 @@ static u32 vfp_double_fdiv(ARMul_State* state, int dd, int dn, int dm, u32 fpscr
}
vdd.significand |= (reml != 0);
}
-
- exceptions |= vfp_double_normaliseround(state, dd, &vdd, fpscr, "fdiv");
- return exceptions;
+ return vfp_double_normaliseround(state, dd, &vdd, fpscr, 0, "fdiv");
vdn_nan:
exceptions |= vfp_propagate_nan(&vdd, &vdn, &vdm, fpscr);
@@ -1167,8 +1154,7 @@ infinity:
invalid:
vfp_put_double(state, vfp_double_pack(&vfp_double_default_qnan), dd);
- exceptions |= FPSCR_IOC;
- return exceptions;
+ return FPSCR_IOC;
}
static struct op fops[] = {
@@ -1243,7 +1229,7 @@ u32 vfp_double_cpdo(ARMul_State* state, u32 inst, u32 fpscr) {
except = fop->fn(state, dest, dn, dm, fpscr);
LOG_TRACE(Core_ARM11, "VFP: itr%d: exceptions=%08x", vecitr >> FPSCR_LENGTH_BIT, except);
- exceptions |= except;
+ exceptions |= except & ~VFP_NAN_FLAG;
/*
* CHECK: It appears to be undefined whether we stop when
diff --git a/src/core/arm/skyeye_common/vfp/vfpsingle.cpp b/src/core/arm/skyeye_common/vfp/vfpsingle.cpp
index 99ab80145..1f9142abc 100644
--- a/src/core/arm/skyeye_common/vfp/vfpsingle.cpp
+++ b/src/core/arm/skyeye_common/vfp/vfpsingle.cpp
@@ -83,10 +83,9 @@ static void vfp_single_normalise_denormal(struct vfp_single* vs) {
}
u32 vfp_single_normaliseround(ARMul_State* state, int sd, struct vfp_single* vs, u32 fpscr,
- const char* func) {
+ u32 exceptions, const char* func) {
u32 significand, incr, rmode;
int exponent, shift, underflow;
- u32 exceptions = 0;
vfp_single_dump("pack: in", vs);
@@ -407,7 +406,8 @@ static u32 vfp_single_fsqrt(ARMul_State* state, int sd, int unused, s32 m, u32 f
}
vsd.significand = vfp_shiftright32jamming(vsd.significand, 1);
- exceptions |= vfp_single_normaliseround(state, sd, &vsd, fpscr, "fsqrt");
+ exceptions |= vfp_single_normaliseround(state, sd, &vsd, fpscr, 0, "fsqrt");
+
return exceptions;
}
@@ -528,8 +528,7 @@ static u32 vfp_single_fcvtd(ARMul_State* state, int dd, int unused, s32 m, u32 f
else
vdd.exponent = vsm.exponent + (1023 - 127);
- exceptions |= vfp_double_normaliseround(state, dd, &vdd, fpscr, "fcvtd");
- return exceptions;
+ return vfp_double_normaliseround(state, dd, &vdd, fpscr, exceptions, "fcvtd");
pack_nan:
vfp_put_double(state, vfp_double_pack(&vdd), dd);
@@ -538,26 +537,22 @@ pack_nan:
static u32 vfp_single_fuito(ARMul_State* state, int sd, int unused, s32 m, u32 fpscr) {
struct vfp_single vs;
- u32 exceptions = 0;
vs.sign = 0;
vs.exponent = 127 + 31 - 1;
vs.significand = (u32)m;
- exceptions |= vfp_single_normaliseround(state, sd, &vs, fpscr, "fuito");
- return exceptions;
+ return vfp_single_normaliseround(state, sd, &vs, fpscr, 0, "fuito");
}
static u32 vfp_single_fsito(ARMul_State* state, int sd, int unused, s32 m, u32 fpscr) {
struct vfp_single vs;
- u32 exceptions = 0;
vs.sign = (m & 0x80000000) >> 16;
vs.exponent = 127 + 31 - 1;
vs.significand = vs.sign ? -m : m;
- exceptions |= vfp_single_normaliseround(state, sd, &vs, fpscr, "fsito");
- return exceptions;
+ return vfp_single_normaliseround(state, sd, &vs, fpscr, 0, "fsito");
}
static u32 vfp_single_ftoui(ARMul_State* state, int sd, int unused, s32 m, u32 fpscr) {
@@ -949,8 +944,7 @@ static u32 vfp_single_multiply_accumulate(ARMul_State* state, int sd, int sn, s3
exceptions |= vfp_single_add(&vsd, &vsn, &vsp, fpscr);
- exceptions |= vfp_single_normaliseround(state, sd, &vsd, fpscr, func);
- return exceptions;
+ return vfp_single_normaliseround(state, sd, &vsd, fpscr, exceptions, func);
}
/*
@@ -961,10 +955,8 @@ static u32 vfp_single_multiply_accumulate(ARMul_State* state, int sd, int sn, s3
* sd = sd + (sn * sm)
*/
static u32 vfp_single_fmac(ARMul_State* state, int sd, int sn, s32 m, u32 fpscr) {
- u32 exceptions = 0;
LOG_TRACE(Core_ARM11, "s%u = %08x", sn, sd);
- exceptions |= vfp_single_multiply_accumulate(state, sd, sn, m, fpscr, 0, "fmac");
- return exceptions;
+ return vfp_single_multiply_accumulate(state, sd, sn, m, fpscr, 0, "fmac");
}
/*
@@ -1012,9 +1004,7 @@ static u32 vfp_single_fmul(ARMul_State* state, int sd, int sn, s32 m, u32 fpscr)
vfp_single_normalise_denormal(&vsm);
exceptions |= vfp_single_multiply(&vsd, &vsn, &vsm, fpscr);
-
- exceptions |= vfp_single_normaliseround(state, sd, &vsd, fpscr, "fmul");
- return exceptions;
+ return vfp_single_normaliseround(state, sd, &vsd, fpscr, exceptions, "fmul");
}
/*
@@ -1037,9 +1027,7 @@ static u32 vfp_single_fnmul(ARMul_State* state, int sd, int sn, s32 m, u32 fpscr
exceptions |= vfp_single_multiply(&vsd, &vsn, &vsm, fpscr);
vsd.sign = vfp_sign_negate(vsd.sign);
-
- exceptions |= vfp_single_normaliseround(state, sd, &vsd, fpscr, "fnmul");
- return exceptions;
+ return vfp_single_normaliseround(state, sd, &vsd, fpscr, exceptions, "fnmul");
}
/*
@@ -1065,8 +1053,7 @@ static u32 vfp_single_fadd(ARMul_State* state, int sd, int sn, s32 m, u32 fpscr)
exceptions |= vfp_single_add(&vsd, &vsn, &vsm, fpscr);
- exceptions |= vfp_single_normaliseround(state, sd, &vsd, fpscr, "fadd");
- return exceptions;
+ return vfp_single_normaliseround(state, sd, &vsd, fpscr, exceptions, "fadd");
}
/*
@@ -1075,12 +1062,22 @@ static u32 vfp_single_fadd(ARMul_State* state, int sd, int sn, s32 m, u32 fpscr)
static u32 vfp_single_fsub(ARMul_State* state, int sd, int sn, s32 m, u32 fpscr) {
LOG_TRACE(Core_ARM11, "s%u = %08x", sn, sd);
/*
- * Subtraction is addition with one sign inverted.
+ * Subtraction is addition with one sign inverted. Unpack the second operand to perform FTZ if
+ * necessary, we can't let fadd do this because a denormal in m might get flushed to +0 in FTZ
+ * mode, and the resulting sign of 0 OP +0 differs between fadd and fsub. We do not need to do
+ * this for n because +0 OP 0 is always +0 for both fadd and fsub.
*/
+ struct vfp_single vsm;
+ u32 exceptions = vfp_single_unpack(&vsm, m, fpscr);
+ if (exceptions & FPSCR_IDC) {
+ // The value was flushed to zero, re-pack it.
+ m = vfp_single_pack(&vsm);
+ }
+
if (m != 0x7FC00000) // Only negate if m isn't NaN.
m = vfp_single_packed_negate(m);
- return vfp_single_fadd(state, sd, sn, m, fpscr);
+ return vfp_single_fadd(state, sd, sn, m, fpscr) | exceptions;
}
/*
@@ -1161,8 +1158,7 @@ static u32 vfp_single_fdiv(ARMul_State* state, int sd, int sn, s32 m, u32 fpscr)
if ((vsd.significand & 0x3f) == 0)
vsd.significand |= ((u64)vsm.significand * vsd.significand != (u64)vsn.significand << 32);
- exceptions |= vfp_single_normaliseround(state, sd, &vsd, fpscr, "fdiv");
- return exceptions;
+ return vfp_single_normaliseround(state, sd, &vsd, fpscr, 0, "fdiv");
vsn_nan:
exceptions |= vfp_propagate_nan(&vsd, &vsn, &vsm, fpscr);
@@ -1188,8 +1184,7 @@ infinity:
invalid:
vfp_put_float(state, vfp_single_pack(&vfp_single_default_qnan), sd);
- exceptions |= FPSCR_IOC;
- return exceptions;
+ return FPSCR_IOC;
}
static struct op fops[] = {
@@ -1259,7 +1254,7 @@ u32 vfp_single_cpdo(ARMul_State* state, u32 inst, u32 fpscr) {
except = fop->fn(state, dest, sn, m, fpscr);
LOG_TRACE(Core_ARM11, "itr%d: exceptions=%08x", vecitr >> FPSCR_LENGTH_BIT, except);
- exceptions |= except;
+ exceptions |= except & ~VFP_NAN_FLAG;
/*
* CHECK: It appears to be undefined whether we stop when