aboutsummaryrefslogtreecommitdiffstats
path: root/codecs
diff options
context:
space:
mode:
authorrussell <russell@f38db490-d61c-443f-a65b-d21fe96a405b>2004-11-15 04:32:12 +0000
committerrussell <russell@f38db490-d61c-443f-a65b-d21fe96a405b>2004-11-15 04:32:12 +0000
commitc1875c411bd87df73c70b5b7be884f862d1a0841 (patch)
treef6e7365229142c612047e805d48dc3f6d2b95e29 /codecs
parent4457633088eda96f43ff75b2496f1bd2d71533f5 (diff)
add missing file (bug #2843)
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@4254 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'codecs')
-rwxr-xr-xcodecs/log2comp.h63
1 files changed, 63 insertions, 0 deletions
diff --git a/codecs/log2comp.h b/codecs/log2comp.h
new file mode 100755
index 000000000..9f3924170
--- /dev/null
+++ b/codecs/log2comp.h
@@ -0,0 +1,63 @@
+/* log2comp.h - various base 2 log computation versions
+ *
+ * Asterisk -- A telephony toolkit for Linux.
+ *
+ * Implementation by Alex Volkov <codepro@usa.net>
+ *
+ * Copyright (c) 2004, Digium
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License
+ *
+ * Define WANT_ASM before including this file to use assembly
+ * whenever possible
+ */
+
+#if defined(_MSC_VER)
+# define inline __inline
+#elif defined(__GNUC__)
+# define inline __inline__
+#else
+# define inline
+#endif
+
+#if defined(WANT_ASM) && defined(_MSC_VER) && defined(_M_IX86)
+/* MS C Inline Asm */
+# pragma warning( disable : 4035 )
+static inline int log2(int val) { __asm
+{
+ xor eax, eax
+ dec eax
+ bsr eax, val
+}}
+# pragma warning( default : 4035 )
+#elif defined(WANT_ASM) && defined(__GNUC__) && (defined(__i386__) || defined(i386))
+/* GNU Inline Asm */
+static inline int log2(int val)
+{
+ int a;
+ __asm__
+ ("\
+ xorl %0, %0 ;\
+ decl %0 ;\
+ bsrl %1, %0 ;\
+ "
+ : "=r" (a)
+ : "mr" (val)
+ : "cc"
+ );
+ return a;
+}
+#else
+/* no ASM for this compiler and/or platform */
+/* rather slow base 2 log computation
+ * Using looped shift.
+ */
+static inline int log2(int val)
+{
+ int i;
+ for (i = -1; val; ++i, val >>= 1)
+ ;
+ return (i);
+}
+#endif