Skip to content

Commit

Permalink
Continued FPU fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
dingusdev committed Oct 30, 2024
1 parent 5f826d6 commit f660efc
Showing 1 changed file with 70 additions and 6 deletions.
76 changes: 70 additions & 6 deletions cpu/ppc/ppcfpopcodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ void dppc_interpreter::ppc_fadd() {
ppc_dblresult64_d = set_endresult_nan(ppc_dblresult64_d);
}
}

if (std::isnan(val_reg_a) || std::isnan(val_reg_b)) {
ppc_dblresult64_d = std::numeric_limits<double>::quiet_NaN();
}
Expand Down Expand Up @@ -254,6 +255,10 @@ void dppc_interpreter::ppc_fdiv() {
}
}

if (std::isnan(val_reg_a) || std::isnan(val_reg_b)) {
ppc_dblresult64_d = std::numeric_limits<double>::quiet_NaN();
}

ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);
fpresult_update(ppc_dblresult64_d);

Expand All @@ -280,6 +285,10 @@ void dppc_interpreter::ppc_fmul() {
}
}

if (std::isnan(val_reg_a) || std::isnan(val_reg_c)) {
ppc_dblresult64_d = std::numeric_limits<double>::quiet_NaN();
}

ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);
fpresult_update(ppc_dblresult64_d);

Expand All @@ -301,8 +310,13 @@ void dppc_interpreter::ppc_fmadd() {
double ppc_dblresult64_d = std::fma(val_reg_a, val_reg_c, val_reg_b);

double inf = std::numeric_limits<double>::infinity();
if (((val_reg_a == inf) && (val_reg_b == -inf)) || ((val_reg_a == -inf) && (val_reg_b == inf)))
if (((val_reg_a == inf) && (val_reg_b == -inf)) || \
((val_reg_a == -inf) && (val_reg_b == inf))) {
ppc_state.fpscr |= VXISI;
if (std::isnan(ppc_dblresult64_d)) {
ppc_dblresult64_d = set_endresult_nan(ppc_dblresult64_d);
}
}

if ((std::isinf(val_reg_a) && (val_reg_c == 0.0)) ||
(std::isinf(val_reg_c) && (val_reg_a == 0.0))) {
Expand All @@ -312,6 +326,10 @@ void dppc_interpreter::ppc_fmadd() {
}
}

if (std::isnan(val_reg_a) || std::isnan(val_reg_b) || std::isnan(val_reg_c)) {
ppc_dblresult64_d = std::numeric_limits<double>::quiet_NaN();
}

ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);
fpresult_update(ppc_dblresult64_d);

Expand Down Expand Up @@ -348,6 +366,10 @@ void dppc_interpreter::ppc_fmsub() {
}
}

if (std::isnan(val_reg_a) || std::isnan(val_reg_b) || std::isnan(val_reg_c)) {
ppc_dblresult64_d = std::numeric_limits<double>::quiet_NaN();
}

ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);
fpresult_update(ppc_dblresult64_d);

Expand Down Expand Up @@ -387,6 +409,10 @@ void dppc_interpreter::ppc_fnmadd() {
}
}

if (std::isnan(val_reg_a) || std::isnan(val_reg_b) || std::isnan(val_reg_c)) {
ppc_dblresult64_d = std::numeric_limits<double>::quiet_NaN();
}

ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);
fpresult_update(ppc_dblresult64_d);

Expand Down Expand Up @@ -423,6 +449,10 @@ void dppc_interpreter::ppc_fnmsub() {
}
}

if (std::isnan(val_reg_a) || std::isnan(val_reg_b) || std::isnan(val_reg_c)) {
ppc_dblresult64_d = std::numeric_limits<double>::quiet_NaN();
}

ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);
fpresult_update(ppc_dblresult64_d);

Expand All @@ -438,6 +468,7 @@ void dppc_interpreter::ppc_fadds() {
ppc_grab_regsfpdab(ppc_cur_instruction);

snan_double_check(reg_a, reg_b);
max_double_check(val_reg_a, val_reg_b);

double ppc_dblresult64_d = (float)(val_reg_a + val_reg_b);

Expand All @@ -449,6 +480,10 @@ void dppc_interpreter::ppc_fadds() {
}
}

if (std::isnan(val_reg_a) || std::isnan(val_reg_b)) {
ppc_dblresult64_d = std::numeric_limits<double>::quiet_NaN();
}

ppc_store_sfpresult_flt(reg_d, ppc_dblresult64_d);
fpresult_update(ppc_dblresult64_d);

