Clean up port_def.inc by inlining BSWAP macros that are only used once.

PiperOrigin-RevId: 631130592
pull/16751/head
Protobuf Team Bot 9 months ago committed by Copybara-Service
parent e03c1ce349
commit e949bba22a
  1. 14
      src/google/protobuf/endian.h
  2. 21
      src/google/protobuf/port_def.inc
  3. 3
      src/google/protobuf/port_undef.inc

@ -14,6 +14,8 @@
#include <cstdint>
#include "absl/base/config.h"
// Must be included last.
#include "google/protobuf/port_def.inc"
@ -22,8 +24,8 @@ namespace protobuf {
namespace internal {
inline uint64_t BSwap64(uint64_t host_int) {
#if defined(PROTOBUF_BUILTIN_BSWAP64)
return PROTOBUF_BUILTIN_BSWAP64(host_int);
#if defined(__GNUC__) || ABSL_HAVE_BUILTIN(__builtin_bswap64)
return __builtin_bswap64(host_int);
#elif defined(_MSC_VER)
return _byteswap_uint64(host_int);
#else
@ -39,8 +41,8 @@ inline uint64_t BSwap64(uint64_t host_int) {
}
inline uint32_t BSwap32(uint32_t host_int) {
#if defined(PROTOBUF_BUILTIN_BSWAP32)
return PROTOBUF_BUILTIN_BSWAP32(host_int);
#if defined(__GNUC__) || ABSL_HAVE_BUILTIN(__builtin_bswap32)
return __builtin_bswap32(host_int);
#elif defined(_MSC_VER)
return _byteswap_ulong(host_int);
#else
@ -52,8 +54,8 @@ inline uint32_t BSwap32(uint32_t host_int) {
}
inline uint16_t BSwap16(uint16_t host_int) {
#if defined(PROTOBUF_BUILTIN_BSWAP16)
return PROTOBUF_BUILTIN_BSWAP16(host_int);
#if defined(__GNUC__) || ABSL_HAVE_BUILTIN(__builtin_bswap16)
return __builtin_bswap16(host_int);
#elif defined(_MSC_VER)
return _byteswap_ushort(host_int);
#else

@ -67,27 +67,6 @@
// - MSVC: https://docs.microsoft.com/en-us/visualstudio/releases/2019/release-notes-history
// https://docs.microsoft.com/en-us/visualstudio/releasenotes/vs2017-relnotes-history
// Portable PROTOBUF_BUILTIN_BSWAPxx definitions
// Code must check for availability, e.g.: `defined(PROTOBUF_BUILTIN_BSWAP32)`
#ifdef PROTOBUF_BUILTIN_BSWAP16
#error PROTOBUF_BUILTIN_BSWAP16 was previously defined
#endif
#ifdef PROTOBUF_BUILTIN_BSWAP32
#error PROTOBUF_BUILTIN_BSWAP32 was previously defined
#endif
#ifdef PROTOBUF_BUILTIN_BSWAP64
#error PROTOBUF_BUILTIN_BSWAP64 was previously defined
#endif
#if defined(__GNUC__) || ABSL_HAVE_BUILTIN(__builtin_bswap16)
#define PROTOBUF_BUILTIN_BSWAP16(x) __builtin_bswap16(x)
#endif
#if defined(__GNUC__) || ABSL_HAVE_BUILTIN(__builtin_bswap32)
#define PROTOBUF_BUILTIN_BSWAP32(x) __builtin_bswap32(x)
#endif
#if defined(__GNUC__) || ABSL_HAVE_BUILTIN(__builtin_bswap64)
#define PROTOBUF_BUILTIN_BSWAP64(x) __builtin_bswap64(x)
#endif
// Portable check for gcc-style atomic built-ins
#if ABSL_HAVE_BUILTIN(__atomic_load_n)
#define PROTOBUF_BUILTIN_ATOMIC 1

@ -16,9 +16,6 @@
#undef PROTOBUF_POISON_MEMORY_REGION
#undef PROTOBUF_UNPOISON_MEMORY_REGION
#undef PROTOBUF_BUILTIN_BSWAP16
#undef PROTOBUF_BUILTIN_BSWAP32
#undef PROTOBUF_BUILTIN_BSWAP64
#undef PROTOBUF_BUILTIN_ATOMIC
#undef PROTOBUF_GNUC_MIN
#undef PROTOBUF_CLANG_MIN

Loading…
Cancel
Save