chiark / gitweb /
[PATCH] volume-id build fix and update
[elogind.git] / klibc / 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_MAJOR__ >= 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 /* How to declare a "constant" function (a function in the
42    mathematical sense) */
43 #ifdef __GNUC__
44 # define __constfunc __attribute__((const))
45 #else
46 # define __constfunc
47 #endif
48
49 /* Format attribute */
50 #ifdef __GNUC__
51 # define __formatfunc(t,f,a) __attribute__((format(t,f,a)))
52 #else
53 # define __formatfunc(t,f,a)
54 #endif
55
56 /* likely/unlikely */
57 #if defined(__GNUC__) && (__GNUC_MAJOR__ > 2 || (__GNUC_MAJOR__ == 2 && __GNUC_MINOR__ >= 95))
58 # define __likely(x)   __builtin_expect((x), 1)
59 # define __unlikely(x) __builtin_expect((x), 0)
60 #else
61 # define __likely(x)   (x)
62 # define __unlikely(x) (x)
63 #endif
64
65 /* Possibly unused function */
66 #ifdef __GNUC__
67 # define __unusedfunc   __attribute__((unused))
68 #else
69 # define __unusedfunc
70 #endif
71
72 /* "pure" function:
73
74      Many functions have no effects except the return value and their
75      return value depends only on the parameters and/or global
76      variables.  Such a function can be subject to common subexpression
77      elimination and loop optimization just as an arithmetic operator
78      would be.  These functions should be declared with the attribute
79      `pure'.
80 */
81 #ifdef __GNUC__
82 # define __attribute_pure__     __attribute__((pure))
83 #else
84 # define __attribute_pure__
85 #endif
86
87 /* "const" function:
88
89      Many functions do not examine any values except their arguments,
90      and have no effects except the return value.  Basically this is
91      just slightly more strict class than the `pure' attribute above,
92      since function is not allowed to read global memory.
93
94      Note that a function that has pointer arguments and examines the
95      data pointed to must _not_ be declared `const'.  Likewise, a
96      function that calls a non-`const' function usually must not be
97      `const'.  It does not make sense for a `const' function to return
98      `void'.
99 */
100 #ifdef __GNUC__
101 # define __attribute_const__    __attribute__((const))
102 #else
103 # define __attribute_const__
104 #endif
105
106 #endif