]> wimlib.net Git - wimlib/blob - include/wimlib/compiler.h
221df6881e88676a9ba40a82693210d9216c2ccc
[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 #       if defined(__CYGWIN__) || defined(__WIN32__)
13 #               define WIMLIBAPI __declspec(dllexport)
14 #       else
15 #               define WIMLIBAPI __attribute__((visibility("default")))
16 #       endif
17 #       define _always_inline_attribute inline __attribute__((always_inline))
18 #       define _no_inline_attribute __attribute__((noinline))
19 #       define _packed_attribute __attribute__((packed))
20 #       define _format_attribute(type, format_str, args_start) \
21                         /*__attribute__((format(type, format_str, args_start))) */
22 #       if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4)
23 #               define _cold_attribute     __attribute__((cold))
24 #       else
25 #               define _cold_attribute
26 #       endif
27 #       define _malloc_attribute __attribute__((malloc))
28 #       define _warn_unused_result_attribute __attribute__((warn_unused_result))
29 #       define _aligned_attribute(size) __attribute__((aligned(size)))
30 #       define likely(x) __builtin_expect(!!(x), 1)
31 #       define unlikely(x) __builtin_expect(!!(x), 0)
32 #       define inline inline __attribute__((always_inline))
33 #       define prefetch(x) __builtin_prefetch(x)
34 #       define is_constant(x) __builtin_constant_p(x)
35 #else
36 #       define WIMLIBAPI
37 #       define _always_inline_attribute inline
38 #       define _no_inline_attribute
39 #       define _format_attribute(type, format_str, args_start)
40 #       define _cold_attribute
41 #       define _packed_attribute
42 #       define _malloc_attribute
43 #       define _warn_unused_result_attribute
44 #       define _aligned_attribute(size)
45 #       define likely(x) (x)
46 #       define unlikely(x) (x)
47 #       define prefetch(x)
48 #       define is_constant(x) (0)
49 #endif /* __GNUC__ */
50
51 #ifdef __CHECKER__
52 #  define _bitwise_attr __attribute__((bitwise))
53 #  define _force_attr   __attribute__((force))
54 #else
55 #  define _bitwise_attr
56 #  define _force_attr
57 #endif
58
59 #endif /* _WIMLIB_COMPILER_H */