chiark / gitweb /
49872b89d4c2484ff4addb0cc5c6acff6c242dcf
[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 #ifdef __i386__
12 # ifdef __GNUC__
13 #  define __cdecl __attribute__((cdecl,regparm(0)))
14 # else
15   /* Most other C compilers have __cdecl as a keyword */
16 # endif
17 #endif
18
19 /* How to declare a function that *must* be inlined */
20 #ifdef __GNUC__
21 # if __GNUC_MAJOR__ >= 3
22 #  define __must_inline static __inline__ __attribute__((always_inline))
23 # else
24 #  define __must_inline extern __inline__
25 # endif
26 #else
27 # define __must_inline inline   /* Just hope this works... */
28 #endif
29
30 /* How to declare a function that does not return */
31 #ifdef __GNUC__
32 # define __noreturn void __attribute__((noreturn))
33 #else
34 # define __noreturn void
35 #endif
36
37 /* How to declare a "constant" function (a function in the
38    mathematical sense) */
39 #ifdef __GNUC__
40 # define __constfunc __attribute__((const))
41 #else
42 # define __constfunc
43 #endif
44
45 /* Format attribute */
46 #ifdef __GNUC__
47 # define __formatfunc(t,f,a) __attribute__((format(t,f,a)))
48 #else
49 # define __formatfunc(t,f,a)
50 #endif
51
52 /* likely/unlikely */
53 #if defined(__GNUC__) && (__GNUC_MAJOR__ > 2 || (__GNUC_MAJOR__ == 2 && __GNUC_MINOR__ >= 95))
54 # define __likely(x)   __builtin_expect((x), 1)
55 # define __unlikely(x) __builtin_expect((x), 0)
56 #else
57 # define __likely(x)   (x)
58 # define __unlikely(x) (x)
59 #endif
60
61 /* Possibly unused function */
62 #ifdef __GNUC__
63 # define __unusedfunc   __attribute__((unused))
64 #else
65 # define __unusedfunc
66 #endif
67
68 /* "pure" function:
69
70      Many functions have no effects except the return value and their
71      return value depends only on the parameters and/or global
72      variables.  Such a function can be subject to common subexpression
73      elimination and loop optimization just as an arithmetic operator
74      would be.  These functions should be declared with the attribute
75      `pure'.
76 */
77 #ifdef __GNUC__
78 # define __attribute_pure__     __attribute__((pure))
79 #else
80 # define __attribute_pure__
81 #endif
82
83 /* "const" function:
84
85      Many functions do not examine any values except their arguments,
86      and have no effects except the return value.  Basically this is
87      just slightly more strict class than the `pure' attribute above,
88      since function is not allowed to read global memory.
89
90      Note that a function that has pointer arguments and examines the
91      data pointed to must _not_ be declared `const'.  Likewise, a
92      function that calls a non-`const' function usually must not be
93      `const'.  It does not make sense for a `const' function to return
94      `void'.
95 */
96 #ifdef __GNUC__
97 # define __attribute_const__    __attribute__((const))
98 #else
99 # define __attribute_const__
100 #endif
101
102 #endif