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);
220template <
typename TInput>
229#if USE_SSE2_32IMPL || GCC_USE_ASM_32IMPL || VC_USE_ASM_32IMPL
266template <
typename TInput>
273template <
typename TInput>
280template <
typename TInput>
297# if defined(ITK_CHECK_FPU_ROUNDING_MODE)
298 itkAssertInDebugAndIgnoreInReleaseMacro(fegetround() == FE_TONEAREST);
300 return _mm_cvtsd_si64(_mm_set_sd(x));
306# if defined(ITK_CHECK_FPU_ROUNDING_MODE)
307 itkAssertInDebugAndIgnoreInReleaseMacro(fegetround() == FE_TONEAREST);
309 return _mm_cvtss_si64(_mm_set_ss(x));
312#elif GCC_USE_ASM_64IMPL
317# if defined(ITK_CHECK_FPU_ROUNDING_MODE)
318 itkAssertInDebugAndIgnoreInReleaseMacro(fegetround() == FE_TONEAREST);
321 __asm__ __volatile__(
"fistpll %0" :
"=m"(r) :
"t"(x) :
"st");
328# if defined(ITK_CHECK_FPU_ROUNDING_MODE)
329 itkAssertInDebugAndIgnoreInReleaseMacro(fegetround() == FE_TONEAREST);
332 __asm__ __volatile__(
"fistpll %0" :
"=m"(r) :
"t"(x) :
"st");
336#elif VC_USE_ASM_64IMPL
341# if defined(ITK_CHECK_FPU_ROUNDING_MODE)
342 itkAssertInDebugAndIgnoreInReleaseMacro(fegetround() == FE_TONEAREST);
356# if defined(ITK_CHECK_FPU_ROUNDING_MODE)
357 itkAssertInDebugAndIgnoreInReleaseMacro(fegetround() == FE_TONEAREST);
370template <
typename TInput>
379#if USE_SSE2_64IMPL || GCC_USE_ASM_64IMPL || VC_USE_ASM_64IMPL
416template <
typename TInput>
423template <
typename TInput>
430template <
typename TInput>
476 [[nodiscard]]
constexpr bool
481 [[nodiscard]]
constexpr IntType
505#undef USE_SSE2_32IMPL
506#undef GCC_USE_ASM_32IMPL
507#undef VC_USE_ASM_32IMPL
509#undef USE_SSE2_64IMPL
510#undef GCC_USE_ASM_64IMPL
511#undef VC_USE_ASM_64IMPL
static bool IsNegative(T val)
static bool IsNonnegative(T val)
constexpr int32_t Floor_32(TInput x)
ITK_GCC_PRAGMA_POP constexpr int32_t RoundHalfIntegerToEven_32(TInput x)
constexpr int64_t RoundHalfIntegerToEven_64(TInput x)
constexpr int32_t RoundHalfIntegerUp_32(TInput x)
constexpr TReturn Floor_base(TInput x)
constexpr TReturn RoundHalfIntegerUp_base(TInput x)
ITK_GCC_PRAGMA_PUSH ITK_GCC_SUPPRESS_Wfloat_equal constexpr TReturn RoundHalfIntegerToEven_base(TInput x)
constexpr int64_t RoundHalfIntegerUp_64(TInput x)
constexpr int32_t Ceil_32(TInput x)
constexpr int64_t Ceil_64(TInput x)
constexpr int64_t Floor_64(TInput x)
constexpr TReturn Ceil_base(TInput x)
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
constexpr bool Sign() const
constexpr FloatIEEE(IntType i)
constexpr IntType AsULP() const
constexpr FloatIEEE(FloatType f)
constexpr FloatIEEE(UIntType ui)
typename FloatIEEETraits< T >::IntType IntType
typename FloatIEEETraits< T >::UIntType UIntType