Fixed the implementation of Eigen::internal::count_leading_zeros for MSVC.

Also updated the code to silence bogux warnings generated by nvcc when compilining this function.
This commit is contained in:
Benoit Steiner 2015-11-23 12:17:45 -08:00
parent 562078780a
commit 547a8608e5

View File

@ -34,10 +34,7 @@ namespace {
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE int count_leading_zeros(const T val) EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE int count_leading_zeros(const T val)
{ {
#ifdef __CUDA_ARCH__ #ifdef __CUDA_ARCH__
if (sizeof(T) == 8) { return (sizeof(T) == 8) ? __clzll(val) : __clz(val);
return __clzll(val);
}
return __clz(val);
#elif EIGEN_COMP_MSVC #elif EIGEN_COMP_MSVC
DWORD leading_zeros = 0; DWORD leading_zeros = 0;
if (sizeof(T) == 8) { if (sizeof(T) == 8) {
@ -46,11 +43,11 @@ namespace {
else { else {
_BitScanReverse(&leading_zero, val); _BitScanReverse(&leading_zero, val);
} }
return leading_zeros;
#else #else
if (sizeof(T) == 8) { return (sizeof(T) == 8) ?
return __builtin_clzl(static_cast<uint64_t>(val)); __builtin_clzl(static_cast<uint64_t>(val)) :
} __builtin_clz(static_cast<uint32_t>(val));
return __builtin_clz(static_cast<uint32_t>(val));
#endif #endif
} }