asterisk/codecs/log2comp.h
Jason Parker 56bddc2a0d Merged revisions 109648 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.4

........
r109648 | qwell | 2008-03-18 14:23:44 -0500 (Tue, 18 Mar 2008) | 7 lines

Allow codecs that use log2comp (g726) to compile correctly on x86 with gcc4 optimizations.

(closes issue #12253)
Reported by: fossil
Patches:
      log2comp.patch uploaded by fossil (license 140)

........


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@109651 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-18 19:24:15 +00:00

75 lines
1.4 KiB
C

/*! \file
* \brief log2comp.h - various base 2 log computation versions
*
* Asterisk -- A telephony toolkit for Linux.
*
* \author Alex Volkov <codepro@usa.net>
*
* Copyright (c) 2004 - 2005, Digium Inc.
*
* 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 ilog2(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 ilog2(int val)
{
int a;
__asm__
("\
xorl %0, %0 ;\
decl %0 ;\
bsrl %1, %0 ;\
"
: "=&r" (a)
: "mr" (val)
: "cc"
);
return a;
}
#elif defined(WANT_ASM) && defined(__GNUC__) && defined(__powerpc__)
static inline int ilog2(int val)
{
int a;
__asm__ ("cntlzw %0,%1"
: "=r" (a)
: "r" (val)
);
return 31-a;
}
#else
/* no ASM for this compiler and/or platform */
/* rather slow base 2 log computation
* Using looped shift.
*/
static inline int ilog2(int val)
{
int i;
for (i = -1; val; ++i, val >>= 1)
;
return (i);
}
#endif