chiark / gitweb /
7ff6ff7d51bba208dc96bf3f1904e4fb6b977102
[elogind.git] / klibc / include / klibc / compiler.h
1 /*
2  * klibc/compiler.h
3  *
4  * Various compiler features
5  */
6
7 #ifndef _KLIBC_COMPILER_H
8 #define _KLIBC_COMPILER_H
9
10 /* Specific calling conventions */
11 /* __cdecl is used when we want varadic and non-varadic functions to have
12    the same binary calling convention. */
13 #ifdef __i386__
14 # ifdef __GNUC__
15 #  define __cdecl __attribute__((cdecl,regparm(0)))
16 # else
17   /* Most other C compilers have __cdecl as a keyword */
18 # endif
19 #else
20 # define __cdecl                /* Meaningless on non-i386 */
21 #endif
22
23 /* How to declare a function that *must* be inlined */
24 #ifdef __GNUC__
25 # if __GNUC__ >= 3
26 #  define __must_inline static __inline__ __attribute__((always_inline))
27 # else
28 #  define __must_inline extern __inline__
29 # endif
30 #else
31 # define __must_inline inline   /* Just hope this works... */
32 #endif
33
34 /* How to declare a function that does not return */
35 #ifdef __GNUC__
36 # define __noreturn void __attribute__((noreturn))
37 #else
38 # define __noreturn void
39 #endif
40
41 /* "const" function:
42
43      Many functions do not examine any values except their arguments,
44      and have no effects except the return value.  Basically this is
45      just slightly more strict class than the `pure' attribute above,
46      since function is not allowed to read global memory.
47
48      Note that a function that has pointer arguments and examines the
49      data pointed to must _not_ be declared `const'.  Likewise, a
50      function that calls a non-`const' function usually must not be
51      `const'.  It does not make sense for a `const' function to return
52      `void'.
53 */
54 #ifdef __GNUC__
55 # define __constfunc __attribute__((const))
56 #else
57 # define __constfunc
58 #endif
59 #undef __attribute_const__
60 #define __attribute_const__ __constfunc
61
62 /* "pure" function:
63
64      Many functions have no effects except the return value and their
65      return value depends only on the parameters and/or global
66      variables.  Such a function can be subject to common subexpression
67      elimination and loop optimization just as an arithmetic operator
68      would be.  These functions should be declared with the attribute
69      `pure'.
70 */
71 #ifdef __GNUC__
72 # define __purefunc __attribute__((pure))
73 #else
74 # define __purefunc
75 #endif
76 #undef __attribute_pure__
77 #define __attribute_pure__ __purefunc
78
79 /* Format attribute */
80 #ifdef __GNUC__
81 # define __formatfunc(t,f,a) __attribute__((format(t,f,a)))
82 #else
83 # define __formatfunc(t,f,a)
84 #endif
85
86 /* malloc() function (returns unaliased pointer) */
87 #if defined(__GNUC__) && (__GNUC__ >= 3)
88 # define __mallocfunc __attribute__((malloc))
89 #else
90 # define __mallocfunc
91 #endif
92
93 /* likely/unlikely */
94 #if defined(__GNUC__) && (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95))
95 # define __likely(x)   __builtin_expect((x), 1)
96 # define __unlikely(x) __builtin_expect((x), 0)
97 #else
98 # define __likely(x)   (x)
99 # define __unlikely(x) (x)
100 #endif
101
102 /* Possibly unused function */
103 #ifdef __GNUC__
104 # define __unusedfunc   __attribute__((unused))
105 #else
106 # define __unusedfunc
107 #endif
108
109 /* It's all user space... */
110 #define __user
111
112 /* The bitwise attribute: disallow arithmetric operations */
113 #ifdef __CHECKER__ /* sparse only */
114 # define __bitwise      __attribute__((bitwise))
115 #else
116 # define __bitwise
117 #endif
118
119 /* Compiler pragma to make an alias symbol */
120 #define __ALIAS(__t, __f, __p, __a) \
121   __t __f __p __attribute__((weak, alias(#__a)));
122
123 #endif