28#ifndef itkMathDetail_h
29#define itkMathDetail_h
36#if (defined(ITK_COMPILER_SUPPORTS_SSE2_32) || defined(ITK_COMPILER_SUPPORTS_SSE2_64)) && !defined(ITK_WRAPPING_PARSER)
37# include <emmintrin.h>
41#define USE_SSE2_64IMPL 0
42#define USE_SSE2_32IMPL 0
45#if defined(ITK_COMPILER_SUPPORTS_SSE2_32) && !defined(ITK_WRAPPING_PARSER)
46# undef USE_SSE2_32IMPL
47# define USE_SSE2_32IMPL 1
49#if defined(ITK_COMPILER_SUPPORTS_SSE2_64) && !defined(ITK_WRAPPING_PARSER)
50# undef USE_SSE2_64IMPL
51# define USE_SSE2_64IMPL 1
57#if defined(__GNUC__) && !defined(ITK_WRAPPING_PARSER) && \
58 (defined(__i386__) || defined(__i386) || defined(__x86_64__) || defined(__x86_64))
59# define GCC_USE_ASM_32IMPL 1
60# define GCC_USE_ASM_64IMPL 1
62# define GCC_USE_ASM_32IMPL 0
63# define GCC_USE_ASM_64IMPL 0
67#if defined(_MSC_VER) && !defined(ITK_WRAPPING_PARSER) && !defined(_WIN64)
68# define VC_USE_ASM_32IMPL 1
69# define VC_USE_ASM_64IMPL 1
71# define VC_USE_ASM_32IMPL 0
72# define VC_USE_ASM_64IMPL 0
89ITK_GCC_SUPPRESS_Wfloat_equal
91template <
typename TReturn,
typename TInput>
97 x +=
static_cast<TInput
>(0.5);
101 x -=
static_cast<TInput
>(0.5);
104 const auto r =
static_cast<TReturn
>(x);
105 return (x !=
static_cast<TInput
>(r)) ? r :
static_cast<TReturn
>(2 * (r / 2));
108template <
typename TReturn,
typename TInput>
112 x +=
static_cast<TInput
>(0.5);
113 const auto r =
static_cast<TReturn
>(x);
115 : (x ==
static_cast<TInput
>(r) ? r : r -
static_cast<TReturn
>(1));
118template <
typename TReturn,
typename TInput>
122 const auto r =
static_cast<TReturn
>(x);
125 : (x ==
static_cast<TInput
>(r) ? r : r -
static_cast<TReturn
>(1));
128template <
typename TReturn,
typename TInput>
132 const auto r =
static_cast<TReturn
>(x);
147# if defined(ITK_CHECK_FPU_ROUNDING_MODE)
148 itkAssertInDebugAndIgnoreInReleaseMacro(fegetround() == FE_TONEAREST);
150 return _mm_cvtsd_si32(_mm_set_sd(x));
156# if defined(ITK_CHECK_FPU_ROUNDING_MODE)
157 itkAssertInDebugAndIgnoreInReleaseMacro(fegetround() == FE_TONEAREST);
159 return _mm_cvtss_si32(_mm_set_ss(x));
162#elif GCC_USE_ASM_32IMPL
167# if defined(ITK_CHECK_FPU_ROUNDING_MODE)
168 itkAssertInDebugAndIgnoreInReleaseMacro(fegetround() == FE_TONEAREST);
171 __asm__ __volatile__(
"fistpl %0" :
"=m"(r) :
"t"(x) :
"st");
178# if defined(ITK_CHECK_FPU_ROUNDING_MODE)
179 itkAssertInDebugAndIgnoreInReleaseMacro(fegetround() == FE_TONEAREST);
182 __asm__ __volatile__(
"fistpl %0" :
"=m"(r) :
"t"(x) :
"st");
186#elif VC_USE_ASM_32IMPL
191# if defined(ITK_CHECK_FPU_ROUNDING_MODE)
192 itkAssertInDebugAndIgnoreInReleaseMacro(fegetround() == FE_TONEAREST);
206# if defined(ITK_CHECK_FPU_ROUNDING_MODE)
207 itkAssertInDebugAndIgnoreInReleaseMacro(fegetround() == FE_TONEAREST);
233#if USE_SSE2_32IMPL || GCC_USE_ASM_32IMPL || VC_USE_ASM_32IMPL
313# if defined(ITK_CHECK_FPU_ROUNDING_MODE)
314 itkAssertInDebugAndIgnoreInReleaseMacro(fegetround() == FE_TONEAREST);
316 return _mm_cvtsd_si64(_mm_set_sd(x));
322# if defined(ITK_CHECK_FPU_ROUNDING_MODE)
323 itkAssertInDebugAndIgnoreInReleaseMacro(fegetround() == FE_TONEAREST);
325 return _mm_cvtss_si64(_mm_set_ss(x));
328#elif GCC_USE_ASM_64IMPL
333# if defined(ITK_CHECK_FPU_ROUNDING_MODE)
334 itkAssertInDebugAndIgnoreInReleaseMacro(fegetround() == FE_TONEAREST);
337 __asm__ __volatile__(
"fistpll %0" :
"=m"(r) :
"t"(x) :
"st");
344# if defined(ITK_CHECK_FPU_ROUNDING_MODE)
345 itkAssertInDebugAndIgnoreInReleaseMacro(fegetround() == FE_TONEAREST);
348 __asm__ __volatile__(
"fistpll %0" :
"=m"(r) :
"t"(x) :
"st");
352#elif VC_USE_ASM_64IMPL
357# if defined(ITK_CHECK_FPU_ROUNDING_MODE)
358 itkAssertInDebugAndIgnoreInReleaseMacro(fegetround() == FE_TONEAREST);
372# if defined(ITK_CHECK_FPU_ROUNDING_MODE)
373 itkAssertInDebugAndIgnoreInReleaseMacro(fegetround() == FE_TONEAREST);
399#if USE_SSE2_64IMPL || GCC_USE_ASM_64IMPL || VC_USE_ASM_64IMPL
534#undef USE_SSE2_32IMPL
535#undef GCC_USE_ASM_32IMPL
536#undef VC_USE_ASM_32IMPL
538#undef USE_SSE2_64IMPL
539#undef GCC_USE_ASM_64IMPL
540#undef VC_USE_ASM_64IMPL
static bool IsNegative(T val)
static bool IsNonnegative(T val)
ITK_GCC_PRAGMA_POP int32_t RoundHalfIntegerToEven_32(double x)
int32_t Floor_32(double x)
TReturn RoundHalfIntegerUp_base(TInput x)
int32_t RoundHalfIntegerUp_32(double x)
TReturn Ceil_base(TInput x)
int64_t Floor_64(double x)
int64_t Ceil_64(double x)
int32_t Ceil_32(double x)
int64_t RoundHalfIntegerUp_64(double x)
int64_t RoundHalfIntegerToEven_64(double x)
ITK_GCC_PRAGMA_PUSH ITK_GCC_SUPPRESS_Wfloat_equal TReturn RoundHalfIntegerToEven_base(TInput x)
TReturn Floor_base(TInput x)
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
typename FloatIEEETraits< T >::IntType IntType
typename FloatIEEETraits< T >::UIntType UIntType