]> wimlib.net Git - wimlib/blob - include/wimlib/compiler.h
Allow hc_matchfinder and bt_matchfinder to be "templated"
[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 /* prefetchr() - prefetch into L1 cache for read  */
42 #ifndef prefetchr
43 #  define prefetchr(addr)
44 #endif
45
46 /* prefetchw() - prefetch into L1 cache for write  */
47 #ifndef prefetchw
48 #  define prefetchw(addr)
49 #endif
50
51 #ifndef _cold_attribute
52 #  define _cold_attribute
53 #endif
54
55 #ifndef _malloc_attribute
56 #  define _malloc_attribute
57 #endif
58
59 #ifndef _format_attribute
60 #  define _format_attribute(type, format_str, format_start)
61 #endif
62
63 #ifndef noinline
64 #  define noinline
65 #endif
66
67 /* Same as 'noinline', but 'noinline_for_stack' documents that 'noinline' is
68  * being used to prevent the annotated function from being inlined into a
69  * recursive function and increasing its stack usage.  */
70 #define noinline_for_stack      noinline
71
72 #ifndef CPU_IS_BIG_ENDIAN
73 #  error "missing required endianness definition"
74 #endif
75
76 #define CPU_IS_LITTLE_ENDIAN (!CPU_IS_BIG_ENDIAN)
77
78 #ifndef UNALIGNED_ACCESS_SPEED
79 #  define UNALIGNED_ACCESS_SPEED 0
80 #endif
81
82 #define UNALIGNED_ACCESS_IS_ALLOWED     (UNALIGNED_ACCESS_SPEED >= 1)
83 #define UNALIGNED_ACCESS_IS_FAST        (UNALIGNED_ACCESS_SPEED >= 2)
84 #define UNALIGNED_ACCESS_IS_VERY_FAST   (UNALIGNED_ACCESS_SPEED >= 3)
85
86 #ifndef typeof
87 #  error "missing required definition of typeof"
88 #endif
89
90 #if !defined(min) || !defined(max) || !defined(swap)
91 #  error "missing required definitions of min(), max(), and swap() macros"
92 #endif
93
94 #ifdef __CHECKER__
95 #  define _bitwise_attr __attribute__((bitwise))
96 #  define _force_attr   __attribute__((force))
97 #else
98 #  define _bitwise_attr
99 #  define _force_attr
100 #endif
101
102 /* STATIC_ASSERT() - verify the truth of an expression at compilation time.  */
103 #if __STDC_VERSION__ >= 201112L
104 #  define STATIC_ASSERT(expr)   _Static_assert((expr), "")
105 #else
106 #  define STATIC_ASSERT(expr)   ((void)sizeof(char[1 - 2 * !(expr)]))
107 #endif
108
109 #define CONCAT_IMPL(s1, s2)     s1##s2
110
111 /* CONCAT() - concatenate two tokens at preprocessing time.  */
112 #define CONCAT(s1, s2)          CONCAT_IMPL(s1, s2)
113
114 #endif /* _WIMLIB_COMPILER_H */