提交 6c10328e 编写于 作者: A Arkady Shapkin 提交者: Behdad Esfahbod

Use _BitScanForward and _BitScanReverse on MSVC

上级 23d21a74
......@@ -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;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册