Warn if configure gives invalid library dep info
[asterisk-bristuff.git] / codecs / log2comp.h
blobaa397c858f5426bbe1df0bcd652b76ed75db72a1
1 /*! \file
2 * \brief log2comp.h - various base 2 log computation versions
3 *
4 * Asterisk -- A telephony toolkit for Linux.
6 * \author Alex Volkov <codepro@usa.net>
8 * Copyright (c) 2004 - 2005, Digium Inc.
10 * This program is free software, distributed under the terms of
11 * the GNU General Public License
13 * Define WANT_ASM before including this file to use assembly
14 * whenever possible
17 #if defined(_MSC_VER)
18 # define inline __inline
19 #elif defined(__GNUC__)
20 # define inline __inline__
21 #else
22 # define inline
23 #endif
25 #if defined(WANT_ASM) && defined(_MSC_VER) && defined(_M_IX86)
26 /* MS C Inline Asm */
27 # pragma warning( disable : 4035 )
28 static inline int ilog2(int val) { __asm
30 xor eax, eax
31 dec eax
32 bsr eax, val
34 # pragma warning( default : 4035 )
35 #elif defined(WANT_ASM) && defined(__GNUC__) && (defined(__i386__) || defined(i386))
36 /* GNU Inline Asm */
37 static inline int ilog2(int val)
39 int a;
40 __asm__
41 ("\
42 xorl %0, %0 ;\
43 decl %0 ;\
44 bsrl %1, %0 ;\
46 : "=&r" (a)
47 : "mr" (val)
48 : "cc"
50 return a;
52 #elif defined(WANT_ASM) && defined(__GNUC__) && defined(__powerpc__)
53 static inline int ilog2(int val)
55 int a;
56 __asm__ ("cntlzw %0,%1"
57 : "=r" (a)
58 : "r" (val)
60 return 31-a;
62 #else
63 /* no ASM for this compiler and/or platform */
64 /* rather slow base 2 log computation
65 * Using looped shift.
67 static inline int ilog2(int val)
69 int i;
70 for (i = -1; val; ++i, val >>= 1)
72 return (i);
74 #endif