diff options
author | robot-contrib <robot-contrib@yandex-team.com> | 2023-10-23 23:42:01 +0300 |
---|---|---|
committer | robot-contrib <robot-contrib@yandex-team.com> | 2023-10-24 00:04:36 +0300 |
commit | cc78b961ed847896c5d94fc564556e2db812df70 (patch) | |
tree | e3232d9376329099f75d97812a012e535ae695cb /contrib/libs/snappy/snappy-stubs-internal.h | |
parent | 34017dfc732950000ee19e1e6e48a0175dd2109f (diff) | |
download | ydb-cc78b961ed847896c5d94fc564556e2db812df70.tar.gz |
Update contrib/libs/snappy to 1.1.10
Diffstat (limited to 'contrib/libs/snappy/snappy-stubs-internal.h')
-rw-r--r-- | contrib/libs/snappy/snappy-stubs-internal.h | 81 |
1 files changed, 57 insertions, 24 deletions
diff --git a/contrib/libs/snappy/snappy-stubs-internal.h b/contrib/libs/snappy/snappy-stubs-internal.h index c2a838f38f..1548ed7ac7 100644 --- a/contrib/libs/snappy/snappy-stubs-internal.h +++ b/contrib/libs/snappy/snappy-stubs-internal.h @@ -31,7 +31,7 @@ #ifndef THIRD_PARTY_SNAPPY_OPENSOURCE_SNAPPY_STUBS_INTERNAL_H_ #define THIRD_PARTY_SNAPPY_OPENSOURCE_SNAPPY_STUBS_INTERNAL_H_ -#ifdef HAVE_CONFIG_H +#if HAVE_CONFIG_H #include "config.h" #endif @@ -43,11 +43,11 @@ #include <limits> #include <string> -#ifdef HAVE_SYS_MMAN_H +#if HAVE_SYS_MMAN_H #include <sys/mman.h> #endif -#ifdef HAVE_UNISTD_H +#if HAVE_UNISTD_H #include <unistd.h> #endif @@ -90,20 +90,20 @@ #define ARRAYSIZE(a) int{sizeof(a) / sizeof(*(a))} // Static prediction hints. -#ifdef HAVE_BUILTIN_EXPECT +#if HAVE_BUILTIN_EXPECT #define SNAPPY_PREDICT_FALSE(x) (__builtin_expect(x, 0)) #define SNAPPY_PREDICT_TRUE(x) (__builtin_expect(!!(x), 1)) #else #define SNAPPY_PREDICT_FALSE(x) x #define SNAPPY_PREDICT_TRUE(x) x -#endif +#endif // HAVE_BUILTIN_EXPECT // Inlining hints. -#ifdef HAVE_ATTRIBUTE_ALWAYS_INLINE +#if HAVE_ATTRIBUTE_ALWAYS_INLINE #define SNAPPY_ATTRIBUTE_ALWAYS_INLINE __attribute__((always_inline)) #else #define SNAPPY_ATTRIBUTE_ALWAYS_INLINE -#endif +#endif // HAVE_ATTRIBUTE_ALWAYS_INLINE // Stubbed version of ABSL_FLAG. // @@ -171,27 +171,42 @@ class LittleEndian { public: // Functions to do unaligned loads and stores in little-endian order. static inline uint16_t Load16(const void *ptr) { - const uint8_t* const buffer = reinterpret_cast<const uint8_t*>(ptr); - // Compiles to a single mov/str on recent clang and gcc. +#if SNAPPY_IS_BIG_ENDIAN + const uint8_t* const buffer = reinterpret_cast<const uint8_t*>(ptr); return (static_cast<uint16_t>(buffer[0])) | (static_cast<uint16_t>(buffer[1]) << 8); +#else + // memcpy() turns into a single instruction early in the optimization + // pipeline (relatively to a series of byte accesses). So, using memcpy + // instead of byte accesses may lead to better decisions in more stages of + // the optimization pipeline. + uint16_t value; + std::memcpy(&value, ptr, 2); + return value; +#endif } static inline uint32_t Load32(const void *ptr) { - const uint8_t* const buffer = reinterpret_cast<const uint8_t*>(ptr); - // Compiles to a single mov/str on recent clang and gcc. +#if SNAPPY_IS_BIG_ENDIAN + const uint8_t* const buffer = reinterpret_cast<const uint8_t*>(ptr); return (static_cast<uint32_t>(buffer[0])) | (static_cast<uint32_t>(buffer[1]) << 8) | (static_cast<uint32_t>(buffer[2]) << 16) | (static_cast<uint32_t>(buffer[3]) << 24); +#else + // See Load16() for the rationale of using memcpy(). + uint32_t value; + std::memcpy(&value, ptr, 4); + return value; +#endif } static inline uint64_t Load64(const void *ptr) { - const uint8_t* const buffer = reinterpret_cast<const uint8_t*>(ptr); - // Compiles to a single mov/str on recent clang and gcc. +#if SNAPPY_IS_BIG_ENDIAN + const uint8_t* const buffer = reinterpret_cast<const uint8_t*>(ptr); return (static_cast<uint64_t>(buffer[0])) | (static_cast<uint64_t>(buffer[1]) << 8) | (static_cast<uint64_t>(buffer[2]) << 16) | @@ -200,30 +215,44 @@ class LittleEndian { (static_cast<uint64_t>(buffer[5]) << 40) | (static_cast<uint64_t>(buffer[6]) << 48) | (static_cast<uint64_t>(buffer[7]) << 56); +#else + // See Load16() for the rationale of using memcpy(). + uint64_t value; + std::memcpy(&value, ptr, 8); + return value; +#endif } static inline void Store16(void *dst, uint16_t value) { - uint8_t* const buffer = reinterpret_cast<uint8_t*>(dst); - // Compiles to a single mov/str on recent clang and gcc. +#if SNAPPY_IS_BIG_ENDIAN + uint8_t* const buffer = reinterpret_cast<uint8_t*>(dst); buffer[0] = static_cast<uint8_t>(value); buffer[1] = static_cast<uint8_t>(value >> 8); +#else + // See Load16() for the rationale of using memcpy(). + std::memcpy(dst, &value, 2); +#endif } static void Store32(void *dst, uint32_t value) { - uint8_t* const buffer = reinterpret_cast<uint8_t*>(dst); - // Compiles to a single mov/str on recent clang and gcc. +#if SNAPPY_IS_BIG_ENDIAN + uint8_t* const buffer = reinterpret_cast<uint8_t*>(dst); buffer[0] = static_cast<uint8_t>(value); buffer[1] = static_cast<uint8_t>(value >> 8); buffer[2] = static_cast<uint8_t>(value >> 16); buffer[3] = static_cast<uint8_t>(value >> 24); +#else + // See Load16() for the rationale of using memcpy(). + std::memcpy(dst, &value, 4); +#endif } static void Store64(void* dst, uint64_t value) { - uint8_t* const buffer = reinterpret_cast<uint8_t*>(dst); - // Compiles to a single mov/str on recent clang and gcc. +#if SNAPPY_IS_BIG_ENDIAN + uint8_t* const buffer = reinterpret_cast<uint8_t*>(dst); buffer[0] = static_cast<uint8_t>(value); buffer[1] = static_cast<uint8_t>(value >> 8); buffer[2] = static_cast<uint8_t>(value >> 16); @@ -232,14 +261,18 @@ class LittleEndian { buffer[5] = static_cast<uint8_t>(value >> 40); buffer[6] = static_cast<uint8_t>(value >> 48); buffer[7] = static_cast<uint8_t>(value >> 56); +#else + // See Load16() for the rationale of using memcpy(). + std::memcpy(dst, &value, 8); +#endif } static inline constexpr bool IsLittleEndian() { -#if defined(SNAPPY_IS_BIG_ENDIAN) +#if SNAPPY_IS_BIG_ENDIAN return false; #else return true; -#endif // defined(SNAPPY_IS_BIG_ENDIAN) +#endif // SNAPPY_IS_BIG_ENDIAN } }; @@ -265,7 +298,7 @@ class Bits { void operator=(const Bits&); }; -#if defined(HAVE_BUILTIN_CTZ) +#if HAVE_BUILTIN_CTZ inline int Bits::Log2FloorNonZero(uint32_t n) { assert(n != 0); @@ -354,7 +387,7 @@ inline int Bits::FindLSBSetNonZero(uint32_t n) { #endif // End portable versions. -#if defined(HAVE_BUILTIN_CTZ) +#if HAVE_BUILTIN_CTZ inline int Bits::FindLSBSetNonZero64(uint64_t n) { assert(n != 0); @@ -388,7 +421,7 @@ inline int Bits::FindLSBSetNonZero64(uint64_t n) { } } -#endif // End portable version. +#endif // HAVE_BUILTIN_CTZ // Variable-length integer encoding. class Varint { |