aboutsummaryrefslogtreecommitdiffstats
path: root/include/bit_ops.h
diff options
context:
space:
mode:
authorlloyd <[email protected]>2008-09-05 14:56:14 +0000
committerlloyd <[email protected]>2008-09-05 14:56:14 +0000
commitb3f36983110046a97093ce6b5e90565aaa369e6f (patch)
tree492f075d5e7aaf18842ffb448d7bc80851c359e5 /include/bit_ops.h
parent23edbc3cd784dce36148133109921990bfe0ddf8 (diff)
Replace __builtin_ctzl with a new ctz function in bit_ops.h
Diffstat (limited to 'include/bit_ops.h')
-rw-r--r--include/bit_ops.h13
1 files changed, 12 insertions, 1 deletions
diff --git a/include/bit_ops.h b/include/bit_ops.h
index 42b922620..ca6fb7d5d 100644
--- a/include/bit_ops.h
+++ b/include/bit_ops.h
@@ -13,7 +13,6 @@ namespace Botan {
/*************************************************
* Return true iff arg is 2**n for some n > 0 *
* T should be an unsigned integer type *
-*
*************************************************/
template<typename T>
inline bool power_of_2(T arg)
@@ -71,6 +70,18 @@ inline u32bit hamming_weight(T n)
return weight;
}
+/*************************************************
+* Count the trailing zero bits in n *
+*************************************************/
+template<typename T>
+inline int ctz(T n)
+ {
+ for(int i = 0; i != 8*sizeof(T); ++i)
+ if((n >> i) & 0x01)
+ return i;
+ return 8*sizeof(T);
+ }
+
}
#endif