Asterisk - The Open Source Telephony Project GIT-master-f36a736
log2comp.h
Go to the documentation of this file.
1/*! \file
2 * \brief log2comp.h - various base 2 log computation versions
3 *
4 * Asterisk -- An open source telephony toolkit.
5 *
6 * \author Alex Volkov <codepro@usa.net>
7 *
8 * Copyright (c) 2004 - 2005, Digium Inc.
9 *
10 * This program is free software, distributed under the terms of
11 * the GNU General Public License
12 *
13 * Define WANT_ASM before including this file to use assembly
14 * whenever possible
15 */
16
17#if defined(_MSC_VER)
18# define inline __inline
19#elif defined(__GNUC__)
20# define inline __inline__
21#else
22# define inline
23#endif
24
25#if defined(WANT_ASM) && defined(_MSC_VER) && defined(_M_IX86)
26/* MS C Inline Asm */
27# pragma warning( disable : 4035 )
28static inline int ilog2(int val) { __asm
29{
30 xor eax, eax
31 dec eax
32 bsr eax, val
33}}
34# pragma warning( default : 4035 )
35#elif defined(WANT_ASM) && defined(__GNUC__) && (defined(__i386__) || defined(i386))
36/* GNU Inline Asm */
37static inline int ilog2(int val)
38{
39 int a;
40 __asm__
41 ("\
42 xorl %0, %0 ;\
43 decl %0 ;\
44 bsrl %1, %0 ;\
45 "
46 : "=&r" (a)
47 : "mr" (val)
48 : "cc"
49 );
50 return a;
51}
52#elif defined(WANT_ASM) && defined(__GNUC__) && defined(__powerpc__)
53static inline int ilog2(int val)
54{
55 int a;
56 __asm__ ("cntlzw %0,%1"
57 : "=r" (a)
58 : "r" (val)
59 );
60 return 31-a;
61}
62#else
63/* no ASM for this compiler and/or platform */
64/* rather slow base 2 log computation
65 * Using looped shift.
66 */
67static inline int ilog2(int val)
68{
69 int i;
70 for (i = -1; val; ++i, val >>= 1)
71 ;
72 return (i);
73}
74#endif
static int ilog2(int val)
Definition: log2comp.h:67
Definition: ast_expr2.c:325
static struct test_val a