Added optimizations to ClassifyFloat/Double functions in Mathutil.cpp and to PPCCache.cpp

This commit is contained in:
eli173 2013-06-01 19:17:52 -05:00
parent 80b09c074e
commit 7aae9ccbc0
2 changed files with 64 additions and 73 deletions

View File

@ -15,19 +15,15 @@ namespace MathUtil
u32 ClassifyDouble(double dvalue) u32 ClassifyDouble(double dvalue)
{ {
// TODO: Optimize the below to be as fast as possible. // TODO: Optimize the below to be as fast as possible.
IntDouble value; u64 exp = *(u64*)(&dvalue) & DOUBLE_EXP;
value.d = dvalue; if (exp != DOUBLE_ZERO && exp != DOUBLE_EXP)
u64 sign = value.i & DOUBLE_SIGN;
u64 exp = value.i & DOUBLE_EXP;
if (exp > DOUBLE_ZERO && exp < DOUBLE_EXP)
{ {
// Nice normalized number. // Nice normalized number.
return sign ? PPC_FPCLASS_NN : PPC_FPCLASS_PN; return *(u64*)(&dvalue)&DOUBLE_SIGN ? PPC_FPCLASS_NN : PPC_FPCLASS_PN;
} }
else else
{ {
u64 mantissa = value.i & DOUBLE_FRAC; if (*(u64*)(&dvalue) & DOUBLE_FRAC)
if (mantissa)
{ {
if (exp) if (exp)
{ {
@ -36,38 +32,35 @@ u32 ClassifyDouble(double dvalue)
else else
{ {
// Denormalized number. // Denormalized number.
return sign ? PPC_FPCLASS_ND : PPC_FPCLASS_PD; return *(u64*)(&dvalue)&DOUBLE_SIGN ? PPC_FPCLASS_ND : PPC_FPCLASS_PD;
} }
} }
else if (exp) else if (exp)
{ {
//Infinite //Infinite
return sign ? PPC_FPCLASS_NINF : PPC_FPCLASS_PINF; return *(u64*)(&dvalue)&DOUBLE_SIGN ? PPC_FPCLASS_NINF : PPC_FPCLASS_PINF;
} }
else else
{ {
//Zero //Zero
return sign ? PPC_FPCLASS_NZ : PPC_FPCLASS_PZ; return *(u64*)(&dvalue)&DOUBLE_SIGN ? PPC_FPCLASS_NZ : PPC_FPCLASS_PZ;
} }
} }
} }
u32 ClassifyFloat(float fvalue) u32 ClassifyFloat(float fvalue)
{ {
// TODO: Optimize the below to be as fast as possible. // TODO: Optimize the below to be as fast as possible.
IntFloat value; u32 exp = *(u32*)(&fvalue) & FLOAT_EXP;
value.f = fvalue;
u32 sign = value.i & FLOAT_SIGN;
u32 exp = value.i & FLOAT_EXP;
if (exp > FLOAT_ZERO && exp < FLOAT_EXP) if (exp > FLOAT_ZERO && exp < FLOAT_EXP)
{ {
// Nice normalized number. // Nice normalized number.
return sign ? PPC_FPCLASS_NN : PPC_FPCLASS_PN; return *(u32*)(&fvalue) & FLOAT_SIGN ? PPC_FPCLASS_NN : PPC_FPCLASS_PN;
} }
else else
{ {
u32 mantissa = value.i & FLOAT_FRAC; if (*(u32*)(&fvalue) & FLOAT_FRAC)
if (mantissa)
{ {
if (exp) if (exp)
{ {
@ -76,18 +69,18 @@ u32 ClassifyFloat(float fvalue)
else else
{ {
// Denormalized number. // Denormalized number.
return sign ? PPC_FPCLASS_ND : PPC_FPCLASS_PD; return *(u32*)(&fvalue) & FLOAT_SIGN ? PPC_FPCLASS_ND : PPC_FPCLASS_PD;
} }
} }
else if (exp) else if (exp)
{ {
// Infinite // Infinite
return sign ? PPC_FPCLASS_NINF : PPC_FPCLASS_PINF; return *(u32*)(&fvalue) & FLOAT_SIGN ? PPC_FPCLASS_NINF : PPC_FPCLASS_PINF;
} }
else else
{ {
//Zero //Zero
return sign ? PPC_FPCLASS_NZ : PPC_FPCLASS_PZ; return *(u32*)(&fvalue) & FLOAT_SIGN ? PPC_FPCLASS_NZ : PPC_FPCLASS_PZ;
} }
} }
} }

View File

@ -26,28 +26,26 @@ namespace PowerPC
for (u32 m = 0; m < 128; m++) for (u32 m = 0; m < 128; m++)
{ {
u32 b[7];
for (int i = 0; i < 7; i++) b[i] = m & (1<<i);
u32 w; u32 w;
if (b[0]) if(m & (1<<0))
if (b[2]) if(m & (1<<2))
if (b[6]) if(m & (1<<6))
w=7; w=7;
else else
w=6; w=6;
else else
if (b[5]) if(m & (1<<5))
w=5; w=5;
else else
w=4; w=4;
else else
if (b[1]) if(m & (1<<1))
if (b[4]) if(m & (1<<4))
w=3; w=3;
else else
w=2; w=2;
else else
if (b[3]) if(m & (1<<3))
w=1; w=1;
else else
w=0; w=0;