Skip to content

Commit dfc289c

Browse files
committed
build: Drop endianess workaround
This mirrors a change in leveldb: google/leveldb@201f522, now that compilers can better optimise the generic code.
1 parent b60d2b7 commit dfc289c

File tree

3 files changed

+0
-24
lines changed

3 files changed

+0
-24
lines changed

CMakeLists.txt

-3
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,6 @@ option(CRC32C_BUILD_BENCHMARKS "Build CRC32C's benchmarks" ON)
6969
option(CRC32C_USE_GLOG "Build CRC32C's tests with Google Logging" ON)
7070
option(CRC32C_INSTALL "Install CRC32C's header and library" ON)
7171

72-
include(TestBigEndian)
73-
test_big_endian(BYTE_ORDER_BIG_ENDIAN)
74-
7572
include(CheckCXXCompilerFlag)
7673
# Used by glog.
7774
check_cxx_compiler_flag(-Wno-deprecated CRC32C_HAVE_NO_DEPRECATED)

src/crc32c_config.h.in

-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55
#ifndef CRC32C_CRC32C_CONFIG_H_
66
#define CRC32C_CRC32C_CONFIG_H_
77

8-
// Define to 1 if building for a big-endian platform.
9-
#cmakedefine01 BYTE_ORDER_BIG_ENDIAN
10-
118
// Define to 1 if the compiler has the __builtin_prefetch intrinsic.
129
#cmakedefine01 HAVE_BUILTIN_PREFETCH
1310

src/crc32c_read_le.h

-18
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,18 @@
88
#include <cstdint>
99
#include <cstring>
1010

11-
#ifdef CRC32C_HAVE_CONFIG_H
12-
#include "crc32c/crc32c_config.h"
13-
#endif
14-
1511
namespace crc32c {
1612

1713
// Reads a little-endian 32-bit integer from a 32-bit-aligned buffer.
1814
inline uint32_t ReadUint32LE(const uint8_t* buffer) {
19-
#if BYTE_ORDER_BIG_ENDIAN
2015
return ((static_cast<uint32_t>(static_cast<uint8_t>(buffer[0]))) |
2116
(static_cast<uint32_t>(static_cast<uint8_t>(buffer[1])) << 8) |
2217
(static_cast<uint32_t>(static_cast<uint8_t>(buffer[2])) << 16) |
2318
(static_cast<uint32_t>(static_cast<uint8_t>(buffer[3])) << 24));
24-
#else // !BYTE_ORDER_BIG_ENDIAN
25-
uint32_t result;
26-
// This should be optimized to a single instruction.
27-
std::memcpy(&result, buffer, sizeof(result));
28-
return result;
29-
#endif // BYTE_ORDER_BIG_ENDIAN
3019
}
3120

3221
// Reads a little-endian 64-bit integer from a 64-bit-aligned buffer.
3322
inline uint64_t ReadUint64LE(const uint8_t* buffer) {
34-
#if BYTE_ORDER_BIG_ENDIAN
3523
return ((static_cast<uint64_t>(static_cast<uint8_t>(buffer[0]))) |
3624
(static_cast<uint64_t>(static_cast<uint8_t>(buffer[1])) << 8) |
3725
(static_cast<uint64_t>(static_cast<uint8_t>(buffer[2])) << 16) |
@@ -40,12 +28,6 @@ inline uint64_t ReadUint64LE(const uint8_t* buffer) {
4028
(static_cast<uint64_t>(static_cast<uint8_t>(buffer[5])) << 40) |
4129
(static_cast<uint64_t>(static_cast<uint8_t>(buffer[6])) << 48) |
4230
(static_cast<uint64_t>(static_cast<uint8_t>(buffer[7])) << 56));
43-
#else // !BYTE_ORDER_BIG_ENDIAN
44-
uint64_t result;
45-
// This should be optimized to a single instruction.
46-
std::memcpy(&result, buffer, sizeof(result));
47-
return result;
48-
#endif // BYTE_ORDER_BIG_ENDIAN
4931
}
5032

5133
} // namespace crc32c

0 commit comments

Comments
 (0)