aboutsummaryrefslogtreecommitdiff
path: root/src/common/integer.h
diff options
context:
space:
mode:
authorLasse Collin <lasse.collin@tukaani.org>2008-09-11 10:48:12 +0300
committerLasse Collin <lasse.collin@tukaani.org>2008-09-11 10:48:12 +0300
commit962f2231d49409fe6852e44ffe8c5dbabb04bc7d (patch)
tree97c20e7a2012af59d5d6998185647ccb340e87d0 /src/common/integer.h
parentSilence a compiler warning. (diff)
downloadxz-962f2231d49409fe6852e44ffe8c5dbabb04bc7d.tar.xz
Fix a compiler error on big endian systems that don't
support unaligned memory access.
Diffstat (limited to '')
-rw-r--r--src/common/integer.h32
1 files changed, 18 insertions, 14 deletions
diff --git a/src/common/integer.h b/src/common/integer.h
index a6e43be2..9addf965 100644
--- a/src/common/integer.h
+++ b/src/common/integer.h
@@ -14,6 +14,20 @@
#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
@@ -24,23 +38,13 @@
// 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])