1
0
Fork 0

Merge pull request #2696 from Subv/vfp_revert

Dyncom/VFP: Revert edf30d8 and fix the FPSCR getting invalid values.
This commit is contained in:
Yuri Kunde Schlesner 2017-05-08 21:38:45 -07:00 committed by GitHub
commit 13dd0b88de
3 changed files with 30 additions and 59 deletions

View File

@ -291,7 +291,7 @@ inline s32 vfp_single_pack(const vfp_single* s) {
return (s32)val; 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); const char* func);
// Double-precision // 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_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_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); const char* func);

View File

@ -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, 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; u64 significand, incr;
int exponent, shift, underflow; int exponent, shift, underflow;
u32 rmode; u32 rmode;
u32 exceptions = 0;
vfp_double_dump("pack: in", vd); vfp_double_dump("pack: in", vd);
@ -360,7 +359,8 @@ static u32 vfp_double_fsqrt(ARMul_State* state, int dd, int unused, int dm, u32
} }
vdd.significand = vfp_shiftright64jamming(vdd.significand, 1); 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; return exceptions;
} }
@ -492,8 +492,7 @@ static u32 vfp_double_fcvts(ARMul_State* state, int sd, int unused, int dm, u32
else else
vsd.exponent = vdm.exponent - (1023 - 127); vsd.exponent = vdm.exponent - (1023 - 127);
exceptions |= vfp_single_normaliseround(state, sd, &vsd, fpscr, "fcvts"); return vfp_single_normaliseround(state, sd, &vsd, fpscr, exceptions, "fcvts");
return exceptions;
pack_nan: pack_nan:
vfp_put_float(state, vfp_single_pack(&vsd), sd); vfp_put_float(state, vfp_single_pack(&vsd), sd);
@ -502,7 +501,6 @@ pack_nan:
static u32 vfp_double_fuito(ARMul_State* state, int dd, int unused, int dm, u32 fpscr) { static u32 vfp_double_fuito(ARMul_State* state, int dd, int unused, int dm, u32 fpscr) {
struct vfp_double vdm; struct vfp_double vdm;
u32 exceptions = 0;
u32 m = vfp_get_float(state, dm); u32 m = vfp_get_float(state, dm);
LOG_TRACE(Core_ARM11, "In %s", __FUNCTION__); LOG_TRACE(Core_ARM11, "In %s", __FUNCTION__);
@ -510,13 +508,11 @@ static u32 vfp_double_fuito(ARMul_State* state, int dd, int unused, int dm, u32
vdm.exponent = 1023 + 63 - 1; vdm.exponent = 1023 + 63 - 1;
vdm.significand = (u64)m; vdm.significand = (u64)m;
exceptions |= vfp_double_normaliseround(state, dd, &vdm, fpscr, "fuito"); return vfp_double_normaliseround(state, dd, &vdm, fpscr, 0, "fuito");
return exceptions;
} }
static u32 vfp_double_fsito(ARMul_State* state, int dd, int unused, int dm, u32 fpscr) { static u32 vfp_double_fsito(ARMul_State* state, int dd, int unused, int dm, u32 fpscr) {
struct vfp_double vdm; struct vfp_double vdm;
u32 exceptions = 0;
u32 m = vfp_get_float(state, dm); u32 m = vfp_get_float(state, dm);
LOG_TRACE(Core_ARM11, "In %s", __FUNCTION__); LOG_TRACE(Core_ARM11, "In %s", __FUNCTION__);
@ -524,8 +520,7 @@ static u32 vfp_double_fsito(ARMul_State* state, int dd, int unused, int dm, u32
vdm.exponent = 1023 + 63 - 1; vdm.exponent = 1023 + 63 - 1;
vdm.significand = vdm.sign ? (~m + 1) : m; vdm.significand = vdm.sign ? (~m + 1) : m;
exceptions |= vfp_double_normaliseround(state, dd, &vdm, fpscr, "fsito"); return vfp_double_normaliseround(state, dd, &vdm, fpscr, 0, "fsito");
return exceptions;
} }
static u32 vfp_double_ftoui(ARMul_State* state, int sd, int unused, int dm, u32 fpscr) { static u32 vfp_double_ftoui(ARMul_State* state, int sd, int unused, int dm, u32 fpscr) {
@ -912,8 +907,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_add(&vdd, &vdn, &vdp, fpscr);
exceptions |= vfp_double_normaliseround(state, dd, &vdd, fpscr, func); return vfp_double_normaliseround(state, dd, &vdd, fpscr, exceptions, func);
return exceptions;
} }
/* /*
@ -970,9 +964,7 @@ static u32 vfp_double_fmul(ARMul_State* state, int dd, int dn, int dm, u32 fpscr
vfp_double_normalise_denormal(&vdm); vfp_double_normalise_denormal(&vdm);
exceptions |= vfp_double_multiply(&vdd, &vdn, &vdm, fpscr); exceptions |= vfp_double_multiply(&vdd, &vdn, &vdm, fpscr);
return vfp_double_normaliseround(state, dd, &vdd, fpscr, exceptions, "fmul");
exceptions |= vfp_double_normaliseround(state, dd, &vdd, fpscr, "fmul");
return exceptions;
} }
/* /*
@ -994,8 +986,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); exceptions |= vfp_double_multiply(&vdd, &vdn, &vdm, fpscr);
vdd.sign = vfp_sign_negate(vdd.sign); vdd.sign = vfp_sign_negate(vdd.sign);
exceptions |= vfp_double_normaliseround(state, dd, &vdd, fpscr, "fnmul"); return vfp_double_normaliseround(state, dd, &vdd, fpscr, exceptions, "fnmul");
return exceptions;
} }
/* /*
@ -1016,8 +1007,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_add(&vdd, &vdn, &vdm, fpscr);
exceptions |= vfp_double_normaliseround(state, dd, &vdd, fpscr, "fadd"); return vfp_double_normaliseround(state, dd, &vdd, fpscr, exceptions, "fadd");
return exceptions;
} }
/* /*
@ -1043,8 +1033,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_add(&vdd, &vdn, &vdm, fpscr);
exceptions |= vfp_double_normaliseround(state, dd, &vdd, fpscr, "fsub"); return vfp_double_normaliseround(state, dd, &vdd, fpscr, exceptions, "fsub");
return exceptions;
} }
/* /*
@ -1126,9 +1115,7 @@ static u32 vfp_double_fdiv(ARMul_State* state, int dd, int dn, int dm, u32 fpscr
} }
vdd.significand |= (reml != 0); vdd.significand |= (reml != 0);
} }
return vfp_double_normaliseround(state, dd, &vdd, fpscr, 0, "fdiv");
exceptions |= vfp_double_normaliseround(state, dd, &vdd, fpscr, "fdiv");
return exceptions;
vdn_nan: vdn_nan:
exceptions |= vfp_propagate_nan(&vdd, &vdn, &vdm, fpscr); exceptions |= vfp_propagate_nan(&vdd, &vdn, &vdm, fpscr);
@ -1154,8 +1141,7 @@ infinity:
invalid: invalid:
vfp_put_double(state, vfp_double_pack(&vfp_double_default_qnan), dd); vfp_put_double(state, vfp_double_pack(&vfp_double_default_qnan), dd);
exceptions |= FPSCR_IOC; return FPSCR_IOC;
return exceptions;
} }
static struct op fops[] = { static struct op fops[] = {
@ -1230,7 +1216,7 @@ u32 vfp_double_cpdo(ARMul_State* state, u32 inst, u32 fpscr) {
except = fop->fn(state, dest, dn, dm, fpscr); except = fop->fn(state, dest, dn, dm, fpscr);
LOG_TRACE(Core_ARM11, "VFP: itr%d: exceptions=%08x", vecitr >> FPSCR_LENGTH_BIT, except); 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 * CHECK: It appears to be undefined whether we stop when

View File

@ -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, 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; u32 significand, incr, rmode;
int exponent, shift, underflow; int exponent, shift, underflow;
u32 exceptions = 0;
vfp_single_dump("pack: in", vs); vfp_single_dump("pack: in", vs);
@ -394,7 +393,8 @@ static u32 vfp_single_fsqrt(ARMul_State* state, int sd, int unused, s32 m, u32 f
} }
vsd.significand = vfp_shiftright32jamming(vsd.significand, 1); 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; return exceptions;
} }
@ -515,8 +515,7 @@ static u32 vfp_single_fcvtd(ARMul_State* state, int dd, int unused, s32 m, u32 f
else else
vdd.exponent = vsm.exponent + (1023 - 127); vdd.exponent = vsm.exponent + (1023 - 127);
exceptions |= vfp_double_normaliseround(state, dd, &vdd, fpscr, "fcvtd"); return vfp_double_normaliseround(state, dd, &vdd, fpscr, exceptions, "fcvtd");
return exceptions;
pack_nan: pack_nan:
vfp_put_double(state, vfp_double_pack(&vdd), dd); vfp_put_double(state, vfp_double_pack(&vdd), dd);
@ -525,26 +524,22 @@ pack_nan:
static u32 vfp_single_fuito(ARMul_State* state, int sd, int unused, s32 m, u32 fpscr) { static u32 vfp_single_fuito(ARMul_State* state, int sd, int unused, s32 m, u32 fpscr) {
struct vfp_single vs; struct vfp_single vs;
u32 exceptions = 0;
vs.sign = 0; vs.sign = 0;
vs.exponent = 127 + 31 - 1; vs.exponent = 127 + 31 - 1;
vs.significand = (u32)m; vs.significand = (u32)m;
exceptions |= vfp_single_normaliseround(state, sd, &vs, fpscr, "fuito"); return vfp_single_normaliseround(state, sd, &vs, fpscr, 0, "fuito");
return exceptions;
} }
static u32 vfp_single_fsito(ARMul_State* state, int sd, int unused, s32 m, u32 fpscr) { static u32 vfp_single_fsito(ARMul_State* state, int sd, int unused, s32 m, u32 fpscr) {
struct vfp_single vs; struct vfp_single vs;
u32 exceptions = 0;
vs.sign = (m & 0x80000000) >> 16; vs.sign = (m & 0x80000000) >> 16;
vs.exponent = 127 + 31 - 1; vs.exponent = 127 + 31 - 1;
vs.significand = vs.sign ? -m : m; vs.significand = vs.sign ? -m : m;
exceptions |= vfp_single_normaliseround(state, sd, &vs, fpscr, "fsito"); return vfp_single_normaliseround(state, sd, &vs, fpscr, 0, "fsito");
return exceptions;
} }
static u32 vfp_single_ftoui(ARMul_State* state, int sd, int unused, s32 m, u32 fpscr) { static u32 vfp_single_ftoui(ARMul_State* state, int sd, int unused, s32 m, u32 fpscr) {
@ -936,8 +931,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_add(&vsd, &vsn, &vsp, fpscr);
exceptions |= vfp_single_normaliseround(state, sd, &vsd, fpscr, func); return vfp_single_normaliseround(state, sd, &vsd, fpscr, exceptions, func);
return exceptions;
} }
/* /*
@ -948,10 +942,8 @@ static u32 vfp_single_multiply_accumulate(ARMul_State* state, int sd, int sn, s3
* sd = sd + (sn * sm) * sd = sd + (sn * sm)
*/ */
static u32 vfp_single_fmac(ARMul_State* state, int sd, int sn, s32 m, u32 fpscr) { 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); LOG_TRACE(Core_ARM11, "s%u = %08x", sn, sd);
exceptions |= vfp_single_multiply_accumulate(state, sd, sn, m, fpscr, 0, "fmac"); return vfp_single_multiply_accumulate(state, sd, sn, m, fpscr, 0, "fmac");
return exceptions;
} }
/* /*
@ -999,9 +991,7 @@ static u32 vfp_single_fmul(ARMul_State* state, int sd, int sn, s32 m, u32 fpscr)
vfp_single_normalise_denormal(&vsm); vfp_single_normalise_denormal(&vsm);
exceptions |= vfp_single_multiply(&vsd, &vsn, &vsm, fpscr); exceptions |= vfp_single_multiply(&vsd, &vsn, &vsm, fpscr);
return vfp_single_normaliseround(state, sd, &vsd, fpscr, exceptions, "fmul");
exceptions |= vfp_single_normaliseround(state, sd, &vsd, fpscr, "fmul");
return exceptions;
} }
/* /*
@ -1024,9 +1014,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); exceptions |= vfp_single_multiply(&vsd, &vsn, &vsm, fpscr);
vsd.sign = vfp_sign_negate(vsd.sign); vsd.sign = vfp_sign_negate(vsd.sign);
return vfp_single_normaliseround(state, sd, &vsd, fpscr, exceptions, "fnmul");
exceptions |= vfp_single_normaliseround(state, sd, &vsd, fpscr, "fnmul");
return exceptions;
} }
/* /*
@ -1052,8 +1040,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_add(&vsd, &vsn, &vsm, fpscr);
exceptions |= vfp_single_normaliseround(state, sd, &vsd, fpscr, "fadd"); return vfp_single_normaliseround(state, sd, &vsd, fpscr, exceptions, "fadd");
return exceptions;
} }
/* /*
@ -1148,8 +1135,7 @@ static u32 vfp_single_fdiv(ARMul_State* state, int sd, int sn, s32 m, u32 fpscr)
if ((vsd.significand & 0x3f) == 0) if ((vsd.significand & 0x3f) == 0)
vsd.significand |= ((u64)vsm.significand * vsd.significand != (u64)vsn.significand << 32); vsd.significand |= ((u64)vsm.significand * vsd.significand != (u64)vsn.significand << 32);
exceptions |= vfp_single_normaliseround(state, sd, &vsd, fpscr, "fdiv"); return vfp_single_normaliseround(state, sd, &vsd, fpscr, 0, "fdiv");
return exceptions;
vsn_nan: vsn_nan:
exceptions |= vfp_propagate_nan(&vsd, &vsn, &vsm, fpscr); exceptions |= vfp_propagate_nan(&vsd, &vsn, &vsm, fpscr);
@ -1175,8 +1161,7 @@ infinity:
invalid: invalid:
vfp_put_float(state, vfp_single_pack(&vfp_single_default_qnan), sd); vfp_put_float(state, vfp_single_pack(&vfp_single_default_qnan), sd);
exceptions |= FPSCR_IOC; return FPSCR_IOC;
return exceptions;
} }
static struct op fops[] = { static struct op fops[] = {
@ -1246,7 +1231,7 @@ u32 vfp_single_cpdo(ARMul_State* state, u32 inst, u32 fpscr) {
except = fop->fn(state, dest, sn, m, fpscr); except = fop->fn(state, dest, sn, m, fpscr);
LOG_TRACE(Core_ARM11, "itr%d: exceptions=%08x", vecitr >> FPSCR_LENGTH_BIT, except); 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 * CHECK: It appears to be undefined whether we stop when