docs: update for new data placement options
[fio.git] / compiler / compiler.h
... / ...
CommitLineData
1#ifndef FIO_COMPILER_H
2#define FIO_COMPILER_H
3
4#define __must_check __attribute__((warn_unused_result))
5
6#define __compiletime_warning(message) __attribute__((warning(message)))
7#define __compiletime_error(message) __attribute__((error(message)))
8
9/*
10 * Mark unused variables passed to ops functions as unused, to silence gcc
11 */
12#define fio_unused __attribute__((__unused__))
13#define fio_init __attribute__((constructor))
14#define fio_exit __attribute__((destructor))
15
16#define fio_unlikely(x) __builtin_expect(!!(x), 0)
17
18/*
19 * Check at compile time that something is of a particular type.
20 * Always evaluates to 1 so you may use it easily in comparisons.
21 */
22#define typecheck(type,x) \
23({ type __dummy; \
24 __typeof__(x) __dummy2; \
25 (void)(&__dummy == &__dummy2); \
26 1; \
27})
28
29
30#if defined(CONFIG_STATIC_ASSERT)
31#define compiletime_assert(condition, msg) _Static_assert(condition, msg)
32
33#elif !defined(CONFIG_DISABLE_OPTIMIZATIONS)
34
35#ifndef __compiletime_error
36#define __compiletime_error(message)
37#endif
38
39#ifndef __compiletime_error_fallback
40#define __compiletime_error_fallback(condition) do { } while (0)
41#endif
42
43#define __compiletime_assert(condition, msg, prefix, suffix) \
44 do { \
45 int __cond = !(condition); \
46 extern void prefix ## suffix(void) __compiletime_error(msg); \
47 if (__cond) \
48 prefix ## suffix(); \
49 __compiletime_error_fallback(__cond); \
50 } while (0)
51
52#define _compiletime_assert(condition, msg, prefix, suffix) \
53 __compiletime_assert(condition, msg, prefix, suffix)
54
55#define compiletime_assert(condition, msg) \
56 _compiletime_assert(condition, msg, __compiletime_assert_, __LINE__)
57
58#else
59
60#define compiletime_assert(condition, msg) do { } while (0)
61
62#endif
63
64#ifdef FIO_INTERNAL
65#define FIO_ARRAY_SIZE(x) (sizeof((x)) / (sizeof((x)[0])))
66#define FIO_FIELD_SIZE(s, f) (sizeof(((__typeof__(s))0)->f))
67#endif
68
69#ifndef __has_attribute
70#define __has_attribute(x) __GCC4_has_attribute_##x
71#define __GCC4_has_attribute___fallthrough__ 0
72#endif
73
74#if __has_attribute(__fallthrough__)
75#define fio_fallthrough __attribute__((__fallthrough__))
76#else
77#define fio_fallthrough do {} while (0) /* fallthrough */
78#endif
79
80#endif