28 #ifndef itkMathDetail_h
29 #define itkMathDetail_h
36 #if defined( ITK_HAVE_EMMINTRIN_H ) && !defined( ITK_WRAPPING_PARSER )
37 #include <emmintrin.h>
41 #define USE_SSE2_64IMPL 0
42 #define USE_SSE2_32IMPL 0
46 #if defined(__APPLE__) && defined( __SSE2__ ) && !defined( ITK_WRAPPING_PARSER )
48 # if defined( __i386__ )
49 # undef USE_SSE2_32IMPL
50 # define USE_SSE2_32IMPL 1
53 # if defined( __x86_64 )
55 # undef USE_SSE2_64IMPL
56 # define USE_SSE2_64IMPL 1
59 # undef USE_SSE2_32IMPL
60 # define USE_SSE2_32IMPL 1
69 # if defined(ITK_COMPILER_SUPPORTS_SSE2_32) && !defined( ITK_WRAPPING_PARSER )
70 # undef USE_SSE2_32IMPL
71 # define USE_SSE2_32IMPL 1
73 # if defined(ITK_COMPILER_SUPPORTS_SSE2_64) && !defined( ITK_WRAPPING_PARSER )
74 # undef USE_SSE2_64IMPL
75 # define USE_SSE2_64IMPL 1
84 #if defined( __GNUC__ ) && ( !defined( ITK_WRAPPING_PARSER ) ) && ( defined( __i386__ ) || defined( __i386 ) \
85 || defined( __x86_64__ ) || defined( __x86_64 ) )
86 #define GCC_USE_ASM_32IMPL 1
87 #define GCC_USE_ASM_64IMPL 1
89 #define GCC_USE_ASM_32IMPL 0
90 #define GCC_USE_ASM_64IMPL 0
93 #if defined( VCL_VC ) && ( !defined( ITK_WRAPPING_PARSER ) ) && !defined( _WIN64 )
94 #define VC_USE_ASM_32IMPL 1
95 #define VC_USE_ASM_64IMPL 1
97 #define VC_USE_ASM_32IMPL 0
98 #define VC_USE_ASM_64IMPL 0
116 CLANG_SUPPRESS_Wfloat_equal
118 template<
typename TReturn,
typename TInput >
123 x +=
static_cast< TInput
>( 0.5 );
127 x -=
static_cast< TInput
>( 0.5 );
130 const auto r =
static_cast< TReturn
>( x );
131 return ( x != static_cast< TInput >( r ) ) ? r : static_cast< TReturn >( 2 * ( r / 2 ) );
134 template<
typename TReturn,
typename TInput >
137 x +=
static_cast< TInput
>( 0.5 );
138 const auto r =
static_cast< TReturn
>( x );
141 ( x == static_cast< TInput >( r ) ? r : r -
static_cast< TReturn
>( 1 ) );
144 template<
typename TReturn,
typename TInput >
147 const auto r =
static_cast< TReturn
>( x );
151 ( x == static_cast< TInput >( r ) ? r : r -
static_cast< TReturn
>( 1 ) );
154 template<
typename TReturn,
typename TInput >
157 const auto r =
static_cast< TReturn
>( x );
161 ( x == static_cast< TInput >( r ) ? r : r +
static_cast< TReturn
>( 1 ) );
169 #if USE_SSE2_32IMPL // sse2 implementation
173 #if defined( ITK_CHECK_FPU_ROUNDING_MODE )
174 itkAssertInDebugAndIgnoreInReleaseMacro(fegetround() == FE_TONEAREST);
176 return _mm_cvtsd_si32( _mm_set_sd(x) );
181 #if defined( ITK_CHECK_FPU_ROUNDING_MODE )
182 itkAssertInDebugAndIgnoreInReleaseMacro(fegetround() == FE_TONEAREST);
184 return _mm_cvtss_si32( _mm_set_ss(x) );
187 #elif GCC_USE_ASM_32IMPL // gcc asm implementation
191 #if defined( ITK_CHECK_FPU_ROUNDING_MODE )
192 itkAssertInDebugAndIgnoreInReleaseMacro(fegetround() == FE_TONEAREST);
195 __asm__ __volatile__ (
"fistpl %0" :
"=m" ( r ) :
"t" ( x ) :
"st" );
201 #if defined( ITK_CHECK_FPU_ROUNDING_MODE )
202 itkAssertInDebugAndIgnoreInReleaseMacro(fegetround() == FE_TONEAREST);
205 __asm__ __volatile__ (
"fistpl %0" :
"=m" ( r ) :
"t" ( x ) :
"st" );
209 #elif VC_USE_ASM_32IMPL // msvc asm implementation
213 #if defined( ITK_CHECK_FPU_ROUNDING_MODE )
214 itkAssertInDebugAndIgnoreInReleaseMacro(fegetround() == FE_TONEAREST);
227 #if defined( ITK_CHECK_FPU_ROUNDING_MODE )
228 itkAssertInDebugAndIgnoreInReleaseMacro(fegetround() == FE_TONEAREST);
239 #else // Base implementation
246 #if USE_SSE2_32IMPL || GCC_USE_ASM_32IMPL || VC_USE_ASM_32IMPL
257 #else // Base implementation
268 #endif // USE_SSE2_32IMPL || GCC_USE_ASM_32IMPL || VC_USE_ASM_32IMPL
273 #if USE_SSE2_64IMPL // sse2 implementation
277 #if defined( ITK_CHECK_FPU_ROUNDING_MODE )
278 itkAssertInDebugAndIgnoreInReleaseMacro(fegetround() == FE_TONEAREST);
280 return _mm_cvtsd_si64( _mm_set_sd(x) );
285 #if defined( ITK_CHECK_FPU_ROUNDING_MODE )
286 itkAssertInDebugAndIgnoreInReleaseMacro(fegetround() == FE_TONEAREST);
288 return _mm_cvtss_si64( _mm_set_ss(x) );
291 #elif GCC_USE_ASM_64IMPL // gcc asm implementation
295 #if defined( ITK_CHECK_FPU_ROUNDING_MODE )
296 itkAssertInDebugAndIgnoreInReleaseMacro(fegetround() == FE_TONEAREST);
299 __asm__ __volatile__ (
"fistpll %0" :
"=m" ( r ) :
"t" ( x ) :
"st" );
305 #if defined( ITK_CHECK_FPU_ROUNDING_MODE )
306 itkAssertInDebugAndIgnoreInReleaseMacro(fegetround() == FE_TONEAREST);
309 __asm__ __volatile__ (
"fistpll %0" :
"=m" ( r ) :
"t" ( x ) :
"st" );
313 #elif VC_USE_ASM_64IMPL // msvc asm implementation
317 #if defined( ITK_CHECK_FPU_ROUNDING_MODE )
318 itkAssertInDebugAndIgnoreInReleaseMacro(fegetround() == FE_TONEAREST);
331 #if defined( ITK_CHECK_FPU_ROUNDING_MODE )
332 itkAssertInDebugAndIgnoreInReleaseMacro(fegetround() == FE_TONEAREST);
343 #else // Base implementation
350 #if USE_SSE2_64IMPL || GCC_USE_ASM_64IMPL || VC_USE_ASM_64IMPL
361 #else // Base implementation
372 #endif // USE_SSE2_64IMPL || GCC_USE_ASM_64IMPL || VC_USE_ASM_64IMPL
374 template <
typename T>
391 template <
typename T>
420 template<
typename T >
429 #undef USE_SSE2_32IMPL
430 #undef GCC_USE_ASM_32IMPL
431 #undef VC_USE_ASM_32IMPL
433 #undef USE_SSE2_64IMPL
434 #undef GCC_USE_ASM_64IMPL
435 #undef VC_USE_ASM_64IMPL
437 #endif // end of itkMathDetail.h
int64_t RoundHalfIntegerUp_64(double x)
int32_t Ceil_32(double x)
CLANG_PRAGMA_PUSH CLANG_SUPPRESS_Wfloat_equal TReturn RoundHalfIntegerToEven_base(TInput x)
Define numeric traits for std::vector.
typename FloatIEEETraits< T >::IntType IntType
TReturn Ceil_base(TInput x)
CLANG_PRAGMA_POP int32_t RoundHalfIntegerToEven_32(double x)
int64_t Floor_64(double x)
TReturn RoundHalfIntegerUp_base(TInput x)
int64_t Ceil_64(double x)
typename FloatIEEETraits< T >::UIntType UIntType
int64_t RoundHalfIntegerToEven_64(double x)
TReturn Floor_base(TInput x)
int32_t Floor_32(double x)
int32_t RoundHalfIntegerUp_32(double x)