From 24a19b7a189d9438ad75a651233bd213595d8903 Mon Sep 17 00:00:00 2001 From: Jeffrey Walton Date: Mon, 9 Oct 2017 21:14:21 -0400 Subject: [PATCH] Cleanup use of BMI intrinsics under GCC and compatibles --- misc.h | 35 +++++++++-------------------------- 1 file changed, 9 insertions(+), 26 deletions(-) diff --git a/misc.h b/misc.h index 36bae7cf..8c421c23 100644 --- a/misc.h +++ b/misc.h @@ -1,4 +1,3 @@ - // misc.h - originally written and placed in the public domain by Wei Dai //! \file misc.h @@ -67,27 +66,11 @@ #include #endif -#if defined(__GNUC__) && defined(__BMI__) -# include -# if defined(__clang__) -# ifndef _tzcnt_u32 -# define _tzcnt_u32(x) __tzcnt_u32(x) -# endif -# ifndef _blsr_u32 -# define _blsr_u32(x) __blsr_u32(x) -# endif -# ifdef __x86_64__ -# ifndef _tzcnt_u64 -# define _tzcnt_u64(x) __tzcnt_u64(x) -# endif -# ifndef _blsr_u64 -# define _blsr_u64(x) __blsr_u64(x) -# endif -# endif // x86_64 -# endif // Clang -#endif // GNUC and BMI +#if defined(__BMI__) +# include +#endif // GCC and BMI -#endif // CRYPTOPP_DOXYGEN_PROCESSING +#endif // CRYPTOPP_DOXYGEN_PROCESSING #if CRYPTOPP_DOXYGEN_PROCESSING //! \brief The maximum value of a machine word @@ -730,7 +713,7 @@ inline unsigned int TrailingZeros(word32 v) // We don't enable for Microsoft because it requires a runtime check. // http://msdn.microsoft.com/en-us/library/hh977023%28v=vs.110%29.aspx CRYPTOPP_ASSERT(v != 0); -#if defined(__GNUC__) && defined(__BMI__) +#if defined(__BMI__) return (unsigned int)_tzcnt_u32(v); #elif defined(__GNUC__) && (CRYPTOPP_GCC_VERSION >= 30400) return (unsigned int)__builtin_ctz(v); @@ -761,7 +744,7 @@ inline unsigned int TrailingZeros(word64 v) // We don't enable for Microsoft because it requires a runtime check. // http://msdn.microsoft.com/en-us/library/hh977023%28v=vs.110%29.aspx CRYPTOPP_ASSERT(v != 0); -#if defined(__GNUC__) && defined(__BMI__) && defined(__x86_64__) +#if defined(__BMI__) && defined(__x86_64__) return (unsigned int)_tzcnt_u64(v); #elif defined(__GNUC__) && (CRYPTOPP_GCC_VERSION >= 30400) return (unsigned int)__builtin_ctzll(v); @@ -869,7 +852,7 @@ inline bool IsPowerOf2(const T &value) return value > 0 && (value & (value-1)) == 0; } -#if defined(__GNUC__) && defined(__BMI__) +#if defined(__BMI__) template <> inline bool IsPowerOf2(const word32 &value) { @@ -882,8 +865,8 @@ inline bool IsPowerOf2(const word64 &value) { return value > 0 && _blsr_u64(value) == 0; } -# endif -#endif +# endif // __x86_64__ +#endif // __BMI__ //! \brief Performs a saturating subtract clamped at 0 //! \tparam T1 class or type