aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/utils/bit_ops.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/utils/bit_ops.h')
-rw-r--r--src/lib/utils/bit_ops.h22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/lib/utils/bit_ops.h b/src/lib/utils/bit_ops.h
index 0072fde71..75a7584ad 100644
--- a/src/lib/utils/bit_ops.h
+++ b/src/lib/utils/bit_ops.h
@@ -1,6 +1,10 @@
/*
* Bit/Word Operations
* (C) 1999-2008 Jack Lloyd
+* (C) Copyright Projet SECRET, INRIA, Rocquencourt
+* (C) Bhaskar Biswas and Nicolas Sendrier
+* (C) 2014 cryptosource GmbH
+* (C) 2014 Falko Strenzke [email protected]
*
* Distributed under the terms of the Botan license
*/
@@ -98,6 +102,24 @@ inline size_t ctz(T n)
return 8*sizeof(T);
}
+template<typename T>
+size_t ceil_log2(T x)
+ {
+ if(x >> (sizeof(T)*8-1))
+ return sizeof(T)*8;
+
+ size_t result = 0;
+ T compare = 1;
+
+ while(compare < x)
+ {
+ compare <<= 1;
+ result++;
+ }
+
+ return result;
+ }
+
}
#endif