Use _BitScanReverse for EC_ILOG with MSVC.
Also updates the TI dsplib macros to use the same EC_CLZ mechanism as everything else.
This commit is contained in:
parent
1aaa50d1c1
commit
df2c71ea5a
1 changed files with 22 additions and 12 deletions
|
@ -83,17 +83,30 @@
|
||||||
/*Count leading zeros.
|
/*Count leading zeros.
|
||||||
This macro should only be used for implementing ec_ilog(), if it is defined.
|
This macro should only be used for implementing ec_ilog(), if it is defined.
|
||||||
All other code should use EC_ILOG() instead.*/
|
All other code should use EC_ILOG() instead.*/
|
||||||
#ifdef __GNUC_PREREQ
|
#if defined(_MSC_VER)
|
||||||
#if __GNUC_PREREQ(3,4)
|
# include <intrin.h>
|
||||||
# if INT_MAX>=2147483647
|
static __inline int ec_bsr(unsigned long _x){
|
||||||
# define EC_CLZ0 sizeof(unsigned)*CHAR_BIT
|
unsigned long ret;
|
||||||
# define EC_CLZ(_x) (__builtin_clz(_x))
|
_BitScanReverse(&ret,_x);
|
||||||
# elif LONG_MAX>=2147483647L
|
return (int)ret;
|
||||||
# define EC_CLZ0 sizeof(unsigned long)*CHAR_BIT
|
}
|
||||||
# define EC_CLZ(_x) (__builtin_clzl(_x))
|
# define EC_CLZ0 (1)
|
||||||
|
# define EC_CLZ(_x) (-ec_bsr(_x))
|
||||||
|
#elif defined(ENABLE_TI_DSPLIB)
|
||||||
|
# include "dsplib.h"
|
||||||
|
# define EC_CLZ0 (31)
|
||||||
|
# define EC_CLZ(_x) (_lnorm(x))
|
||||||
|
#elif defined(__GNUC_PREREQ)
|
||||||
|
# if __GNUC_PREREQ(3,4)
|
||||||
|
# if INT_MAX>=2147483647
|
||||||
|
# define EC_CLZ0 ((int)sizeof(unsigned)*CHAR_BIT)
|
||||||
|
# define EC_CLZ(_x) (__builtin_clz(_x))
|
||||||
|
# elif LONG_MAX>=2147483647L
|
||||||
|
# define EC_CLZ0 ((int)sizeof(unsigned long)*CHAR_BIT)
|
||||||
|
# define EC_CLZ(_x) (__builtin_clzl(_x))
|
||||||
|
# endif
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(EC_CLZ)
|
#if defined(EC_CLZ)
|
||||||
/*Note that __builtin_clz is not defined when _x==0, according to the gcc
|
/*Note that __builtin_clz is not defined when _x==0, according to the gcc
|
||||||
|
@ -101,9 +114,6 @@
|
||||||
The majority of the time we can never pass it zero.
|
The majority of the time we can never pass it zero.
|
||||||
When we need to, it can be special cased.*/
|
When we need to, it can be special cased.*/
|
||||||
# define EC_ILOG(_x) (EC_CLZ0-EC_CLZ(_x))
|
# define EC_ILOG(_x) (EC_CLZ0-EC_CLZ(_x))
|
||||||
#elif defined(ENABLE_TI_DSPLIB)
|
|
||||||
#include "dsplib.h"
|
|
||||||
#define EC_ILOG(x) (31 - _lnorm(x))
|
|
||||||
#else
|
#else
|
||||||
# define EC_ILOG(_x) (ec_ilog(_x))
|
# define EC_ILOG(_x) (ec_ilog(_x))
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue