Fix a compiler error on big endian systems that don't
authorLasse Collin <lasse.collin@tukaani.org>
Thu, 11 Sep 2008 07:48:12 +0000 (10:48 +0300)
committerLasse Collin <lasse.collin@tukaani.org>
Thu, 11 Sep 2008 07:48:12 +0000 (10:48 +0300)
support unaligned memory access.

src/common/integer.h

index a6e43be..9addf96 100644 (file)
 #ifndef LZMA_INTEGER_H
 #define LZMA_INTEGER_H
 
+// On big endian, we need byte swapping. These macros may be used outside
+// this file, so don't put these inside HAVE_FAST_UNALIGNED_ACCESS.
+#ifdef WORDS_BIGENDIAN
+#      include "bswap.h"
+#      define integer_le_16(n) bswap_16(n)
+#      define integer_le_32(n) bswap_32(n)
+#      define integer_le_64(n) bswap_64(n)
+#else
+#      define integer_le_16(n) (n)
+#      define integer_le_32(n) (n)
+#      define integer_le_64(n) (n)
+#endif
+
+
 // I'm aware of AC_CHECK_ALIGNED_ACCESS_REQUIRED from Autoconf archive, but
 // it's not useful here. We don't care if unaligned access is supported,
 // we care if it is fast. Some systems can emulate unaligned access in
 // NOTE: HAVE_FAST_UNALIGNED_ACCESS indicates only support for 16-bit and
 // 32-bit integer loads and stores. 64-bit integers may or may not work.
 // That's why 64-bit functions are commented out.
-#ifdef HAVE_FAST_UNALIGNED_ACCESS
-
-// On big endian, we need byte swapping.
 //
 // TODO: Big endian PowerPC supports byte swapping load and store instructions
 // that also allow unaligned access. Inline assembler could be OK for that.
-#ifdef WORDS_BIGENDIAN
-#      include "bswap.h"
-#      define integer_le_16(n) bswap_16(n)
-#      define integer_le_32(n) bswap_32(n)
-#      define integer_le_64(n) bswap_64(n)
-#else
-#      define integer_le_16(n) (n)
-#      define integer_le_32(n) (n)
-#      define integer_le_64(n) (n)
-#endif
-
+//
+// Performance of these functions isn't that important until LZMA3, but it
+// doesn't hurt to have these ready already.
+#ifdef HAVE_FAST_UNALIGNED_ACCESS
 
 static inline uint16_t
 integer_read_16(const uint8_t buf[static 2])