[vtk-developers] vtkImageReslice performance questions/improvemnts

David Gobbi david.gobbi at gmail.com
Tue Sep 14 11:08:01 EDT 2010


Hi Sean,

Casting to int does round-towards-zero, while floor() does
round-towards-neg-infinity.  The latter rounding mode is needed for
vtkImageReslice. Also, even casting to int can be notoriously slow on
the x86 CPU.  A summary is provided here:
http://www.stereopsis.com/FPU.html

The general implementation "static_cast<int>(floor())" is the simplest
correct implementation, even if it is inefficient, so I'd like to
leave it as the general case.  But we could easily add an #ifdef to
add whichever float-to-int conversion is most efficient for your
platform.

  David


On Tue, Sep 14, 2010 at 8:43 AM, Sean McBride <sean at rogue-research.com> wrote:
> Hi all,
>
> We've been profiling our app lately, and I've found some of our
> bottlenecks are in vtkImageReslice.
>
> One is vtkResliceRound() here:
>
> <http://vtk.org/gitweb?p=VTK.git;a=blob;f=Imaging/
> vtkImageReslice.cxx;h=2c65fbd922fd6b9daeae39110232d19ef21e6b93;hb=HEAD>
>
> It has a bunch of incomprehensible (but clever!) CPU-specific
> implementations, but the general implementation is:
>
> inline int vtkResliceRound(double x)
> {
>  return static_cast<int>(floor(x+0.5));
> }
>
> The comments indicate that the slow floor() is the reason for the CPU-
> specific implementations.  But I don't see the need for the floor() at
> all.  floor() returns double, but then we cast to int anyway.  So why
> not skip the floor and cast straight to int?
>
> In my usage, that change works and is much faster.  Is there some edge-
> case that I'm not seeing?
>
> Thanks,
>
> --
> ____________________________________________________________
> Sean McBride, B. Eng                 sean at rogue-research.com
> Rogue Research                        www.rogue-research.com
> Mac Software Developer              Montréal, Québec, Canada
>
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtk-developers
>
>



More information about the vtk-developers mailing list