summaryrefslogtreecommitdiff
path: root/base/intmath.hh
diff options
context:
space:
mode:
Diffstat (limited to 'base/intmath.hh')
-rw-r--r--base/intmath.hh14
1 files changed, 14 insertions, 0 deletions
diff --git a/base/intmath.hh b/base/intmath.hh
index cb5a34107..fc28eecef 100644
--- a/base/intmath.hh
+++ b/base/intmath.hh
@@ -119,6 +119,20 @@ FloorLog2(int64_t x)
return FloorLog2((uint64_t)x);
}
+inline int
+FloorLog2(size_t x)
+{
+ assert(x > 0);
+ assert(sizeof(size_t) == 4 || sizeof(size_t) == 8);
+
+ // It's my hope that this is optimized away?
+ if (sizeof(size_t) == 4)
+ return FloorLog2((uint32_t)x);
+ else if (sizeof(size_t) == 8)
+ return FloorLog2((uint64_t)x);
+
+}
+
template <class T>
inline int
CeilLog2(T n)