xref: /aosp_15_r20/external/xz-embedded/userspace/xz_config.h (revision d2c16535d139cb185e89120452531bba6b36d3c6)
1*d2c16535SElliott Hughes /* SPDX-License-Identifier: 0BSD */
2*d2c16535SElliott Hughes 
3*d2c16535SElliott Hughes /*
4*d2c16535SElliott Hughes  * Private includes and definitions for userspace use of XZ Embedded
5*d2c16535SElliott Hughes  *
6*d2c16535SElliott Hughes  * Author: Lasse Collin <[email protected]>
7*d2c16535SElliott Hughes  */
8*d2c16535SElliott Hughes 
9*d2c16535SElliott Hughes #ifndef XZ_CONFIG_H
10*d2c16535SElliott Hughes #define XZ_CONFIG_H
11*d2c16535SElliott Hughes 
12*d2c16535SElliott Hughes /* Uncomment to enable building of xz_dec_catrun(). */
13*d2c16535SElliott Hughes /* #define XZ_DEC_CONCATENATED */
14*d2c16535SElliott Hughes 
15*d2c16535SElliott Hughes /* Uncomment to enable CRC64 support. */
16*d2c16535SElliott Hughes /* #define XZ_USE_CRC64 */
17*d2c16535SElliott Hughes 
18*d2c16535SElliott Hughes /* Uncomment as needed to enable BCJ filter decoders. */
19*d2c16535SElliott Hughes /* #define XZ_DEC_X86 */
20*d2c16535SElliott Hughes /* #define XZ_DEC_ARM */
21*d2c16535SElliott Hughes /* #define XZ_DEC_ARMTHUMB */
22*d2c16535SElliott Hughes /* #define XZ_DEC_ARM64 */
23*d2c16535SElliott Hughes /* #define XZ_DEC_RISCV */
24*d2c16535SElliott Hughes /* #define XZ_DEC_POWERPC */
25*d2c16535SElliott Hughes /* #define XZ_DEC_IA64 */
26*d2c16535SElliott Hughes /* #define XZ_DEC_SPARC */
27*d2c16535SElliott Hughes 
28*d2c16535SElliott Hughes /*
29*d2c16535SElliott Hughes  * Visual Studio 2013 update 2 supports only __inline, not inline.
30*d2c16535SElliott Hughes  * MSVC v19.0 / VS 2015 and newer support both.
31*d2c16535SElliott Hughes  */
32*d2c16535SElliott Hughes #if defined(_MSC_VER) && _MSC_VER < 1900 && !defined(inline)
33*d2c16535SElliott Hughes #	define inline __inline
34*d2c16535SElliott Hughes #endif
35*d2c16535SElliott Hughes 
36*d2c16535SElliott Hughes #include <stdbool.h>
37*d2c16535SElliott Hughes #include <stdlib.h>
38*d2c16535SElliott Hughes #include <string.h>
39*d2c16535SElliott Hughes 
40*d2c16535SElliott Hughes #include "xz.h"
41*d2c16535SElliott Hughes 
42*d2c16535SElliott Hughes #define kmalloc(size, flags) malloc(size)
43*d2c16535SElliott Hughes #define kfree(ptr) free(ptr)
44*d2c16535SElliott Hughes #define vmalloc(size) malloc(size)
45*d2c16535SElliott Hughes #define vfree(ptr) free(ptr)
46*d2c16535SElliott Hughes 
47*d2c16535SElliott Hughes #define memeq(a, b, size) (memcmp(a, b, size) == 0)
48*d2c16535SElliott Hughes #define memzero(buf, size) memset(buf, 0, size)
49*d2c16535SElliott Hughes 
50*d2c16535SElliott Hughes #ifndef min
51*d2c16535SElliott Hughes #	define min(x, y) ((x) < (y) ? (x) : (y))
52*d2c16535SElliott Hughes #endif
53*d2c16535SElliott Hughes #define min_t(type, x, y) min(x, y)
54*d2c16535SElliott Hughes 
55*d2c16535SElliott Hughes #ifndef fallthrough
56*d2c16535SElliott Hughes #	if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202000
57*d2c16535SElliott Hughes #		define fallthrough [[fallthrough]]
58*d2c16535SElliott Hughes #	elif defined(__GNUC__) && __GNUC__ >= 7
59*d2c16535SElliott Hughes #		define fallthrough __attribute__((__fallthrough__))
60*d2c16535SElliott Hughes #	else
61*d2c16535SElliott Hughes #		define fallthrough do {} while (0)
62*d2c16535SElliott Hughes #	endif
63*d2c16535SElliott Hughes #endif
64*d2c16535SElliott Hughes 
65*d2c16535SElliott Hughes /*
66*d2c16535SElliott Hughes  * Some functions have been marked with __always_inline to keep the
67*d2c16535SElliott Hughes  * performance reasonable even when the compiler is optimizing for
68*d2c16535SElliott Hughes  * small code size. You may be able to save a few bytes by #defining
69*d2c16535SElliott Hughes  * __always_inline to plain inline, but don't complain if the code
70*d2c16535SElliott Hughes  * becomes slow.
71*d2c16535SElliott Hughes  *
72*d2c16535SElliott Hughes  * NOTE: System headers on GNU/Linux may #define this macro already,
73*d2c16535SElliott Hughes  * so if you want to change it, you need to #undef it first.
74*d2c16535SElliott Hughes  */
75*d2c16535SElliott Hughes #ifndef __always_inline
76*d2c16535SElliott Hughes #	ifdef __GNUC__
77*d2c16535SElliott Hughes #		define __always_inline \
78*d2c16535SElliott Hughes 			inline __attribute__((__always_inline__))
79*d2c16535SElliott Hughes #	else
80*d2c16535SElliott Hughes #		define __always_inline inline
81*d2c16535SElliott Hughes #	endif
82*d2c16535SElliott Hughes #endif
83*d2c16535SElliott Hughes 
84*d2c16535SElliott Hughes /* Inline functions to access unaligned unsigned 32-bit integers */
85*d2c16535SElliott Hughes #ifndef get_unaligned_le32
get_unaligned_le32(const uint8_t * buf)86*d2c16535SElliott Hughes static inline uint32_t get_unaligned_le32(const uint8_t *buf)
87*d2c16535SElliott Hughes {
88*d2c16535SElliott Hughes 	return (uint32_t)buf[0]
89*d2c16535SElliott Hughes 			| ((uint32_t)buf[1] << 8)
90*d2c16535SElliott Hughes 			| ((uint32_t)buf[2] << 16)
91*d2c16535SElliott Hughes 			| ((uint32_t)buf[3] << 24);
92*d2c16535SElliott Hughes }
93*d2c16535SElliott Hughes #endif
94*d2c16535SElliott Hughes 
95*d2c16535SElliott Hughes #ifndef get_unaligned_be32
get_unaligned_be32(const uint8_t * buf)96*d2c16535SElliott Hughes static inline uint32_t get_unaligned_be32(const uint8_t *buf)
97*d2c16535SElliott Hughes {
98*d2c16535SElliott Hughes 	return (uint32_t)(buf[0] << 24)
99*d2c16535SElliott Hughes 			| ((uint32_t)buf[1] << 16)
100*d2c16535SElliott Hughes 			| ((uint32_t)buf[2] << 8)
101*d2c16535SElliott Hughes 			| (uint32_t)buf[3];
102*d2c16535SElliott Hughes }
103*d2c16535SElliott Hughes #endif
104*d2c16535SElliott Hughes 
105*d2c16535SElliott Hughes #ifndef put_unaligned_le32
put_unaligned_le32(uint32_t val,uint8_t * buf)106*d2c16535SElliott Hughes static inline void put_unaligned_le32(uint32_t val, uint8_t *buf)
107*d2c16535SElliott Hughes {
108*d2c16535SElliott Hughes 	buf[0] = (uint8_t)val;
109*d2c16535SElliott Hughes 	buf[1] = (uint8_t)(val >> 8);
110*d2c16535SElliott Hughes 	buf[2] = (uint8_t)(val >> 16);
111*d2c16535SElliott Hughes 	buf[3] = (uint8_t)(val >> 24);
112*d2c16535SElliott Hughes }
113*d2c16535SElliott Hughes #endif
114*d2c16535SElliott Hughes 
115*d2c16535SElliott Hughes #ifndef put_unaligned_be32
put_unaligned_be32(uint32_t val,uint8_t * buf)116*d2c16535SElliott Hughes static inline void put_unaligned_be32(uint32_t val, uint8_t *buf)
117*d2c16535SElliott Hughes {
118*d2c16535SElliott Hughes 	buf[0] = (uint8_t)(val >> 24);
119*d2c16535SElliott Hughes 	buf[1] = (uint8_t)(val >> 16);
120*d2c16535SElliott Hughes 	buf[2] = (uint8_t)(val >> 8);
121*d2c16535SElliott Hughes 	buf[3] = (uint8_t)val;
122*d2c16535SElliott Hughes }
123*d2c16535SElliott Hughes #endif
124*d2c16535SElliott Hughes 
125*d2c16535SElliott Hughes /*
126*d2c16535SElliott Hughes  * Use get_unaligned_le32() also for aligned access for simplicity. On
127*d2c16535SElliott Hughes  * little endian systems, #define get_le32(ptr) (*(const uint32_t *)(ptr))
128*d2c16535SElliott Hughes  * could save a few bytes in code size.
129*d2c16535SElliott Hughes  */
130*d2c16535SElliott Hughes #ifndef get_le32
131*d2c16535SElliott Hughes #	define get_le32 get_unaligned_le32
132*d2c16535SElliott Hughes #endif
133*d2c16535SElliott Hughes 
134*d2c16535SElliott Hughes #endif
135