]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
fix the fallback atomic operation implementation for use on arm devices.
authorMichael Jerris <mike@jerris.com>
Tue, 15 May 2007 17:22:49 +0000 (17:22 +0000)
committerMichael Jerris <mike@jerris.com>
Tue, 15 May 2007 17:22:49 +0000 (17:22 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@5186 d0543943-73ff-0310-b7d9-9358b9ac24b2

libs/js/nsprpub/pr/src/misc/pratom.c

index 24028e56bda4609ef6dd68a1afd578d834525a78..a903e98a50c881b0f12897be947124fc8090a53f 100644 (file)
  */
 
 #if !defined(_PR_HAVE_ATOMIC_OPS)
+#include "prbit.h"
+
+/*
+** Compute the log of the least power of 2 greater than or equal to n
+*/
+PR_IMPLEMENT(PRIntn) PR_CeilingLog2(PRUint32 n)
+{
+    PRIntn log2 = 0;
+
+    if (n & (n-1))
+       log2++;
+    if (n >> 16)
+       log2 += 16, n >>= 16;
+    if (n >> 8)
+       log2 += 8, n >>= 8;
+    if (n >> 4)
+       log2 += 4, n >>= 4;
+    if (n >> 2)
+       log2 += 2, n >>= 2;
+    if (n >> 1)
+       log2++;
+    return log2;
+}
+
+/*
+** Compute the log of the greatest power of 2 less than or equal to n.
+** This really just finds the highest set bit in the word.
+*/
+PR_IMPLEMENT(PRIntn) PR_FloorLog2(PRUint32 n)
+{
+    PRIntn log2 = 0;
+
+    if (n >> 16)
+       log2 += 16, n >>= 16;
+    if (n >> 8)
+       log2 += 8, n >>= 8;
+    if (n >> 4)
+       log2 += 4, n >>= 4;
+    if (n >> 2)
+       log2 += 2, n >>= 2;
+    if (n >> 1)
+       log2++;
+    return log2;
+}
 
 #if defined(_PR_PTHREADS) && !defined(_PR_DCETHREADS)
 /*