From 442e1c0c6ffebf233bae7367bc49a4d90c149b0b Mon Sep 17 00:00:00 2001 From: Tudor Bosman Date: Fri, 10 Aug 2012 14:22:05 -0700 Subject: [PATCH] sizeof works just as well as numeric_limits::digits Summary: ... and is shorter and more readable Test Plan: folly/test Reviewed By: andrei.alexandrescu@fb.com FB internal diff: D545774 --- folly/Bits.h | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/folly/Bits.h b/folly/Bits.h index 4649a073..8ecac77c 100644 --- a/folly/Bits.h +++ b/folly/Bits.h @@ -84,8 +84,7 @@ template typename std::enable_if< (std::is_integral::value && std::is_unsigned::value && - (std::numeric_limits::digits <= - std::numeric_limits::digits)), + sizeof(T) <= sizeof(unsigned int)), unsigned int>::type findFirstSet(T x) { return __builtin_ffs(x); @@ -95,10 +94,8 @@ template typename std::enable_if< (std::is_integral::value && std::is_unsigned::value && - (std::numeric_limits::digits > - std::numeric_limits::digits) && - (std::numeric_limits::digits <= - std::numeric_limits::digits)), + sizeof(T) > sizeof(unsigned int) && + sizeof(T) <= sizeof(unsigned long)), unsigned int>::type findFirstSet(T x) { return __builtin_ffsl(x); @@ -108,10 +105,8 @@ template typename std::enable_if< (std::is_integral::value && std::is_unsigned::value && - (std::numeric_limits::digits > - std::numeric_limits::digits) && - (std::numeric_limits::digits <= - std::numeric_limits::digits)), + sizeof(T) > sizeof(unsigned long) && + sizeof(T) <= sizeof(unsigned long long)), unsigned int>::type findFirstSet(T x) { return __builtin_ffsll(x); @@ -134,8 +129,7 @@ template typename std::enable_if< (std::is_integral::value && std::is_unsigned::value && - (std::numeric_limits::digits <= - std::numeric_limits::digits)), + sizeof(T) <= sizeof(unsigned int)), unsigned int>::type findLastSet(T x) { return x ? 8 * sizeof(unsigned int) - __builtin_clz(x) : 0; @@ -145,10 +139,8 @@ template typename std::enable_if< (std::is_integral::value && std::is_unsigned::value && - (std::numeric_limits::digits > - std::numeric_limits::digits) && - (std::numeric_limits::digits <= - std::numeric_limits::digits)), + sizeof(T) > sizeof(unsigned int) && + sizeof(T) <= sizeof(unsigned long)), unsigned int>::type findLastSet(T x) { return x ? 8 * sizeof(unsigned long) - __builtin_clzl(x) : 0; @@ -158,10 +150,8 @@ template typename std::enable_if< (std::is_integral::value && std::is_unsigned::value && - (std::numeric_limits::digits > - std::numeric_limits::digits) && - (std::numeric_limits::digits <= - std::numeric_limits::digits)), + sizeof(T) > sizeof(unsigned long) && + sizeof(T) <= sizeof(unsigned long long)), unsigned int>::type findLastSet(T x) { return x ? 8 * sizeof(unsigned long long) - __builtin_clzll(x) : 0; -- 2.34.1