]> wimlib.net Git - wimlib/blob - include/wimlib/compiler.h
Reduce stack usage of recursive scan functions
[wimlib] / include / wimlib / compiler.h
1 /*
2  * compiler.h
3  *
4  * The author dedicates this file to the public domain.
5  * You can do whatever you want with this file.
6  */
7
8 #ifndef _WIMLIB_COMPILER_H
9 #define _WIMLIB_COMPILER_H
10
11 #ifdef __GNUC__
12 #  include "wimlib/compiler-gcc.h"
13 #else
14 #  error "Unrecognized compiler.  Please add a header file for your compiler."
15 #endif
16
17 #ifndef WIMLIBAPI
18 #  define WIMLIBAPI
19 #endif
20
21 #ifndef _packed_attribute
22 #  error "missing required definition of _packed_attribute"
23 #endif
24
25 #ifndef _aligned_attribute
26 #  error "missing required definition of _aligned_attribute"
27 #endif
28
29 #ifndef _may_alias_attribute
30 #  error "missing required definition of _may_alias_attribute"
31 #endif
32
33 #ifndef likely
34 #  define likely(expr)          (expr)
35 #endif
36
37 #ifndef unlikely
38 #  define unlikely(expr)        (expr)
39 #endif
40
41 #ifndef prefetch
42 #  define prefetch(addr)
43 #endif
44
45 #ifndef _cold_attribute
46 #  define _cold_attribute
47 #endif
48
49 #ifndef _malloc_attribute
50 #  define _malloc_attribute
51 #endif
52
53 #ifndef _format_attribute
54 #  define _format_attribute(type, format_str, format_start)
55 #endif
56
57 #ifndef noinline
58 #  define noinline
59 #endif
60
61 /* Same as 'noinline', but 'noinline_for_stack' documents that 'noinline' is
62  * being used to prevent the annotated function from being inlined into a
63  * recursive function and increasing its stack usage.  */
64 #define noinline_for_stack      noinline
65
66 #ifndef CPU_IS_BIG_ENDIAN
67 #  error "missing required endianness definition"
68 #endif
69
70 #define CPU_IS_LITTLE_ENDIAN (!CPU_IS_BIG_ENDIAN)
71
72 #ifndef UNALIGNED_ACCESS_SPEED
73 #  define UNALIGNED_ACCESS_SPEED 0
74 #endif
75
76 #define UNALIGNED_ACCESS_IS_ALLOWED     (UNALIGNED_ACCESS_SPEED >= 1)
77 #define UNALIGNED_ACCESS_IS_FAST        (UNALIGNED_ACCESS_SPEED >= 2)
78 #define UNALIGNED_ACCESS_IS_VERY_FAST   (UNALIGNED_ACCESS_SPEED >= 3)
79
80 #ifndef typeof
81 #  error "missing required definition of typeof"
82 #endif
83
84 #if !defined(min) || !defined(max) || !defined(swap)
85 #  error "missing required definitions of min(), max(), and swap() macros"
86 #endif
87
88 #ifdef __CHECKER__
89 #  define _bitwise_attr __attribute__((bitwise))
90 #  define _force_attr   __attribute__((force))
91 #else
92 #  define _bitwise_attr
93 #  define _force_attr
94 #endif
95
96 #ifndef BUILD_BUG_ON
97 #  define BUILD_BUG_ON(expr)    ((void)sizeof(char[1 - 2*!!(expr)]))
98 #endif
99
100 #endif /* _WIMLIB_COMPILER_H */