Today I learned that NaNs and infinites may slow down programs significantly. So instead of
// some computation that produce NaN when arg == 0
if(arg == 0) // special case
result = 0;
one should write
if(arg == 0)
result = 0; // special case
else
// some computation that produce NaN when arg == 0
Instructions involving denormalized(very small) values are also very slow.
I've heard of a trick to optimize the DP (sometimes up to tens times!):
After this optimization no computations are made with very small numbers, so denormalized numbers are not involved too, so it causes a speedup.
I've never experimented with denormals, but supposedly you can turn them off by calling
_controlfp_s
with the_DN_FLUSH
flag set.After reading this blog, I realized...
Thanks for the heads-up :) I guess I got really lucky today. (After fixing issue you described the time became 140ms)