8
8
#include < cstdint>
9
9
#include < cstring>
10
10
11
- #ifdef CRC32C_HAVE_CONFIG_H
12
- #include " crc32c/crc32c_config.h"
13
- #endif
14
-
15
11
namespace crc32c {
16
12
17
13
// Reads a little-endian 32-bit integer from a 32-bit-aligned buffer.
18
14
inline uint32_t ReadUint32LE (const uint8_t * buffer) {
19
- #if BYTE_ORDER_BIG_ENDIAN
20
15
return ((static_cast <uint32_t >(static_cast <uint8_t >(buffer[0 ]))) |
21
16
(static_cast <uint32_t >(static_cast <uint8_t >(buffer[1 ])) << 8 ) |
22
17
(static_cast <uint32_t >(static_cast <uint8_t >(buffer[2 ])) << 16 ) |
23
18
(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
30
19
}
31
20
32
21
// Reads a little-endian 64-bit integer from a 64-bit-aligned buffer.
33
22
inline uint64_t ReadUint64LE (const uint8_t * buffer) {
34
- #if BYTE_ORDER_BIG_ENDIAN
35
23
return ((static_cast <uint64_t >(static_cast <uint8_t >(buffer[0 ]))) |
36
24
(static_cast <uint64_t >(static_cast <uint8_t >(buffer[1 ])) << 8 ) |
37
25
(static_cast <uint64_t >(static_cast <uint8_t >(buffer[2 ])) << 16 ) |
@@ -40,12 +28,6 @@ inline uint64_t ReadUint64LE(const uint8_t* buffer) {
40
28
(static_cast <uint64_t >(static_cast <uint8_t >(buffer[5 ])) << 40 ) |
41
29
(static_cast <uint64_t >(static_cast <uint8_t >(buffer[6 ])) << 48 ) |
42
30
(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
49
31
}
50
32
51
33
} // namespace crc32c
0 commit comments