aboutsummaryrefslogtreecommitdiffhomepage
path: root/unsupported/Eigen/CXX11/src/Tensor/TensorIntDiv.h
diff options
context:
space:
mode:
authorGravatar Benoit Steiner <benoit.steiner.goog@gmail.com>2015-02-25 22:54:20 -0800
committerGravatar Benoit Steiner <benoit.steiner.goog@gmail.com>2015-02-25 22:54:20 -0800
commit27f3fb2bcc8ea06f3f471560fc1c87210cd0c62b (patch)
tree139c3cff3a4449d33894e964bbe9b6fea413c0c4 /unsupported/Eigen/CXX11/src/Tensor/TensorIntDiv.h
parentf8fbb3f9a642371d3798e8d6e9638d878e00d945 (diff)
Fixed another clang warning
Diffstat (limited to 'unsupported/Eigen/CXX11/src/Tensor/TensorIntDiv.h')
-rw-r--r--unsupported/Eigen/CXX11/src/Tensor/TensorIntDiv.h21
1 files changed, 16 insertions, 5 deletions
diff --git a/unsupported/Eigen/CXX11/src/Tensor/TensorIntDiv.h b/unsupported/Eigen/CXX11/src/Tensor/TensorIntDiv.h
index 2714117ab..4b22c64de 100644
--- a/unsupported/Eigen/CXX11/src/Tensor/TensorIntDiv.h
+++ b/unsupported/Eigen/CXX11/src/Tensor/TensorIntDiv.h
@@ -28,6 +28,21 @@ namespace Eigen {
namespace internal {
+namespace {
+ template <typename T>
+ EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE int count_leading_zeros(const T val)
+ {
+#ifndef __CUDA_ARCH__
+ if (sizeof(T) == 8) {
+ return __builtin_clzl(val);
+ }
+ return __builtin_clz(val);
+#else
+ return __clz(val);
+#endif
+ }
+};
+
template <typename T>
struct TensorIntDivisor {
public:
@@ -44,11 +59,7 @@ struct TensorIntDivisor {
eigen_assert(divider <= (1<<(N-1)) - 1);
// fast ln2
-#ifndef __CUDA_ARCH__
- const int leading_zeros = __builtin_clz(divider);
-#else
- const int leading_zeros = __clz(divider);
-#endif
+ const int leading_zeros = count_leading_zeros(divider);
const int log_div = N - (leading_zeros+1);
multiplier = (static_cast<uint64_t>(1) << (N+log_div)) / divider - (static_cast<uint64_t>(1) << N) + 1;