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