[vtk-developers] Possible changes to vtkMath...

Chris Volpe cvolpe at ara.com
Fri Jul 11 09:32:03 EDT 2003


The problem with that is that it brings us back to square one. It's not
much different from the fabs that the compiler provides already. It
won't be inlined on a non-optimized build. Since the issue that Will
raised is one of unnecessarily-poor performance on a debug build, it
doesn't seem useful to me to suggest alternatives that don't address
that issue. That's the same problem I see with Michael's suggestion to
use inline functions: on a build in which the function would be inlined,
the compiler-provided fabs would be an intrinsic, so there's no point. I
understand the desire to avoid the double side-effect evaluation, but I
personally think that, if improved performance on debug builds is, in
fact, desirable, then the risk inherent in the macro definition is
manageable. Just put a comment above the definition. You could even call
the macro VTK_UNSAFE_FABS and let people use plain ol' fabs when not in
a tight loop.

-Chris

> -----Original Message-----
> From: Andy Cedilnik [mailto:andy.cedilnik at kitware.com]
> Sent: Friday, July 11, 2003 9:04 AM
> To: Michael Halle
> Cc: Will Schroeder; vtk-developers at vtk.org
> Subject: RE: [vtk-developers] Possible changes to vtkMath...
> 
> Hi All,
> 
> How about template? That should be faster.
> 
> Something like
> 
> template <class DataType>
> DataType VTK_ABS(DataType d)
> {
>   return ((d < 0.0 ) ? (-d) : (d) );
> }
> 
> 			Andy
> 
> On Thu, 2003-07-10 at 19:47, Michael Halle wrote:
> > I don't like the idea of a fabs()-based macro because
> > of the double-evaluation side effects.  Conditionally
> > defining it only makes it worse. The ternary operator
> > may or may not be highly optimized on some platforms.
> >
> > Inlining is the defined mechanism for this purpose, even
> > if it may be slower on some platforms, I think it's the
> > best choice.
> > Michael Halle
> > mhalle at bwh.harvard.edu
> 
> 
> _______________________________________________
> vtk-developers mailing list
> vtk-developers at vtk.org
> http://www.vtk.org/mailman/listinfo/vtk-developers




More information about the vtk-developers mailing list