Move get_unaligned_le32() macros to platform.h

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Denys Vlasenko 2017-07-15 20:22:25 +02:00
parent 08dfafc437
commit 2c1258c620
3 changed files with 17 additions and 9 deletions

View File

@ -27,11 +27,17 @@ static uint32_t xz_crc32(const uint8_t *buf, size_t size, uint32_t crc)
return ~crc32_block_endian0(~crc, buf, size, global_crc32_table); return ~crc32_block_endian0(~crc, buf, size, global_crc32_table);
} }
/* We use arch-optimized unaligned accessors */ /* We use arch-optimized unaligned fixed-endian accessors.
#define get_unaligned_le32(buf) ({ uint32_t v; move_from_unaligned32(v, buf); SWAP_LE32(v); }) * They have been moved to libbb (proved to be useful elsewhere as well),
#define get_unaligned_be32(buf) ({ uint32_t v; move_from_unaligned32(v, buf); SWAP_BE32(v); }) * just check that we have them defined:
#define put_unaligned_le32(val, buf) move_to_unaligned32(buf, SWAP_LE32(val)) */
#define put_unaligned_be32(val, buf) move_to_unaligned32(buf, SWAP_BE32(val)) #if !defined(get_unaligned_le32) \
|| !defined(get_unaligned_be32) \
|| !defined(put_unaligned_le32) \
|| !defined(put_unaligned_be32)
# error get_unaligned_le32 accessors are not defined
#endif
#define get_le32(p) (*(uint32_t*)(p))
#include "unxz/xz_dec_bcj.c" #include "unxz/xz_dec_bcj.c"
#include "unxz/xz_dec_lzma2.c" #include "unxz/xz_dec_lzma2.c"

View File

@ -247,6 +247,12 @@ typedef uint64_t bb__aliased_uint64_t FIX_ALIASING;
} while (0) } while (0)
#endif #endif
/* Unaligned, fixed-endian accessors */
#define get_unaligned_le32(buf) ({ uint32_t v; move_from_unaligned32(v, buf); SWAP_LE32(v); })
#define get_unaligned_be32(buf) ({ uint32_t v; move_from_unaligned32(v, buf); SWAP_BE32(v); })
#define put_unaligned_le32(val, buf) move_to_unaligned32(buf, SWAP_LE32(val))
#define put_unaligned_be32(val, buf) move_to_unaligned32(buf, SWAP_BE32(val))
/* ---- Size-saving "small" ints (arch-dependent) ----------- */ /* ---- Size-saving "small" ints (arch-dependent) ----------- */

View File

@ -40,10 +40,6 @@
*/ */
#include "tls.h" #include "tls.h"
/* TODO: grep for this and move to libbb */
#define get_unaligned_be32(buf) ({ uint32_t v; move_from_unaligned32(v, buf); SWAP_BE32(v); })
// The lookup-tables are marked const so they can be placed in read-only storage instead of RAM // The lookup-tables are marked const so they can be placed in read-only storage instead of RAM
// The numbers below can be computed dynamically trading ROM for RAM - // The numbers below can be computed dynamically trading ROM for RAM -
// This can be useful in (embedded) bootloader applications, where ROM is often limited. // This can be useful in (embedded) bootloader applications, where ROM is often limited.