diff options
-rw-r--r-- | CMakeLists.txt | 5 | ||||
-rw-r--r-- | cmake/config.h.in | 6 | ||||
-rw-r--r-- | snappy-internal.h | 3 | ||||
-rw-r--r-- | snappy-stubs-internal.h | 35 |
4 files changed, 26 insertions, 23 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index e9e70c8..2a90a08 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,10 +8,7 @@ option(BUILD_SHARED_LIBS "Build shared libraries(DLLs)." OFF) option(SNAPPY_BUILD_TESTS "Build Snappy's own tests." ON) include(TestBigEndian) -test_big_endian(WORDS_BIG_ENDIAN) -if(WORDS_BIG_ENDIAN) - add_definitions(-DWORDS_BIGENDIAN=1) -endif(WORDS_BIG_ENDIAN) +test_big_endian(SNAPPY_IS_BIG_ENDIAN) include(CheckIncludeFile) check_include_file("byteswap.h" HAVE_BYTESWAP_H) diff --git a/cmake/config.h.in b/cmake/config.h.in index 64f2648..97cd818 100644 --- a/cmake/config.h.in +++ b/cmake/config.h.in @@ -55,8 +55,8 @@ /* Define to 1 if you have the <windows.h> header file. */ #cmakedefine HAVE_WINDOWS_H 1 -/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most - significant byte first (like Motorola and SPARC, unlike Intel and VAX). */ -#cmakedefine WORDS_BIGENDIAN 1 +/* Define to 1 if your processor stores words with the most significant byte + first (like Motorola and SPARC, unlike Intel and VAX). */ +#cmakedefine SNAPPY_IS_BIG_ENDIAN 1 #endif // THIRD_PARTY_SNAPPY_OPENSOURCE_CMAKE_CONFIG_H_ diff --git a/snappy-internal.h b/snappy-internal.h index c12637d..4b53d59 100644 --- a/snappy-internal.h +++ b/snappy-internal.h @@ -83,7 +83,8 @@ char* CompressFragment(const char* input, // Requires that s2_limit >= s2. // // Separate implementation for 64-bit, little-endian cpus. -#if defined(ARCH_K8) || (defined(ARCH_PPC) && !defined(WORDS_BIGENDIAN)) +#if !defined(SNAPPY_IS_BIG_ENDIAN) && \ + (defined(ARCH_K8) || defined(ARCH_PPC) || defined(ARCH_ARM)) static inline std::pair<size_t, bool> FindMatchLength(const char* s1, const char* s2, const char* s2_limit) { diff --git a/snappy-stubs-internal.h b/snappy-stubs-internal.h index 9898f18..cb605f8 100644 --- a/snappy-stubs-internal.h +++ b/snappy-stubs-internal.h @@ -64,6 +64,10 @@ #define ARCH_PPC 1 +#elif defined(__aarch64__) + +#define ARCH_ARM 1 + #endif // Needed by OS X, among others. @@ -104,9 +108,10 @@ static const int64 kint64max = static_cast<int64>(0x7FFFFFFFFFFFFFFFLL); // Potentially unaligned loads and stores. -// x86 and PowerPC can simply do these loads and stores native. +// x86, PowerPC, and ARM64 can simply do these loads and stores native. -#if defined(__i386__) || defined(__x86_64__) || defined(__powerpc__) +#if defined(__i386__) || defined(__x86_64__) || defined(__powerpc__) || \ + defined(__aarch64__) #define UNALIGNED_LOAD16(_p) (*reinterpret_cast<const uint16 *>(_p)) #define UNALIGNED_LOAD32(_p) (*reinterpret_cast<const uint32 *>(_p)) @@ -234,7 +239,7 @@ inline void UNALIGNED_STORE64(void *p, uint64 v) { #endif // The following guarantees declaration of the byte swap functions. -#ifdef WORDS_BIGENDIAN +#if defined(SNAPPY_IS_BIG_ENDIAN) #ifdef HAVE_SYS_BYTEORDER_H #include <sys/byteorder.h> @@ -291,7 +296,7 @@ inline uint64 bswap_64(uint64 x) { #endif -#endif // WORDS_BIGENDIAN +#endif // defined(SNAPPY_IS_BIG_ENDIAN) // Convert to little-endian storage, opposite of network format. // Convert x from host to little endian: x = LittleEndian.FromHost(x); @@ -305,7 +310,7 @@ inline uint64 bswap_64(uint64 x) { class LittleEndian { public: // Conversion functions. -#ifdef WORDS_BIGENDIAN +#if defined(SNAPPY_IS_BIG_ENDIAN) static uint16 FromHost16(uint16 x) { return bswap_16(x); } static uint16 ToHost16(uint16 x) { return bswap_16(x); } @@ -315,7 +320,7 @@ class LittleEndian { static bool IsLittleEndian() { return false; } -#else // !defined(WORDS_BIGENDIAN) +#else // !defined(SNAPPY_IS_BIG_ENDIAN) static uint16 FromHost16(uint16 x) { return x; } static uint16 ToHost16(uint16 x) { return x; } @@ -325,7 +330,7 @@ class LittleEndian { static bool IsLittleEndian() { return true; } -#endif // !defined(WORDS_BIGENDIAN) +#endif // !defined(SNAPPY_IS_BIG_ENDIAN) // Functions to do unaligned loads and stores in little-endian order. static uint16 Load16(const void *p) { @@ -356,9 +361,9 @@ class Bits { // that it's 0-indexed. static int FindLSBSetNonZero(uint32 n); -#if defined(ARCH_K8) || defined(ARCH_PPC) +#if defined(ARCH_K8) || defined(ARCH_PPC) || defined(ARCH_ARM) static int FindLSBSetNonZero64(uint64 n); -#endif // defined(ARCH_K8) || defined(ARCH_PPC) +#endif // defined(ARCH_K8) || defined(ARCH_PPC) || defined(ARCH_ARM) private: // No copying @@ -376,11 +381,11 @@ inline int Bits::FindLSBSetNonZero(uint32 n) { return __builtin_ctz(n); } -#if defined(ARCH_K8) || defined(ARCH_PPC) +#if defined(ARCH_K8) || defined(ARCH_PPC) || defined(ARCH_ARM) inline int Bits::FindLSBSetNonZero64(uint64 n) { return __builtin_ctzll(n); } -#endif // defined(ARCH_K8) || defined(ARCH_PPC) +#endif // defined(ARCH_K8) || defined(ARCH_PPC) || defined(ARCH_ARM) #elif defined(_MSC_VER) @@ -399,13 +404,13 @@ inline int Bits::FindLSBSetNonZero(uint32 n) { return 32; } -#if defined(ARCH_K8) || defined(ARCH_PPC) +#if defined(ARCH_K8) || defined(ARCH_PPC) || defined(ARCH_ARM) inline int Bits::FindLSBSetNonZero64(uint64 n) { unsigned long where; if (_BitScanForward64(&where, n)) return static_cast<int>(where); return 64; } -#endif // defined(ARCH_K8) || defined(ARCH_PPC) +#endif // defined(ARCH_K8) || defined(ARCH_PPC) || defined(ARCH_ARM) #else // Portable versions. @@ -439,7 +444,7 @@ inline int Bits::FindLSBSetNonZero(uint32 n) { return rc; } -#if defined(ARCH_K8) || defined(ARCH_PPC) +#if defined(ARCH_K8) || defined(ARCH_PPC) || defined(ARCH_ARM) // FindLSBSetNonZero64() is defined in terms of FindLSBSetNonZero(). inline int Bits::FindLSBSetNonZero64(uint64 n) { const uint32 bottombits = static_cast<uint32>(n); @@ -450,7 +455,7 @@ inline int Bits::FindLSBSetNonZero64(uint64 n) { return FindLSBSetNonZero(bottombits); } } -#endif // defined(ARCH_K8) || defined(ARCH_PPC) +#endif // defined(ARCH_K8) || defined(ARCH_PPC) || defined(ARCH_ARM) #endif // End portable versions. |