diff --git a/src/borg/_endian.h b/src/borg/_endian.h new file mode 100644 index 000000000..645e40784 --- /dev/null +++ b/src/borg/_endian.h @@ -0,0 +1,27 @@ +#include +#include +#include + +#if defined (__SVR4) && defined (__sun) +#include +#endif + +#if (defined(BYTE_ORDER) && defined(BIG_ENDIAN) && (BYTE_ORDER == BIG_ENDIAN)) || \ + (defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)) || \ + (defined(_BIG_ENDIAN) && defined(__SVR4) && defined(__sun)) +#define BORG_BIG_ENDIAN 1 +#elif (defined(BYTE_ORDER) && defined(LITTLE_ENDIAN) && (BYTE_ORDER == LITTLE_ENDIAN)) || \ + (defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)) || \ + (defined(_LITTLE_ENDIAN) && defined(__SVR4) && defined(__sun)) +#define BORG_BIG_ENDIAN 0 +#else +#error Unknown byte order +#endif + +#if BORG_BIG_ENDIAN +#define _le32toh(x) __builtin_bswap32(x) +#define _htole32(x) __builtin_bswap32(x) +#else +#define _le32toh(x) (x) +#define _htole32(x) (x) +#endif diff --git a/src/borg/_hashindex.c b/src/borg/_hashindex.c index 763d0a250..c6435d85b 100644 --- a/src/borg/_hashindex.c +++ b/src/borg/_hashindex.c @@ -10,29 +10,7 @@ #include #include -#if defined (__SVR4) && defined (__sun) -#include -#endif - -#if (defined(BYTE_ORDER) && (BYTE_ORDER == BIG_ENDIAN)) || \ - (defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)) || \ - (defined(_BIG_ENDIAN) && defined(__SVR4)&&defined(__sun)) -#define BORG_BIG_ENDIAN 1 -#elif (defined(BYTE_ORDER) && (BYTE_ORDER == LITTLE_ENDIAN)) || \ - (defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)) || \ - (defined(_LITTLE_ENDIAN) && defined(__SVR4)&&defined(__sun)) -#define BORG_BIG_ENDIAN 0 -#else -#error Unknown byte order -#endif - -#if BORG_BIG_ENDIAN -#define _le32toh(x) __builtin_bswap32(x) -#define _htole32(x) __builtin_bswap32(x) -#else -#define _le32toh(x) (x) -#define _htole32(x) (x) -#endif +#include "_endian.h" #define MAGIC "BORG_IDX" #define MAGIC_LEN 8 diff --git a/src/borg/algorithms/crc32_slice_by_8.c b/src/borg/algorithms/crc32_slice_by_8.c index 2924285f6..dcfd8b8f9 100644 --- a/src/borg/algorithms/crc32_slice_by_8.c +++ b/src/borg/algorithms/crc32_slice_by_8.c @@ -9,6 +9,8 @@ // size_t #include +#include "../_endian.h" + /// compute CRC32 (Slicing-by-8 algorithm), unroll inner loop 4 times uint32_t crc32_4x8bytes(const void* data, size_t length, uint32_t previousCrc32); @@ -23,23 +25,6 @@ uint32_t crc32_4x8bytes(const void* data, size_t length, uint32_t previousCrc32) /// zlib's CRC32 polynomial const uint32_t Polynomial = 0xEDB88320; -/// swap endianness -#if defined (__SVR4) && defined (__sun) -#include -#endif - -#if (defined(BYTE_ORDER)&&(BYTE_ORDER == BIG_ENDIAN)) || \ - (defined(_BIG_ENDIAN)&&defined(__SVR4)&&defined(__sun)) -#define _le32toh(x) __builtin_bswap32(x) -#define BORG_BIG_ENDIAN -#elif (defined(BYTE_ORDER)&&(BYTE_ORDER == LITTLE_ENDIAN)) || \ - (defined(_LITTLE_ENDIAN)&&defined(__SVR4)&&defined(__sun)) -#define _le32toh(x) (x) -#define BORG_LITTLE_ENDIAN -#else -#error Unknown byte order -#endif - // ////////////////////////////////////////////////////////// // constants @@ -358,7 +343,7 @@ uint32_t crc32_slice_by_8(const void* data, size_t length, uint32_t previousCrc3 size_t unrolling; for (unrolling = 0; unrolling < Unroll; unrolling++) { -#ifdef BORG_BIG_ENDIAN +#if BORG_BIG_ENDIAN uint32_t one = *current++ ^ _le32toh(crc); uint32_t two = *current++; crc = Crc32Lookup[0][ two & 0xFF] ^