diff options
Diffstat (limited to 'src/google/protobuf/stubs/port.h')
-rw-r--r-- | src/google/protobuf/stubs/port.h | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/src/google/protobuf/stubs/port.h b/src/google/protobuf/stubs/port.h index ca9a1501..dbc29861 100644 --- a/src/google/protobuf/stubs/port.h +++ b/src/google/protobuf/stubs/port.h @@ -252,9 +252,15 @@ static const uint64 kuint64max = GOOGLE_ULONGLONG(0xFFFFFFFFFFFFFFFF); #define GOOGLE_GUARDED_BY(x) #define GOOGLE_ATTRIBUTE_COLD +#ifdef GOOGLE_PROTOBUF_DONT_USE_UNALIGNED +# define GOOGLE_PROTOBUF_USE_UNALIGNED 0 +#else // x86 and x86-64 can perform unaligned loads/stores directly. -#if defined(_M_X64) || defined(__x86_64__) || \ - defined(_M_IX86) || defined(__i386__) +# define GOOGLE_PROTOBUF_USE_UNALIGNED defined(_M_X64) || \ + defined(__x86_64__) || defined(_M_IX86) || defined(__i386__) +#endif + +#if GOOGLE_PROTOBUF_USE_UNALIGNED #define GOOGLE_UNALIGNED_LOAD16(_p) (*reinterpret_cast<const uint16 *>(_p)) #define GOOGLE_UNALIGNED_LOAD32(_p) (*reinterpret_cast<const uint32 *>(_p)) @@ -348,7 +354,7 @@ class Bits { public: static uint32 Log2FloorNonZero(uint32 n) { #if defined(__GNUC__) - return 31 ^ __builtin_clz(n); + return 31 ^ static_cast<uint32>(__builtin_clz(n)); #elif defined(COMPILER_MSVC) && defined(_M_IX86) _asm { bsr ebx, n @@ -367,7 +373,7 @@ class Bits { // To work around this, when we build for NaCl we use the portable // implementation instead. #if defined(__GNUC__) && !defined(GOOGLE_PROTOBUF_OS_NACL) - return 63 ^ __builtin_clzll(n); + return 63 ^ static_cast<uint32>(__builtin_clzll(n)); #else return Log2FloorNonZero64_Portable(n); #endif @@ -394,9 +400,9 @@ class Bits { const uint32 topbits = static_cast<uint32>(n >> 32); if (topbits == 0) { // Top bits are zero, so scan in bottom bits - return Log2FloorNonZero(static_cast<uint32>(n)); + return static_cast<int>(Log2FloorNonZero(static_cast<uint32>(n))); } else { - return 32 + Log2FloorNonZero(topbits); + return 32 + static_cast<int>(Log2FloorNonZero(topbits)); } } }; |