Use _BitScanForward and _BitScanReverse on MSVC

This commit is contained in:
Arkady Shapkin 2018-02-15 23:17:46 +03:00 committed by Behdad Esfahbod
parent 23d21a74b5
commit 6c10328eb8

View File

@ -51,6 +51,9 @@
#include <stdio.h>
#include <stdarg.h>
#if defined(_MSC_VER)
#include <intrin.h>
#endif
#define HB_PASTE1(a,b) a##b
#define HB_PASTE(a,b) HB_PASTE1(a,b)
@ -352,6 +355,10 @@ _hb_bit_storage (unsigned int number)
{
#if defined(__GNUC__) && (__GNUC__ >= 4) && defined(__OPTIMIZE__)
return likely (number) ? (sizeof (unsigned int) * 8 - __builtin_clz (number)) : 0;
#elif defined_MSC_VER) && defined(__OPTIMIZE__)
unsigned long where;
if (_BitScanReverse(&where, number)) return 1 + where;
return 0;
#else
unsigned int n_bits = 0;
while (number) {
@ -368,6 +375,11 @@ _hb_ctz (unsigned int number)
{
#if defined(__GNUC__) && (__GNUC__ >= 4) && defined(__OPTIMIZE__)
return likely (number) ? __builtin_ctz (number) : 0;
#elif defined_MSC_VER) && defined(__OPTIMIZE__)
unsigned long where;
if (_BitScanForward(&where, n)) return where;
return 0;
}
#else
unsigned int n_bits = 0;
if (unlikely (!number)) return 0;