From: Ian Scott <ian.scott@st...>  20050722 16:43:40

It turns out that because of the way the x86 chip works, doing a cast from double to int is very slow. It is faster to do call vnl_math_rnd than a cast now. Explanation on http://meganerd.com/FPcast/ The relative times (i.e. smaller is faster) of old/default version of vnl_math_rnd 1.69 cast double > int 1.34 new version of vnl_math_rnd(if supported) 0.54 The speedup only works on compilers that have an intrinsic version of lrint() (defined by the C99 standard). This includes gcc3.3 If anyone wants an equivalent speedup for MSVC.NET, then the following should work. inline int vnl_math_rnd (double flt) { int out; _asm { fld int fistp out } return out; } inline int vnl_math_rnd (double flt) { int out; _asm { fld int fistp out } return out; } I'll leave it as an exercise for the reader to figure out how to put inline assembly code in vnl_math.h Ian. 