[vtk-developers] Speeding up raycasting on x86

David Gobbi dgobbi at imaging.robarts.ca
Thu Jul 11 15:23:09 EDT 2002


On Thu, 11 Jul 2002, Lisa Avila wrote:

> Hi David,
>
> I had tried something similar to this in another place at one time and did
> not see a significant improvement so I abandoned it. It seems like you have
> found a good place to use it if you've made a 35% performance improvement!
>
> Does this generate compiler warnings? If it doesn't then I see no reason
> not to use it.

No compiler warnings, that same inline function already exists in
vtkImageReslice.

I can put the inline func into vtkVolumeRayCastMapper.h as a replacement
for the vtkFloorFuncMacro().  At the same time I'll also replace the
vtkRoundFuncMacro() with one that has #ifdefs for iX86.  That will
provide speedups for NearestNeighbor raycasting as well.

And all of this is necessary just because the engineers that designed
the 386 didn't include a 'truncate to int' instruction, only a 'convert
float to int according to prevailing rounding mode' where every operating
system uses 'round to nearest' as the default mode.

 - David


> At 02:15 PM 7/11/2002, David Gobbi wrote:
> >Hi Lisa,
> >
> >I tried a little experiment with vtkVolumeRayCastCompositeFunction
> >and managed a speed-up of 35% in VTK's trilinear ray casting.
> >
> >I replaced all instances of
> >
> >  <something> = (int)(floatval)
> >
> >with
> >
> >  <something> = vtkQuickFloor(floatval)
> >
> >according to the following definition of vtkQuickFloor:
> >
> >inline int vtkQuickFloor(double x)
> >{
> >#if defined i386 || defined _M_IX86
> >   unsigned int hilo[2];
> >   *((double *)hilo) = x + 103079215104.0;  // (2**(52-16))*1.5
> >   return (int)((hilo[1]<<16)|(hilo[0]>>16));
> >#else
> >   return (int)(x);
> >#endif
> >}
> >
> >That big mess with the bitshifts and whatnot is a trick that I found
> >on a web page a couple years ago (I could dig up the URL) that works
> >many times faster than what most iX86 compilers generate for (int)
> >casts.  I've been using it in vtkImageReslice for a while now.
> >
> >Is this the sort of optimization that Kitware is interested in?
> >It is messy and CPU-specific, but it is confined to one single
> >inline function.
> >
> >  - David
> >
> >_______________________________________________
> >vtk-developers mailing list
> >vtk-developers at public.kitware.com
> >http://public.kitware.com/mailman/listinfo/vtk-developers
>




More information about the vtk-developers mailing list