msvc: add intrinsic based BitsLog2Floor

Change-Id: Ic0c7d2f03e300c6699e130916a759403e672f9d8
This commit is contained in:
James Zern 2012-06-19 15:36:06 -07:00
parent 8a69c7d8af
commit e1f769fe1c

View File

@ -37,6 +37,14 @@ extern "C" {
static WEBP_INLINE int BitsLog2Floor(uint32_t n) { static WEBP_INLINE int BitsLog2Floor(uint32_t n) {
return n == 0 ? -1 : 31 ^ __builtin_clz(n); return n == 0 ? -1 : 31 ^ __builtin_clz(n);
} }
#elif defined(_MSC_VER) && (defined(_M_X64) || defined(_M_IX86))
#include <intrin.h>
#pragma intrinsic(_BitScanReverse)
static WEBP_INLINE int BitsLog2Floor(uint32_t n) {
unsigned long first_set_bit;
return _BitScanReverse(&first_set_bit, n) ? first_set_bit : -1;
}
#else #else
static WEBP_INLINE int BitsLog2Floor(uint32_t n) { static WEBP_INLINE int BitsLog2Floor(uint32_t n) {
int log = 0; int log = 0;