Index: third_party/protobuf/src/google/protobuf/stubs/port.h |
diff --git a/third_party/protobuf/src/google/protobuf/stubs/port.h b/third_party/protobuf/src/google/protobuf/stubs/port.h |
index 80e60746531404a403c89661e3ff683034fddbbe..d1e5bee0a4aff09d5bb20d4a0700496f67a41703 100644 |
--- a/third_party/protobuf/src/google/protobuf/stubs/port.h |
+++ b/third_party/protobuf/src/google/protobuf/stubs/port.h |
@@ -60,8 +60,12 @@ |
#endif |
#else |
#include <sys/param.h> // __BYTE_ORDER |
+ #if defined(__OpenBSD__) |
+ #include <endian.h> |
+ #endif |
#if ((defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__)) || \ |
- (defined(__BYTE_ORDER) && __BYTE_ORDER == __LITTLE_ENDIAN)) && \ |
+ (defined(__BYTE_ORDER) && __BYTE_ORDER == __LITTLE_ENDIAN) || \ |
+ (defined(BYTE_ORDER) && BYTE_ORDER == LITTLE_ENDIAN)) && \ |
!defined(PROTOBUF_DISABLE_LITTLE_ENDIAN_OPT_FOR_TEST) |
#define PROTOBUF_LITTLE_ENDIAN 1 |
#endif |
@@ -125,12 +129,12 @@ typedef unsigned __int16 uint16; |
typedef unsigned __int32 uint32; |
typedef unsigned __int64 uint64; |
#else |
-typedef int8_t int8; |
+typedef int8_t int8; |
typedef int16_t int16; |
typedef int32_t int32; |
typedef int64_t int64; |
-typedef uint8_t uint8; |
+typedef uint8_t uint8; |
typedef uint16_t uint16; |
typedef uint32_t uint32; |
typedef uint64_t uint64; |
@@ -147,8 +151,10 @@ typedef uint64_t uint64; |
#define GOOGLE_ULONGLONG(x) x##UI64 |
#define GOOGLE_LL_FORMAT "I64" // As in printf("%I64d", ...) |
#else |
+// By long long, we actually mean int64. |
#define GOOGLE_LONGLONG(x) INT64_C(x) |
#define GOOGLE_ULONGLONG(x) UINT64_C(x) |
+// Used to format real long long integers. |
#define GOOGLE_LL_FORMAT "ll" // As in "%lld". Note that "q" is poor form also. |
#endif |
@@ -190,6 +196,15 @@ static const uint64 kuint64max = GOOGLE_ULONGLONG(0xFFFFFFFFFFFFFFFF); |
#endif |
#endif |
+#ifndef GOOGLE_ATTRIBUTE_NORETURN |
+#ifdef __GNUC__ |
+// Tell the compiler that a given function never returns. |
+#define GOOGLE_ATTRIBUTE_NORETURN __attribute__((noreturn)) |
+#else |
+#define GOOGLE_ATTRIBUTE_NORETURN |
+#endif |
+#endif |
+ |
#ifndef GOOGLE_ATTRIBUTE_DEPRECATED |
#ifdef __GNUC__ |
// If the method/variable/type is used anywhere, produce a warning. |
@@ -292,10 +307,8 @@ inline void GOOGLE_UNALIGNED_STORE64(void *p, uint64 v) { |
#define GOOGLE_THREAD_LOCAL __thread |
#endif |
-// The following guarantees declaration of the byte swap functions, and |
-// defines __BYTE_ORDER for MSVC |
+// The following guarantees declaration of the byte swap functions. |
#ifdef _MSC_VER |
-#define __BYTE_ORDER __LITTLE_ENDIAN |
#define bswap_16(x) _byteswap_ushort(x) |
#define bswap_32(x) _byteswap_ulong(x) |
#define bswap_64(x) _byteswap_uint64(x) |
@@ -334,6 +347,61 @@ static inline uint64 bswap_64(uint64 x) { |
#endif |
// =================================================================== |
+// from google3/util/bits/bits.h |
+ |
+class Bits { |
+ public: |
+ static uint32 Log2FloorNonZero(uint32 n) { |
+#if defined(__GNUC__) |
+ return 31 ^ __builtin_clz(n); |
+#elif defined(COMPILER_MSVC) && defined(_M_IX86) |
+ _asm { |
+ bsr ebx, n |
+ mov n, ebx |
+ } |
+ return n; |
+#else |
+ return Log2FloorNonZero_Portable(n); |
+#endif |
+ } |
+ |
+ static uint64 Log2FloorNonZero64(uint64 n) { |
+#if defined(__GNUC__) |
+ return 63 ^ __builtin_clzll(n); |
+#else |
+ return Log2FloorNonZero64_Portable(n); |
+#endif |
+ } |
+ private: |
+ static int Log2FloorNonZero_Portable(uint32 n) { |
+ if (n == 0) |
+ return -1; |
+ int log = 0; |
+ uint32 value = n; |
+ for (int i = 4; i >= 0; --i) { |
+ int shift = (1 << i); |
+ uint32 x = value >> shift; |
+ if (x != 0) { |
+ value = x; |
+ log += shift; |
+ } |
+ } |
+ assert(value == 1); |
+ return log; |
+ } |
+ |
+ static int Log2FloorNonZero64_Portable(uint64 n) { |
+ 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)); |
+ } else { |
+ return 32 + Log2FloorNonZero(topbits); |
+ } |
+ } |
+}; |
+ |
+// =================================================================== |
// from google3/util/endian/endian.h |
LIBPROTOBUF_EXPORT uint32 ghtonl(uint32 x); |