2 * Private includes and definitions for userspace use of XZ Embedded
4 * Author: Lasse Collin <lasse.collin@tukaani.org>
6 * This file has been put into the public domain.
7 * You can do whatever you want with this file.
13 /* Uncomment as needed to enable BCJ filter decoders. */
14 /* #define XZ_DEC_X86 */
15 /* #define XZ_DEC_POWERPC */
16 /* #define XZ_DEC_IA64 */
17 /* #define XZ_DEC_ARM */
18 /* #define XZ_DEC_ARMTHUMB */
19 /* #define XZ_DEC_SPARC */
27 #define kmalloc(size, flags) malloc(size)
28 #define kfree(ptr) free(ptr)
29 #define vmalloc(size) malloc(size)
30 #define vfree(ptr) free(ptr)
32 #define memeq(a, b, size) (memcmp(a, b, size) == 0)
33 #define memzero(buf, size) memset(buf, 0, size)
36 # define min(x, y) ((x) < (y) ? (x) : (y))
38 #define min_t(type, x, y) min(x, y)
41 * Some functions have been marked with __always_inline to keep the
42 * performance reasonable even when the compiler is optimizing for
43 * small code size. You may be able to save a few bytes by #defining
44 * __always_inline to plain inline, but don't complain if the code
47 * NOTE: System headers on GNU/Linux may #define this macro already,
48 * so if you want to change it, you need to #undef it first.
50 #ifndef __always_inline
52 # define __always_inline \
53 inline __attribute__((__always_inline__))
55 # define __always_inline inline
59 /* Inline functions to access unaligned unsigned 32-bit integers */
60 #ifndef get_unaligned_le32
61 static inline uint32_t get_unaligned_le32(const uint8_t *buf)
63 return (uint32_t)buf[0]
64 | ((uint32_t)buf[1] << 8)
65 | ((uint32_t)buf[2] << 16)
66 | ((uint32_t)buf[3] << 24);
70 #ifndef get_unaligned_be32
71 static inline uint32_t get_unaligned_be32(const uint8_t *buf)
73 return (uint32_t)(buf[0] << 24)
74 | ((uint32_t)buf[1] << 16)
75 | ((uint32_t)buf[2] << 8)
80 #ifndef put_unaligned_le32
81 static inline void put_unaligned_le32(uint32_t val, uint8_t *buf)
83 buf[0] = (uint8_t)val;
84 buf[1] = (uint8_t)(val >> 8);
85 buf[2] = (uint8_t)(val >> 16);
86 buf[3] = (uint8_t)(val >> 24);
90 #ifndef put_unaligned_be32
91 static inline void put_unaligned_be32(uint32_t val, uint8_t *buf)
93 buf[0] = (uint8_t)(val >> 24);
94 buf[1] = (uint8_t)(val >> 16);
95 buf[2] = (uint8_t)(val >> 8);
96 buf[3] = (uint8_t)val;
101 * Use get_unaligned_le32() also for aligned access for simplicity. On
102 * little endian systems, #define get_le32(ptr) (*(const uint32_t *)(ptr))
103 * could save a few bytes in code size.
106 # define get_le32 get_unaligned_le32