From 1d4967b5fc3c95b5a509d04521f004f3e24c7c3e Mon Sep 17 00:00:00 2001 From: Jeffrey Walton Date: Tue, 26 Apr 2016 17:13:15 -0400 Subject: [PATCH] Updated to use BLSR intrinsic from SSE4/BMI when available --- misc.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/misc.h b/misc.h index 23404493..cdee9de7 100644 --- a/misc.h +++ b/misc.h @@ -744,6 +744,20 @@ inline bool IsPowerOf2(const T &value) return value > 0 && (value & (value-1)) == 0; } +#if defined(__GNUC__) && defined(__BMI__) +template <> +inline bool IsPowerOf2(const word32 &value) +{ + return value > 0 && _blsr_u32(value) == 0; +} + +template <> +inline bool IsPowerOf2(const word64 &value) +{ + return value > 0 && _blsr_u64(value) == 0; +} +#endif + //! \brief Tests whether the residue of a value is a power of 2 //! \param a the value to test //! \param b the value to use to reduce \a to its residue