Cleanup use of BMI intrinsics under GCC and compatibles

pull/531/head
Jeffrey Walton 2017-10-09 21:14:21 -04:00
parent 55fe79e5ee
commit 24a19b7a18
No known key found for this signature in database
GPG Key ID: B36AB348921B1838
1 changed files with 9 additions and 26 deletions

33
misc.h
View File

@ -1,4 +1,3 @@
// misc.h - originally written and placed in the public domain by Wei Dai // misc.h - originally written and placed in the public domain by Wei Dai
//! \file misc.h //! \file misc.h
@ -67,25 +66,9 @@
#include <byteswap.h> #include <byteswap.h>
#endif #endif
#if defined(__GNUC__) && defined(__BMI__) #if defined(__BMI__)
# include <immintrin.h> # include <x86intrin.h>
# if defined(__clang__) #endif // GCC and BMI
# 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
#endif // CRYPTOPP_DOXYGEN_PROCESSING #endif // CRYPTOPP_DOXYGEN_PROCESSING
@ -730,7 +713,7 @@ inline unsigned int TrailingZeros(word32 v)
// We don't enable for Microsoft because it requires a runtime check. // 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 // http://msdn.microsoft.com/en-us/library/hh977023%28v=vs.110%29.aspx
CRYPTOPP_ASSERT(v != 0); CRYPTOPP_ASSERT(v != 0);
#if defined(__GNUC__) && defined(__BMI__) #if defined(__BMI__)
return (unsigned int)_tzcnt_u32(v); return (unsigned int)_tzcnt_u32(v);
#elif defined(__GNUC__) && (CRYPTOPP_GCC_VERSION >= 30400) #elif defined(__GNUC__) && (CRYPTOPP_GCC_VERSION >= 30400)
return (unsigned int)__builtin_ctz(v); 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. // 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 // http://msdn.microsoft.com/en-us/library/hh977023%28v=vs.110%29.aspx
CRYPTOPP_ASSERT(v != 0); CRYPTOPP_ASSERT(v != 0);
#if defined(__GNUC__) && defined(__BMI__) && defined(__x86_64__) #if defined(__BMI__) && defined(__x86_64__)
return (unsigned int)_tzcnt_u64(v); return (unsigned int)_tzcnt_u64(v);
#elif defined(__GNUC__) && (CRYPTOPP_GCC_VERSION >= 30400) #elif defined(__GNUC__) && (CRYPTOPP_GCC_VERSION >= 30400)
return (unsigned int)__builtin_ctzll(v); return (unsigned int)__builtin_ctzll(v);
@ -869,7 +852,7 @@ inline bool IsPowerOf2(const T &value)
return value > 0 && (value & (value-1)) == 0; return value > 0 && (value & (value-1)) == 0;
} }
#if defined(__GNUC__) && defined(__BMI__) #if defined(__BMI__)
template <> template <>
inline bool IsPowerOf2<word32>(const word32 &value) inline bool IsPowerOf2<word32>(const word32 &value)
{ {
@ -882,8 +865,8 @@ inline bool IsPowerOf2<word64>(const word64 &value)
{ {
return value > 0 && _blsr_u64(value) == 0; return value > 0 && _blsr_u64(value) == 0;
} }
# endif # endif // __x86_64__
#endif #endif // __BMI__
//! \brief Performs a saturating subtract clamped at 0 //! \brief Performs a saturating subtract clamped at 0
//! \tparam T1 class or type //! \tparam T1 class or type