diff options
author | Feng Xiao <xfxyjwf@gmail.com> | 2018-03-14 13:22:01 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-03-14 13:22:01 -0700 |
commit | d5f5725c0a57913fe7842f49522b9e64c6dae525 (patch) | |
tree | 547e8ef4c3cfd132c2faf7e31ad36bda16ad486f | |
parent | 89b5333ad0f10058d5af62701c5ebea0db376c5b (diff) | |
parent | 22c477d91051f029d96b2078e41b74a15135cc58 (diff) | |
download | protobuf-d5f5725c0a57913fe7842f49522b9e64c6dae525.tar.gz protobuf-d5f5725c0a57913fe7842f49522b9e64c6dae525.tar.bz2 protobuf-d5f5725c0a57913fe7842f49522b9e64c6dae525.zip |
Merge pull request #4310 from KindDragon/patch-1
Support using MSVC intrinsics in Log2FloorNonZero
-rw-r--r-- | src/google/protobuf/stubs/port.h | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/src/google/protobuf/stubs/port.h b/src/google/protobuf/stubs/port.h index 27849298..4597c6cf 100644 --- a/src/google/protobuf/stubs/port.h +++ b/src/google/protobuf/stubs/port.h @@ -91,6 +91,7 @@ // These #includes are for the byte swap functions declared later on. #ifdef _MSC_VER #include <stdlib.h> // NOLINT(build/include) +#include <intrin.h> #elif defined(__APPLE__) #include <libkern/OSByteOrder.h> #elif defined(__GLIBC__) || defined(__CYGWIN__) @@ -394,12 +395,10 @@ class Bits { static uint32 Log2FloorNonZero(uint32 n) { #if defined(__GNUC__) return 31 ^ static_cast<uint32>(__builtin_clz(n)); -#elif defined(COMPILER_MSVC) && defined(_M_IX86) - _asm { - bsr ebx, n - mov n, ebx - } - return n; +#elif defined(_MSC_VER) + unsigned long where; + _BitScanReverse(&where, n); + return where; #else return Log2FloorNonZero_Portable(n); #endif @@ -414,6 +413,10 @@ class Bits { // implementation instead. #if defined(__GNUC__) && !defined(GOOGLE_PROTOBUF_USE_PORTABLE_LOG2) return 63 ^ static_cast<uint32>(__builtin_clzll(n)); +#elif defined(_MSC_VER) && defined(_M_X64) + unsigned long where; + _BitScanReverse64(&where, n); + return where; #else return Log2FloorNonZero64_Portable(n); #endif |