[vtk-developers] Fast floor/round in VTK

Sean McBride sean at rogue-research.com
Fri Oct 8 17:03:23 EDT 2010


On Fri, 8 Oct 2010 08:11:21 -0600, David Gobbi said:

>I've looked into the ITK code a bit more, I'll be using a modified
>version of it in my own code and will probably push to have it merged
>into VTK somewhere down the line.

Great!

>int vtkMath::Floor(double x)
>{
>  const int r = static_cast<int>(x);
>  const int n = ( x != static_cast<double>(r) );
>  const int g = ( x < 0 );
>  return r - ( n & g );
>}
>
>I know that it is obfuscated,

Less that the current special cases. :)

>but I formulated it specifically to make
>sure that there is no branching.  I've looked at the assembly language
>produced by gcc for i386, x86_64, and ppc64 and all are very compact.

So it's not appreciably slower that the current special cases?

-- 
____________________________________________________________
Sean McBride, B. Eng                 sean at rogue-research.com
Rogue Research                        www.rogue-research.com 
Mac Software Developer              Montréal, Québec, Canada





More information about the vtk-developers mailing list