summaryrefslogtreecommitdiff
path: root/Build/source/utils/asymptote/runmath.in
diff options
context:
space:
mode:
Diffstat (limited to 'Build/source/utils/asymptote/runmath.in')
-rw-r--r--Build/source/utils/asymptote/runmath.in42
1 files changed, 40 insertions, 2 deletions
diff --git a/Build/source/utils/asymptote/runmath.in b/Build/source/utils/asymptote/runmath.in
index c31761aeb90..7b6e9e29579 100644
--- a/Build/source/utils/asymptote/runmath.in
+++ b/Build/source/utils/asymptote/runmath.in
@@ -155,12 +155,12 @@ real remainder(real x, real y)
return remainder(x,y);
}
-real J(Int n, real x)
+real Jn(Int n, real x)
{
return jn(n,x);
}
-real Y(Int n, real x)
+real Yn(Int n, real x)
{
return yn(n,x);
}
@@ -279,3 +279,41 @@ Int NOT(Int a)
{
return ~a;
}
+
+Int CLZ(Int a)
+{
+ if((unsignedInt) a > 0xFFFFFFFF) return -1;
+#ifdef __GNUC__
+ return __builtin_clz(a);
+#else
+// find the log base 2 of a 32-bit integer
+ static const int MultiplyDeBruijnBitPosition[32] = {
+ 0, 9, 1, 10, 13, 21, 2, 29, 11, 14, 16, 18, 22, 25, 3, 30,
+ 8, 12, 20, 28, 15, 17, 24, 7, 19, 27, 23, 6, 26, 5, 4, 31
+ };
+
+ a |= a >> 1; // first round down to one less than a power of 2
+ a |= a >> 2;
+ a |= a >> 4;
+ a |= a >> 8;
+ a |= a >> 16;
+
+ return 31-MultiplyDeBruijnBitPosition[(unsignedInt)(a * 0x07C4ACDDU) >> 27];
+#endif
+}
+
+Int CTZ(Int a)
+{
+ if((unsignedInt) a > 0xFFFFFFFF) return -1;
+#ifdef __GNUC__
+ return __builtin_ctz(a);
+#else
+ // find the number of trailing zeros in a 32-bit number
+ static const int MultiplyDeBruijnBitPosition[32] = {
+ 0, 1, 28, 2, 29, 14, 24, 3, 30, 22, 20, 15, 25, 17, 4, 8,
+ 31, 27, 13, 23, 21, 19, 16, 7, 26, 12, 18, 6, 11, 5, 10, 9
+ };
+ return MultiplyDeBruijnBitPosition[((unsignedInt)((a & -a) * 0x077CB531U))
+ >> 27];
+#endif
+}