Expand Down Expand Up @@ -512,6 +547,10 @@ void dppc_interpreter::ppc_fdivs() {
}
}

if (std::isnan(val_reg_a) || std::isnan(val_reg_b)) {
ppc_dblresult64_d = std::numeric_limits<double>::quiet_NaN();
}

ppc_store_sfpresult_flt(reg_d, ppc_dblresult64_d);
fpresult_update(ppc_dblresult64_d);

Expand All @@ -538,6 +577,10 @@ void dppc_interpreter::ppc_fmuls() {
}
}

if (std::isnan(val_reg_a) || std::isnan(val_reg_c)) {
ppc_dblresult64_d = std::numeric_limits<double>::quiet_NaN();
}

ppc_store_sfpresult_flt(reg_d, ppc_dblresult64_d);
fpresult_update(ppc_dblresult64_d);

Expand Down Expand Up @@ -570,9 +613,9 @@ void dppc_interpreter::ppc_fmadds() {
}
}

if (std::isnan(val_reg_b)) {
if (std::isnan(val_reg_a) || std::isnan(val_reg_b) || std::isnan(val_reg_c)) {
ppc_dblresult64_d = std::numeric_limits<double>::quiet_NaN();
}
}

ppc_store_sfpresult_flt(reg_d, ppc_dblresult64_d);
fpresult_update(ppc_dblresult64_d);
Expand All @@ -593,9 +636,6 @@ void dppc_interpreter::ppc_fmsubs() {


double ppc_dblresult64_d = (float)std::fma(val_reg_a, val_reg_c, -val_reg_b);
if (std::isnan(ppc_dblresult64_d)) {
ppc_dblresult64_d = std::numeric_limits<double>::quiet_NaN();
}

if ((std::isinf(val_reg_a) && (val_reg_c == 0.0)) ||
(std::isinf(val_reg_c) && (val_reg_a == 0.0))) {
Expand All @@ -609,6 +649,10 @@ void dppc_interpreter::ppc_fmsubs() {
if ((val_reg_a == inf) && (val_reg_b == inf))
ppc_state.fpscr |= VXISI;

if (std::isnan(val_reg_a) || std::isnan(val_reg_b) || std::isnan(val_reg_c)) {
ppc_dblresult64_d = std::numeric_limits<double>::quiet_NaN();
}

ppc_store_sfpresult_flt(reg_d, ppc_dblresult64_d);
fpresult_update(ppc_dblresult64_d);

Expand Down Expand Up @@ -643,6 +687,10 @@ void dppc_interpreter::ppc_fnmadds() {
}
}

if (std::isnan(val_reg_a) || std::isnan(val_reg_b) || std::isnan(val_reg_c)) {
ppc_dblresult64_d = std::numeric_limits<double>::quiet_NaN();
}

ppc_store_sfpresult_flt(reg_d, ppc_dblresult64_d);
fpresult_update(ppc_dblresult64_d);

Expand Down Expand Up @@ -674,6 +722,10 @@ void dppc_interpreter::ppc_fnmsubs() {
if ((val_reg_a == inf) && (val_reg_b == inf))
ppc_state.fpscr |= VXISI;

if (std::isnan(val_reg_a) || std::isnan(val_reg_b) || std::isnan(val_reg_c)) {
ppc_dblresult64_d = std::numeric_limits<double>::quiet_NaN();
}

ppc_store_sfpresult_flt(reg_d, ppc_dblresult64_d);
fpresult_update(ppc_dblresult64_d);

Expand All @@ -692,6 +744,10 @@ void dppc_interpreter::ppc_fabs() {

double ppc_dblresult64_d = abs(GET_FPR(reg_b));

if (std::isnan(GET_FPR(reg_b))) {
ppc_dblresult64_d = std::numeric_limits<double>::quiet_NaN();
}

ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);

if (rec)
Expand All @@ -710,6 +766,10 @@ void dppc_interpreter::ppc_fnabs() {
double ppc_dblresult64_d = abs(GET_FPR(reg_b));
ppc_dblresult64_d = -ppc_dblresult64_d;

if (std::isnan(GET_FPR(reg_b))) {
ppc_dblresult64_d = std::numeric_limits<double>::quiet_NaN();
}

ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);

if (rec)
Expand All @@ -727,6 +787,10 @@ void dppc_interpreter::ppc_fneg() {

double ppc_dblresult64_d = -(GET_FPR(reg_b));

if (std::isnan(GET_FPR(reg_b))) {
ppc_dblresult64_d = std::numeric_limits<double>::quiet_NaN();
}

ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);

if (rec)
Expand Down

0 comments on commit f660efc

Please sign in to comment.