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

Michael Halle mhalle at bwh.harvard.edu
Fri Jul 11 11:37:11 EDT 2003


Arguably, you could just call it VTK_FABS_MACRO() to
assure that people know it's a macro, and assume they're
paying attention enough to know what that means (both
side effects and behavior).

One could argue that speed optimizing a debug build at
the risk of correctness is somewhat imprudent.  Whatever
the solution, it should be compatible with the most
effective compiler optimization of the non-debug case.
Inlining does that (avoids an extra function call), I
believe, but I'm not sure about the other options.

It's hard to imagine this question hasn't been benchmarked
to death sometime, somewhere.  We aren't talking about
some obscure part of C++.

Michael Halle
mhalle at bwh.harvard.edu



Chris Volpe said:
> 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
>>





More information about the vtk-developers mailing list