aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/bit_ops.h13
-rw-r--r--src/numthry.cpp2
2 files changed, 13 insertions, 2 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
diff --git a/src/numthry.cpp b/src/numthry.cpp
index 9f05b6114..ffd523e82 100644
--- a/src/numthry.cpp
+++ b/src/numthry.cpp
@@ -86,7 +86,7 @@ u32bit low_zero_bits(const BigInt& n)
if(x)
{
- low_zero += __builtin_ctzl(x);
+ low_zero += ctz(x);
break;
}
else