4 * Various compiler features
7 #ifndef _KLIBC_COMPILER_H
8 #define _KLIBC_COMPILER_H
12 /* Specific calling conventions */
13 /* __cdecl is used when we want varadic and non-varadic functions to have
14 the same binary calling convention. */
17 # define __cdecl __attribute__((cdecl,regparm(0)))
19 /* Most other C compilers have __cdecl as a keyword */
22 # define __cdecl /* Meaningless on non-i386 */
25 /* How to declare a function that *must* be inlined */
27 # if __GNUC_MAJOR__ >= 3
28 # define __must_inline static __inline__ __attribute__((always_inline))
30 # define __must_inline extern __inline__
33 # define __must_inline inline /* Just hope this works... */
36 /* How to declare a function that does not return */
38 # define __noreturn void __attribute__((noreturn))
40 # define __noreturn void
45 Many functions do not examine any values except their arguments,
46 and have no effects except the return value. Basically this is
47 just slightly more strict class than the `pure' attribute above,
48 since function is not allowed to read global memory.
50 Note that a function that has pointer arguments and examines the
51 data pointed to must _not_ be declared `const'. Likewise, a
52 function that calls a non-`const' function usually must not be
53 `const'. It does not make sense for a `const' function to return
57 # define __constfunc __attribute__((const))
61 #undef __attribute_const__
62 #define __attribute_const__ __constfunc
66 Many functions have no effects except the return value and their
67 return value depends only on the parameters and/or global
68 variables. Such a function can be subject to common subexpression
69 elimination and loop optimization just as an arithmetic operator
70 would be. These functions should be declared with the attribute
74 # define __purefunc __attribute__((pure))
78 #undef __attribute_pure__
79 #define __attribute_pure__ __purefunc
81 /* Format attribute */
83 # define __formatfunc(t,f,a) __attribute__((format(t,f,a)))
85 # define __formatfunc(t,f,a)
88 /* malloc() function (returns unaliased pointer) */
89 #if defined(__GNUC__) && (__GNUC_MAJOR__ >= 3)
90 # define __mallocfunc __attribute__((malloc))
96 #if defined(__GNUC__) && (__GNUC_MAJOR__ > 2 || (__GNUC_MAJOR__ == 2 && __GNUC_MINOR__ >= 95))
97 # define __likely(x) __builtin_expect((x), 1)
98 # define __unlikely(x) __builtin_expect((x), 0)
100 # define __likely(x) (x)
101 # define __unlikely(x) (x)
104 /* Possibly unused function */
106 # define __unusedfunc __attribute__((unused))
108 # define __unusedfunc
111 /* Constructors and destructors */
112 #define __constructor __attribute__((constructor))
113 #define __destructor __attribute__((destructor))
115 /* Packed structures */
116 #define __packed __attribute__((packed))