summaryrefslogtreecommitdiff
path: root/node/Utils.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'node/Utils.hpp')
-rw-r--r--node/Utils.hpp14
1 files changed, 14 insertions, 0 deletions
diff --git a/node/Utils.hpp b/node/Utils.hpp
index 7b1994be..ceb29d7e 100644
--- a/node/Utils.hpp
+++ b/node/Utils.hpp
@@ -253,6 +253,20 @@ public:
}
/**
+ * Count the number of bits set in an integer
+ *
+ * @param v 64-bit integer
+ * @return Number of bits set in this integer (0-64)
+ */
+ static inline uint64_t countBits(uint64_t v)
+ {
+ v = v - ((v >> 1) & (uint64_t)~(uint64_t)0/3);
+ v = (v & (uint64_t)~(uint64_t)0/15*3) + ((v >> 2) & (uint64_t)~(uint64_t)0/15*3);
+ v = (v + (v >> 4)) & (uint64_t)~(uint64_t)0/255*15;
+ return (uint64_t)(v * ((uint64_t)~(uint64_t)0/255)) >> 56;
+ }
+
+ /**
* Check if a memory buffer is all-zero
*
* @param p Memory to scan