[Insight-developers] vnl updates : Rounding Test : Performance and Correctness

Tom Vercauteren tom.vercauteren at m4x.org
Fri Jan 2 04:33:01 EST 2009


Sorry, mail sent too quickly. The snippet should only be:

#if VNL_CONFIG_ENABLE_SSE2_ROUNDING
#  if VNL_CONFIG_HALFINT_FAST
inline int vnl_math_rnd(float  x){return _mm_cvtss_si32(_mm_set_ss(x));}
#  elif defined  VNL_CONFIG_HALFINT_UP
inline int vnl_math_rnd(float  x){return
(_mm_cvtss_si32(_mm_set_ss(2*x+0.5f))>>1);}
#  else
#    error "Unknown rounding type"
#  endif
#else
#  if VNL_CONFIG_HALFINT_FAST
inline int vnl_math_rnd(float  x) {return x>=0.f?static_cast<int>(x +
.5f):static_cast<int>(x - .5f); }
#  elif defined  VNL_CONFIG_HALFINT_UP
inline int vnl_math_rnd(float  x) {x+=0.5f; return
static_cast<int>(x>=0.f?x:(x==static_cast<int>(x)?x:x-1.f));}
#  else
#    error "Unknown rounding type"
#  endif
#endif

Tom

On Fri, Jan 2, 2009 at 10:31 AM, Tom Vercauteren
<tom.vercauteren at m4x.org> wrote:
> Hi all,
>
> This looks like a good option. Something like that could also be done
> directly into vnl. Below is a snippet that shows what it would look
> like considering only the sse2 and if implementation.
>
> Tom
>
> On Wed, Dec 31, 2008 at 6:15 PM, Luis Ibanez <luis.ibanez at kitware.com> wrote:
>> Amitha, Hans,
>>
>> I actually agree with all your comments.
>>
>> It seems that we all agree that a set of "Round" definitions is what we
>> need,
>> even though we anticipate that the most used will be the RoundItQuickly().
>>
>> The challenge now is to identify a way of implementing this in a manner that
>> make
>> sense for both ITK developers, developers of ITK-based applications, and end
>> users.
>>
>> Trying to look at it from Tom's perspective, the issue that I see is the the
>> decision of
>> speed vs multi-platform consistency will appear at the end-user level and
>> not at the
>> moment when an ITK developer is deciding which on of the available
>> implementations
>> of "round" to use.
>>
>> In other words, the decision of "I just need this program to run as fast as
>> possible
>> and I don't care if the result is different in another platform" will most
>> likely be
>> made by an end-user (application user) than by an application developer, and
>> much less by an ITK developer.
>>
>> This leads to suggest that the selection of the particular Round
>> implementation
>> should probably be managed by a CMake option that would be turned on at the
>> moment of configuring/building ITK and the said application.  By default,
>> probably we would use the settings for rounding in a consistent manner
>> across
>> platforms.
>>
>> My suggestion would be to add a file
>>
>>                                         itkMath.h
>>
>> to Insight/Code/Common
>>
>>  and to put in there the implementations of Round, Ceil, Floor.
>>
>> Then add a CMake flag option to the top CMakeLists.txt file, to select
>> among the different implementations of round.
>>
>> It could be:
>>
>> CMake variable name:    ITK_ROUND_OPTION
>>
>> CMake variable acceptable values:
>>
>>                    MultiPlatform
>>                    Fast
>>                    Unbiased
>>
>> The "Fast" option could delegate the rounding to the VNL implementation
>> (if that happens to be the most efficient one).
>>
>> An alternative proposal would be to define Round as a Macro, and to
>> put it in itkMacro.h
>>
>>
>>
>>        Luis
>>
>>
>> ------------------------------------------------------------------------------
>> On Wed, Dec 31, 2008 at 11:32 AM, Hans Johnson <hans-johnson at uiowa.edu>
>> wrote:
>>>
>>> Amitha:  Thanks.  Indeed the JustRoundItQuickly is likely the most
>>> intended
>>> use of round.   Perhaps what is needed are just two round functions
>>> (JustRoundItQuickly, RoundConsistentlyAcrossPlatforms).
>>>
>>> Hans
>>>
>>>
>>>
>>>
>>> On 12/31/08 10:23 AM, "Amitha Perera" <amitha.perera at kitware.com> wrote:
>>>
>>> > JustRoundItQuickly
>>>
>>
>>
>


More information about the Insight-developers mailing list