summaryrefslogtreecommitdiffstats
path: root/vespalib
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2021-06-04 14:45:37 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2021-06-04 14:45:37 +0000
commit6c537290ad1df8469b54dee80079542c171fac1a (patch)
tree89944b77956563404aa159bb394a57b0e2c399fb /vespalib
parentd9ef7a012e717a0176613de2a6c02f7b5c57fff7 (diff)
Move roundUp2inN<T> to vespalib.
Diffstat (limited to 'vespalib')
-rw-r--r--vespalib/src/vespa/vespalib/util/alloc.h12
-rw-r--r--vespalib/src/vespa/vespalib/util/optimized.h6
2 files changed, 13 insertions, 5 deletions
diff --git a/vespalib/src/vespa/vespalib/util/alloc.h b/vespalib/src/vespa/vespalib/util/alloc.h
index f608a244035..a97e8c9f25e 100644
--- a/vespalib/src/vespa/vespalib/util/alloc.h
+++ b/vespalib/src/vespa/vespalib/util/alloc.h
@@ -102,13 +102,21 @@ private:
namespace vespalib {
/// Rounds up to the closest number that is a power of 2
-inline size_t roundUp2inN(size_t minimum) {
+inline size_t
+roundUp2inN(size_t minimum) {
return 2ul << Optimized::msbIdx(minimum - 1);
}
/// Rounds minElems up to the closest number where minElems*elemSize is a power of 2
-inline size_t roundUp2inN(size_t minElems, size_t elemSize) {
+inline size_t
+roundUp2inN(size_t minElems, size_t elemSize) {
return roundUp2inN(minElems * elemSize)/elemSize;
}
+template <typename T>
+size_t
+roundUp2inN(size_t elems) {
+ return roundUp2inN(elems, sizeof(T));
+}
+
}
diff --git a/vespalib/src/vespa/vespalib/util/optimized.h b/vespalib/src/vespa/vespalib/util/optimized.h
index 92cf1f0ca24..6c6d1b12a71 100644
--- a/vespalib/src/vespa/vespalib/util/optimized.h
+++ b/vespalib/src/vespa/vespalib/util/optimized.h
@@ -22,9 +22,9 @@ public:
static int lsbIdx(unsigned int v);
static int lsbIdx(unsigned long v);
static int lsbIdx(unsigned long long v);
- static int popCount(unsigned int v) { return __builtin_popcount(v); }
- static int popCount(unsigned long v) { return __builtin_popcountl(v); }
- static int popCount(unsigned long long v) { return __builtin_popcountll(v); }
+ static constexpr int popCount(unsigned int v) { return __builtin_popcount(v); }
+ static constexpr int popCount(unsigned long v) { return __builtin_popcountl(v); }
+ static constexpr int popCount(unsigned long long v) { return __builtin_popcountll(v); }
};
/**