R
rembremading
Hi all,
The "AMD Athlon Processor x86 Code Optimization Guide" gives the following
tips
for "Speeding Up Branches Based on Comparisons Between Floats"
#define FLOAT2INTCAST(f) (*((int *)(&f)))
#define FLOAT2UINTCAST(f) (*((unsigned int *)(&f)))
// comparisons among two floats
if (f1 < f2) ==>
float t = f1 - f2;
if (FLOAT2UINTCAST(t) > 0x80000000U)
if (f1 <= f2) ==>
float t = f1 - f2;
if (FLOAT2INTCAST(t) <= 0)
if (f1 > f2) ==>
float t = f1 - f2;
if (FLOAT2INTCAST(t) > 0)
if (f1 >= f2) ==>
float t = f1 - f2;
if (FLOAT2UINTCAST(f) <= 0x80000000U)
Indeed if find that this increases the speed of float comparisons
(depending on the compiler optimization settings, however)
However it seems that it works only if t is of type float.
Simply replacing float by double gives errornous results.
How do I have to modify it if I want to work with double variables
(doing a cast on a double variable "float t = (float) d;" before
I do the comparison, in general, decreases the speed again)
Best wishes, thanks in advance,
Andreas
The "AMD Athlon Processor x86 Code Optimization Guide" gives the following
tips
for "Speeding Up Branches Based on Comparisons Between Floats"
#define FLOAT2INTCAST(f) (*((int *)(&f)))
#define FLOAT2UINTCAST(f) (*((unsigned int *)(&f)))
// comparisons among two floats
if (f1 < f2) ==>
float t = f1 - f2;
if (FLOAT2UINTCAST(t) > 0x80000000U)
if (f1 <= f2) ==>
float t = f1 - f2;
if (FLOAT2INTCAST(t) <= 0)
if (f1 > f2) ==>
float t = f1 - f2;
if (FLOAT2INTCAST(t) > 0)
if (f1 >= f2) ==>
float t = f1 - f2;
if (FLOAT2UINTCAST(f) <= 0x80000000U)
Indeed if find that this increases the speed of float comparisons
(depending on the compiler optimization settings, however)
However it seems that it works only if t is of type float.
Simply replacing float by double gives errornous results.
How do I have to modify it if I want to work with double variables
(doing a cast on a double variable "float t = (float) d;" before
I do the comparison, in general, decreases the speed again)
Best wishes, thanks in advance,
Andreas