Skip to content

Commit a679b5e

Browse files
committed
fix: crc32 should not have byte order be platform dependent
1 parent 8e1e13f commit a679b5e

File tree

1 file changed

+11
-23
lines changed

1 file changed

+11
-23
lines changed

include/alpaca/detail/crc32.h

+11-23
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,10 @@
2828
// size_t
2929
#include <cstddef>
3030

31-
// define endianess and some integer data types
32-
#if defined(_MSC_VER) || defined(__MINGW32__)
33-
// Windows always little endian
3431
#define __ALPACA_BYTE_ORDER __ALPACA_LITTLE_ENDIAN
3532

33+
// define some integer data types
34+
#if defined(_MSC_VER) || defined(__MINGW32__)
3635
// intrinsics / prefetching
3736
#if defined(__MINGW32__) || defined(__clang__)
3837
#define ALPACA_PREFETCH(location) __builtin_prefetch(location)
@@ -42,41 +41,30 @@
4241
#define ALPACA_PREFETCH(location) _mm_prefetch(location, _MM_HINT_T0)
4342
#else
4443
#define ALPACA_PREFETCH(location) ;
45-
#endif
46-
#endif
44+
#endif // __SSE2__
45+
#endif // __MINGW32__
4746
#elif defined(__APPLE__) || defined(__MACH__)
48-
// Apple MacOS uses big endian
49-
#define __ALPACA_BYTE_ORDER __ALPACA_BIG_ENDIAN
50-
5147
// intrinsics / prefetching
5248
#ifdef __GNUC__
5349
#define ALPACA_PREFETCH(location) __builtin_prefetch(location)
54-
#else
50+
#else // __GNUC__
5551
// no prefetching
5652
#define ALPACA_PREFETCH(location) ;
57-
#endif
53+
#endif // __GNUC__
5854

5955
#elif defined(__linux__) || defined(__linux) || defined(linux__) || \
6056
defined(__gnu_linux__)
61-
// defines BYTE_ORDER as __ALPACA_LITTLE_ENDIAN or __ALPACA_BIG_ENDIAN
6257
#include <sys/param.h>
63-
#define __ALPACA_BYTE_ORDER __BYTE_ORDER
64-
6558
// intrinsics / prefetching
6659
#ifdef __GNUC__
6760
#define ALPACA_PREFETCH(location) __builtin_prefetch(location)
68-
#else
61+
#else // __GNUC__
6962
// no prefetching
7063
#define ALPACA_PREFETCH(location) ;
71-
#endif
72-
#else
64+
#endif // __GNUC__
65+
#else // unknown system
7366
#error unsupported system
74-
#endif
75-
76-
// abort if byte order is undefined
77-
#if !defined(__ALPACA_BYTE_ORDER)
78-
#error undefined byte order, compile with -D__ALPACA_BYTE_ORDER=1234 (if little endian) or -D__ALPACA_BYTE_ORDER=4321 (big endian)
79-
#endif
67+
#endif // system
8068

8169
namespace {
8270
/// zlib's CRC32 polynomial
@@ -1386,4 +1374,4 @@ static inline uint32_t crc32_combine(uint32_t crcA, uint32_t crcB,
13861374

13871375
// return combined crc
13881376
return crcA ^ crcB;
1389-
}
1377+
}

0 commit comments

Comments
 (0)