1
0
Fork 0
mirror of https://git.tukaani.org/xz.git synced 2024-04-04 12:36:23 +02:00

Fix a compiler error on big endian systems that don't

support unaligned memory access.
This commit is contained in:
Lasse Collin 2008-09-11 10:48:12 +03:00
parent fa3ab0df8a
commit 962f2231d4

View file

@ -14,22 +14,8 @@
#ifndef LZMA_INTEGER_H #ifndef LZMA_INTEGER_H
#define LZMA_INTEGER_H #define LZMA_INTEGER_H
// I'm aware of AC_CHECK_ALIGNED_ACCESS_REQUIRED from Autoconf archive, but // On big endian, we need byte swapping. These macros may be used outside
// it's not useful here. We don't care if unaligned access is supported, // this file, so don't put these inside HAVE_FAST_UNALIGNED_ACCESS.
// we care if it is fast. Some systems can emulate unaligned access in
// software, which is horribly slow; we want to use byte-by-byte access on
// such systems but the Autoconf test would detect such a system as
// supporting unaligned access.
//
// 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 #ifdef WORDS_BIGENDIAN
# include "bswap.h" # include "bswap.h"
# define integer_le_16(n) bswap_16(n) # define integer_le_16(n) bswap_16(n)
@ -42,6 +28,24 @@
#endif #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
// software, which is horribly slow; we want to use byte-by-byte access on
// such systems but the Autoconf test would detect such a system as
// supporting unaligned access.
//
// 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.
//
// TODO: Big endian PowerPC supports byte swapping load and store instructions
// that also allow unaligned access. Inline assembler could be OK for that.
//
// 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 static inline uint16_t
integer_read_16(const uint8_t buf[static 2]) integer_read_16(const uint8_t buf[static 2])
{ {