Merge pull request #13881 from OatmealDome/clang-floating-point-nonsense-2

FloatUtils: Replace quieting SNaNs via `0.0 + x` with MakeQuiet
This commit is contained in:
OatmealDome
2025-08-17 13:00:19 -04:00
committed by GitHub
3 changed files with 23 additions and 23 deletions

View File

@@ -108,7 +108,7 @@ double ApproximateReciprocalSquareRoot(double val)
return 0.0;
}
return 0.0 + val;
return MakeQuiet(val);
}
// Negative numbers return NaN
@@ -165,7 +165,7 @@ double ApproximateReciprocal(double val)
{
if (mantissa == 0)
return std::copysign(0.0, val);
return 0.0 + val;
return MakeQuiet(val);
}
// Special case small inputs

View File

@@ -68,6 +68,13 @@ inline double FlushToZero(double d)
return std::bit_cast<double>(i);
}
inline double MakeQuiet(double d)
{
const u64 integral = std::bit_cast<u64>(d) | Common::DOUBLE_QBIT;
return std::bit_cast<double>(integral);
}
enum PPCFpClass
{
PPC_FPCLASS_QNAN = 0x11,

View File

@@ -123,13 +123,6 @@ inline double Force25Bit(double d)
return std::bit_cast<double>(integral);
}
inline double MakeQuiet(double d)
{
const u64 integral = std::bit_cast<u64>(d) | Common::DOUBLE_QBIT;
return std::bit_cast<double>(integral);
}
// these functions allow globally modify operations behaviour
// also, these may be used to set flags like FR, FI, OX, UX
@@ -162,12 +155,12 @@ inline FPResult NI_mul(PowerPC::PowerPCState& ppc_state, double a, double b)
if (std::isnan(a))
{
result.value = MakeQuiet(a);
result.value = Common::MakeQuiet(a);
return result;
}
if (std::isnan(b))
{
result.value = MakeQuiet(b);
result.value = Common::MakeQuiet(b);
return result;
}
@@ -200,12 +193,12 @@ inline FPResult NI_div(PowerPC::PowerPCState& ppc_state, double a, double b)
if (std::isnan(a))
{
result.value = MakeQuiet(a);
result.value = Common::MakeQuiet(a);
return result;
}
if (std::isnan(b))
{
result.value = MakeQuiet(b);
result.value = Common::MakeQuiet(b);
return result;
}
@@ -234,12 +227,12 @@ inline FPResult NI_add(PowerPC::PowerPCState& ppc_state, double a, double b)
if (std::isnan(a))
{
result.value = MakeQuiet(a);
result.value = Common::MakeQuiet(a);
return result;
}
if (std::isnan(b))
{
result.value = MakeQuiet(b);
result.value = Common::MakeQuiet(b);
return result;
}
@@ -267,12 +260,12 @@ inline FPResult NI_sub(PowerPC::PowerPCState& ppc_state, double a, double b)
if (std::isnan(a))
{
result.value = MakeQuiet(a);
result.value = Common::MakeQuiet(a);
return result;
}
if (std::isnan(b))
{
result.value = MakeQuiet(b);
result.value = Common::MakeQuiet(b);
return result;
}
@@ -303,17 +296,17 @@ inline FPResult NI_madd(PowerPC::PowerPCState& ppc_state, double a, double c, do
if (std::isnan(a))
{
result.value = MakeQuiet(a);
result.value = Common::MakeQuiet(a);
return result;
}
if (std::isnan(b))
{
result.value = MakeQuiet(b); // !
result.value = Common::MakeQuiet(b); // !
return result;
}
if (std::isnan(c))
{
result.value = MakeQuiet(c);
result.value = Common::MakeQuiet(c);
return result;
}
@@ -341,17 +334,17 @@ inline FPResult NI_msub(PowerPC::PowerPCState& ppc_state, double a, double c, do
if (std::isnan(a))
{
result.value = MakeQuiet(a);
result.value = Common::MakeQuiet(a);
return result;
}
if (std::isnan(b))
{
result.value = MakeQuiet(b); // !
result.value = Common::MakeQuiet(b); // !
return result;
}
if (std::isnan(c))
{
result.value = MakeQuiet(c);
result.value = Common::MakeQuiet(c);
return result;
}