diff --git a/CMakeLists.txt b/CMakeLists.txt index e0b8e7c..d35fbaf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -69,9 +69,6 @@ option(CRC32C_BUILD_BENCHMARKS "Build CRC32C's benchmarks" ON) option(CRC32C_USE_GLOG "Build CRC32C's tests with Google Logging" ON) option(CRC32C_INSTALL "Install CRC32C's header and library" ON) -include(TestBigEndian) -test_big_endian(BYTE_ORDER_BIG_ENDIAN) - include(CheckCXXCompilerFlag) # Used by glog. check_cxx_compiler_flag(-Wno-deprecated CRC32C_HAVE_NO_DEPRECATED) diff --git a/src/crc32c_config.h.in b/src/crc32c_config.h.in index 4034fa5..d3aa7fa 100644 --- a/src/crc32c_config.h.in +++ b/src/crc32c_config.h.in @@ -5,9 +5,6 @@ #ifndef CRC32C_CRC32C_CONFIG_H_ #define CRC32C_CRC32C_CONFIG_H_ -// Define to 1 if building for a big-endian platform. -#cmakedefine01 BYTE_ORDER_BIG_ENDIAN - // Define to 1 if the compiler has the __builtin_prefetch intrinsic. #cmakedefine01 HAVE_BUILTIN_PREFETCH diff --git a/src/crc32c_read_le.h b/src/crc32c_read_le.h index bb2231e..0ce1ab0 100644 --- a/src/crc32c_read_le.h +++ b/src/crc32c_read_le.h @@ -8,48 +8,32 @@ #include #include -#include "crc32c/crc32c_config.h" - namespace crc32c { // Reads a little-endian 16-bit integer from bytes, not necessarily aligned. inline uint16_t ReadUint16LE(const uint8_t* buffer) { -#if BYTE_ORDER_BIG_ENDIAN - return ((uint16_t{buffer[0]}) | (uint16_t{buffer[1]} << 8)); -#else // !BYTE_ORDER_BIG_ENDIAN - uint16_t result; - // This should be optimized to a single instruction. - std::memcpy(&result, buffer, sizeof(result)); - return result; -#endif // BYTE_ORDER_BIG_ENDIAN + return ((static_cast(static_cast(buffer[0]))) | + (static_cast(static_cast(buffer[1])) << 8)); } // Reads a little-endian 32-bit integer from bytes, not necessarily aligned. inline uint32_t ReadUint32LE(const uint8_t* buffer) { -#if BYTE_ORDER_BIG_ENDIAN - return ((uint32_t{buffer[0]}) | (uint32_t{buffer[1]} << 8) | - (uint32_t{buffer[2]} << 16) | (uint32_t{buffer[3]} << 24)); -#else // !BYTE_ORDER_BIG_ENDIAN - uint32_t result; - // This should be optimized to a single instruction. - std::memcpy(&result, buffer, sizeof(result)); - return result; -#endif // BYTE_ORDER_BIG_ENDIAN + return ((static_cast(static_cast(buffer[0]))) | + (static_cast(static_cast(buffer[1])) << 8) | + (static_cast(static_cast(buffer[2])) << 16) | + (static_cast(static_cast(buffer[3])) << 24)); } // Reads a little-endian 64-bit integer from bytes, not necessarily aligned. inline uint64_t ReadUint64LE(const uint8_t* buffer) { -#if BYTE_ORDER_BIG_ENDIAN - return ((uint64_t{buffer[0]}) | (uint64_t{buffer[1]} << 8) | - (uint64_t{buffer[2]} << 16) | (uint64_t{buffer[3]} << 24) | - (uint64_t{buffer[4]} << 32) | (uint64_t{buffer[5]} << 40) | - (uint64_t{buffer[6]} << 48) | (uint64_t{buffer[7]} << 56)); -#else // !BYTE_ORDER_BIG_ENDIAN - uint64_t result; - // This should be optimized to a single instruction. - std::memcpy(&result, buffer, sizeof(result)); - return result; -#endif // BYTE_ORDER_BIG_ENDIAN + return ((static_cast(static_cast(buffer[0]))) | + (static_cast(static_cast(buffer[1])) << 8) | + (static_cast(static_cast(buffer[2])) << 16) | + (static_cast(static_cast(buffer[3])) << 24) | + (static_cast(static_cast(buffer[4])) << 32) | + (static_cast(static_cast(buffer[5])) << 40) | + (static_cast(static_cast(buffer[6])) << 48) | + (static_cast(static_cast(buffer[7])) << 56)); } } // namespace crc32c