diff --git a/Eigen/src/Core/MathFunctions.h b/Eigen/src/Core/MathFunctions.h index 299b072d3..bda28fbfd 100644 --- a/Eigen/src/Core/MathFunctions.h +++ b/Eigen/src/Core/MathFunctions.h @@ -982,10 +982,9 @@ struct count_bits_impl(sizeof(BitsType) * CHAR_BIT); static_assert(std::is_integral::value, "BitsType must be a built-in integer"); static EIGEN_DEVICE_FUNC inline int clz(BitsType bits) { - static const int kLeadingBitsOffset = static_cast((sizeof(unsigned long) - sizeof(BitsType)) * CHAR_BIT); unsigned long out; _BitScanReverse(&out, static_cast(bits)); - return bits == 0 ? kNumBits : static_cast(out - kLeadingBitsOffset); + return bits == 0 ? kNumBits : (kNumBits - 1) - static_cast(out); } static EIGEN_DEVICE_FUNC inline int ctz(BitsType bits) { @@ -1003,10 +1002,9 @@ struct count_bits_impl< static const int kNumBits = static_cast(sizeof(BitsType) * CHAR_BIT); static_assert(std::is_integral::value, "BitsType must be a built-in integer"); static EIGEN_DEVICE_FUNC inline int clz(BitsType bits) { - static const int kLeadingBitsOffset = static_cast((sizeof(__int64) - sizeof(BitsType)) * CHAR_BIT); unsigned long out; _BitScanReverse64(&out, static_cast(bits)); - return bits == 0 ? kNumBits : static_cast(out - kLeadingBitsOffset); + return bits == 0 ? kNumBits : (kNumBits - 1) - static_cast(out); } static EIGEN_DEVICE_FUNC inline int ctz(BitsType bits) {