summaryrefslogtreecommitdiff
path: root/Source/Core/Common/Src/MathUtil.cpp
diff options
context:
space:
mode:
authoreli173 <eli@eli173.com>2013-06-01 19:17:52 -0500
committereli173 <eli@eli173.com>2013-06-01 19:17:52 -0500
commit7aae9ccbc0494cd468a37413d7199061bd1981d2 (patch)
tree2341be1bc7083adb660d5be27ce59fb86795c493 /Source/Core/Common/Src/MathUtil.cpp
parent80b09c074e610304d3e34ba05c80c41a6d872507 (diff)
Added optimizations to ClassifyFloat/Double functions in Mathutil.cpp and to PPCCache.cpp
Diffstat (limited to 'Source/Core/Common/Src/MathUtil.cpp')
-rw-r--r--Source/Core/Common/Src/MathUtil.cpp89
1 files changed, 41 insertions, 48 deletions
diff --git a/Source/Core/Common/Src/MathUtil.cpp b/Source/Core/Common/Src/MathUtil.cpp
index 0e90328ee0..fc79a54ef0 100644
--- a/Source/Core/Common/Src/MathUtil.cpp
+++ b/Source/Core/Common/Src/MathUtil.cpp
@@ -13,61 +13,54 @@ namespace MathUtil
{
u32 ClassifyDouble(double dvalue)
-{
- // TODO: Optimize the below to be as fast as possible.
- IntDouble value;
- value.d = dvalue;
- u64 sign = value.i & DOUBLE_SIGN;
- u64 exp = value.i & DOUBLE_EXP;
- if (exp > DOUBLE_ZERO && exp < DOUBLE_EXP)
- {
- // Nice normalized number.
- return sign ? PPC_FPCLASS_NN : PPC_FPCLASS_PN;
- }
- else
- {
- u64 mantissa = value.i & DOUBLE_FRAC;
- if (mantissa)
- {
- if (exp)
- {
- return PPC_FPCLASS_QNAN;
- }
- else
- {
- // Denormalized number.
- return sign ? PPC_FPCLASS_ND : PPC_FPCLASS_PD;
- }
- }
- else if (exp)
- {
- //Infinite
- return sign ? PPC_FPCLASS_NINF : PPC_FPCLASS_PINF;
- }
- else
- {
- //Zero
- return sign ? PPC_FPCLASS_NZ : PPC_FPCLASS_PZ;
- }
- }
-}
+ {
+ // TODO: Optimize the below to be as fast as possible.
+ u64 exp = *(u64*)(&dvalue) & DOUBLE_EXP;
+ if (exp != DOUBLE_ZERO && exp != DOUBLE_EXP)
+ {
+ // Nice normalized number.
+ return *(u64*)(&dvalue)&DOUBLE_SIGN ? PPC_FPCLASS_NN : PPC_FPCLASS_PN;
+ }
+ else
+ {
+ if (*(u64*)(&dvalue) & DOUBLE_FRAC)
+ {
+ if (exp)
+ {
+ return PPC_FPCLASS_QNAN;
+ }
+ else
+ {
+ // Denormalized number.
+ return *(u64*)(&dvalue)&DOUBLE_SIGN ? PPC_FPCLASS_ND : PPC_FPCLASS_PD;
+ }
+ }
+ else if (exp)
+ {
+ //Infinite
+ return *(u64*)(&dvalue)&DOUBLE_SIGN ? PPC_FPCLASS_NINF : PPC_FPCLASS_PINF;
+ }
+ else
+ {
+ //Zero
+ return *(u64*)(&dvalue)&DOUBLE_SIGN ? PPC_FPCLASS_NZ : PPC_FPCLASS_PZ;
+ }
+ }
+ }
+
u32 ClassifyFloat(float fvalue)
{
// TODO: Optimize the below to be as fast as possible.
- IntFloat value;
- value.f = fvalue;
- u32 sign = value.i & FLOAT_SIGN;
- u32 exp = value.i & FLOAT_EXP;
+ u32 exp = *(u32*)(&fvalue) & FLOAT_EXP;
if (exp > FLOAT_ZERO && exp < FLOAT_EXP)
{
// Nice normalized number.
- return sign ? PPC_FPCLASS_NN : PPC_FPCLASS_PN;
+ return *(u32*)(&fvalue) & FLOAT_SIGN ? PPC_FPCLASS_NN : PPC_FPCLASS_PN;
}
else
{
- u32 mantissa = value.i & FLOAT_FRAC;
- if (mantissa)
+ if (*(u32*)(&fvalue) & FLOAT_FRAC)
{
if (exp)
{
@@ -76,18 +69,18 @@ u32 ClassifyFloat(float fvalue)
else
{
// Denormalized number.
- return sign ? PPC_FPCLASS_ND : PPC_FPCLASS_PD;
+ return *(u32*)(&fvalue) & FLOAT_SIGN ? PPC_FPCLASS_ND : PPC_FPCLASS_PD;
}
}
else if (exp)
{
// Infinite
- return sign ? PPC_FPCLASS_NINF : PPC_FPCLASS_PINF;
+ return *(u32*)(&fvalue) & FLOAT_SIGN ? PPC_FPCLASS_NINF : PPC_FPCLASS_PINF;
}
else
{
//Zero
- return sign ? PPC_FPCLASS_NZ : PPC_FPCLASS_PZ;
+ return *(u32*)(&fvalue) & FLOAT_SIGN ? PPC_FPCLASS_NZ : PPC_FPCLASS_PZ;
}
}
}