[svn-commits] trunk r33933 - in /trunk: channels/chan_agent.c translate.c

svn-commits at lists.digium.com svn-commits at lists.digium.com
Tue Jun 13 13:59:15 MST 2006


Author: kpfleming
Date: Tue Jun 13 15:59:15 2006
New Revision: 33933

URL: http://svn.digium.com/view/asterisk?rev=33933&view=rev
Log:
use a compiler builtin (which uses processor instructions) for this operation

Modified:
    trunk/channels/chan_agent.c
    trunk/translate.c

Modified: trunk/channels/chan_agent.c
URL: http://svn.digium.com/view/asterisk/trunk/channels/chan_agent.c?rev=33933&r1=33932&r2=33933&view=diff
==============================================================================
--- trunk/channels/chan_agent.c (original)
+++ trunk/channels/chan_agent.c Tue Jun 13 15:59:15 2006
@@ -1334,12 +1334,13 @@
 	return chan;
 }
 
-static int powerof(unsigned int v)
-{
-	int x;
-	for (x=0;x<32;x++) {
-		if (v & (1 << x)) return x;
-	}
+static force_inline int powerof(unsigned int d)
+{
+	int x = ffs(d);
+
+	if (x)
+		return x - 1;
+
 	return 0;
 }
 

Modified: trunk/translate.c
URL: http://svn.digium.com/view/asterisk/trunk/translate.c?rev=33933&r1=33932&r2=33933&view=diff
==============================================================================
--- trunk/translate.c (original)
+++ trunk/translate.c Tue Jun 13 15:59:15 2006
@@ -74,13 +74,15 @@
  */
 
 /*! \brief returns the index of the lowest bit set */
-static int powerof(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);
+static force_inline int powerof(unsigned int d)
+{
+	int x = ffs(d);
+
+	if (x)
+		return x - 1;
+
+	ast_log(LOG_WARNING, "No bits set? %d\n", d);
+
 	return -1;
 }
 



More information about the svn-commits mailing list