Fixed demo app
[ana-net.git] / app / compiler.h
blob197dde8d2315c0b05c7b1e5d76a54b3ce45119e2
1 /*
2 * Lightweight Autonomic Network Architecture
3 * Copyright 2011 Daniel Borkmann <dborkma@tik.ee.ethz.ch>,
4 * Swiss federal institute of technology (ETH Zurich)
5 * Subject to the GPL.
6 */
8 #ifndef COMPILER_H
9 #define COMPILER_H
11 #ifndef likely
12 # define likely(x) __builtin_expect(!!(x), 1)
13 #endif
14 #ifndef unlikely
15 # define unlikely(x) __builtin_expect(!!(x), 0)
16 #endif
17 #ifndef __deprecated
18 # define __deprecated /* unimplemented */
19 #endif
20 #ifndef unreachable
21 # define unreachable() do { } while (1)
22 #endif
23 #ifndef barrier
24 # define barrier() __sync_synchronize()
25 #endif
26 #ifndef bug
27 # define bug() __builtin_trap()
28 #endif
29 #ifndef mark_unreachable
30 # define mark_unreachable() __builtin_unreachable()
31 #endif
32 #ifndef is_type
33 # define is_type(x, type) __builtin_types_compatible_p(typeof(x), (type))
34 #endif
35 #ifndef same_type
36 # define same_type(x, y) __builtin_types_compatible_p(typeof(x), typeof(y))
37 #endif
38 #ifndef __read_mostly
39 # define __read_mostly __attribute__((__section__(".data.read_mostly")))
40 #endif
41 #ifndef __must_check
42 # define __must_check /* unimplemented */
43 #endif
44 #ifndef __used
45 # define __used /* unimplemented */
46 #endif
47 #ifndef __maybe_unused
48 # define __maybe_unused /* unimplemented */
49 #endif
50 #ifndef __always_unused
51 # define __always_unused /* unimplemented */
52 #endif
53 #ifndef noinline
54 # define noinline __attribute__((noinline))
55 #endif
56 #ifndef __always_inline
57 # define __always_inline inline
58 #endif
60 * Protected visibility is like default visibility except that it indicates
61 * that references within the defining module will bind to the definition
62 * in that module. That is, the declared entity cannot be overridden by
63 * another module.
65 #ifndef __protected
66 # define __protected __attribute__((visibility("protected")))
67 #endif
69 * Hidden visibility indicates that the entity declared will have a new form
70 * of linkage, which we'll call "hidden linkage". Two declarations of an
71 * object with hidden linkage refer to the same object if they are in the
72 * same shared object.
74 #ifndef __hidden
75 # define __hidden __attribute__((visibility("hidden")))
76 #endif
78 * Internal visibility is like hidden visibility, but with additional
79 * processor specific semantics. Unless otherwise specified by the psABI,
80 * GCC defines internal visibility to mean that a function is never called
81 * from another module. Compare this with hidden functions which, while they
82 * cannot be referenced directly by other modules, can be referenced
83 * indirectly via function pointers. By indicating that a function cannot be
84 * called from outside the module, GCC may for instance omit the load of a
85 * PIC register since it is known that the calling function loaded the
86 * correct value.
88 #ifndef __internal
89 # define __internal __attribute__((visibility("internal")))
90 #endif
91 #ifndef max
92 # define max(a, b) \
93 ({ \
94 typeof (a) _a = (a); \
95 typeof (b) _b = (b); \
96 _a > _b ? _a : _b; \
98 #endif
99 #ifndef min
100 # define min(a, b) \
101 ({ \
102 typeof (a) _a = (a); \
103 typeof (b) _b = (b); \
104 _a < _b ? _a : _b; \
106 #endif
107 #ifndef offsetof
108 # define offsetof(type, member) ((size_t) &((type *) 0)->member)
109 #endif
111 * Casts a member of a structure out to the containing structure.
113 #ifndef container_of
114 # define container_of(ptr, type, member) \
115 ({ \
116 const typeof(((type *) 0)->member) * __mptr = (ptr); \
117 (type *) ((char *) __mptr - offsetof(type, member)); \
119 #endif
121 #endif /* COMPILER_H */