2 * \brief log2comp.h - various base 2 log computation versions
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
18 # define inline __inline
19 #elif defined(__GNUC__)
20 # define inline __inline__
25 #if defined(WANT_ASM) && defined(_MSC_VER) && defined(_M_IX86)
27 # pragma warning( disable : 4035 )
28 static inline int ilog2(int val
) { __asm
34 # pragma warning( default : 4035 )
35 #elif defined(WANT_ASM) && defined(__GNUC__) && (defined(__i386__) || defined(i386))
37 static inline int ilog2(int val
)
52 #elif defined(WANT_ASM) && defined(__GNUC__) && defined(__powerpc__)
53 static inline int ilog2(int val
)
56 __asm__ ("cntlzw %0,%1"
63 /* no ASM for this compiler and/or platform */
64 /* rather slow base 2 log computation
67 static inline int ilog2(int val
)
70 for (i
= -1; val
; ++i
, val
>>= 1)