]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
use a compiler builtin (which uses processor instructions) for this operation
authorKevin P. Fleming <kpfleming@digium.com>
Tue, 13 Jun 2006 20:59:15 +0000 (20:59 +0000)
committerKevin P. Fleming <kpfleming@digium.com>
Tue, 13 Jun 2006 20:59:15 +0000 (20:59 +0000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@33933 65c4cc65-6c06-0410-ace0-fbb531ad65f3

channels/chan_agent.c
translate.c

index 6bbc89cb34b4d57a73b7d6c0060ae1ba47535093..fb77a9456a94a600b218df4e5adc3418fabe7599 100644 (file)
@@ -1334,12 +1334,13 @@ static struct ast_channel *agent_request(const char *type, int format, void *dat
        return chan;
 }
 
-static int powerof(unsigned int v)
+static force_inline int powerof(unsigned int d)
 {
-       int x;
-       for (x=0;x<32;x++) {
-               if (v & (1 << x)) return x;
-       }
+       int x = ffs(d);
+
+       if (x)
+               return x - 1;
+
        return 0;
 }
 
index 6bb31387177f076d8f13e4c2f95d401689c926c7..256130c8288c7d59bee790e2ea257050e90480ca 100644 (file)
@@ -74,13 +74,15 @@ static struct translator_path tr_matrix[MAX_FORMAT][MAX_FORMAT];
  */
 
 /*! \brief returns the index of the lowest bit set */
-static int powerof(int d)
+static force_inline int powerof(unsigned int d)
 {
-       int x;
-       for (x = 0; x < MAX_FORMAT; x++)
-               if ((1 << x) & d)
-                       return x;
-       ast_log(LOG_WARNING, "Powerof %d: No power??\n", d);
+       int x = ffs(d);
+
+       if (x)
+               return x - 1;
+
+       ast_log(LOG_WARNING, "No bits set? %d\n", d);
+
        return -1;
 }