dea0d2e01e549fdc0479822089ff0bf7565e433a
[linux-2.6.git] / include / linux / compiler.h
1 #ifndef __LINUX_COMPILER_H
2 #define __LINUX_COMPILER_H
3
4 #ifndef __ASSEMBLY__
5
6 #ifdef __CHECKER__
7 # define __user         __attribute__((noderef, address_space(1)))
8 # define __kernel       /* default address space */
9 # define __safe         __attribute__((safe))
10 # define __force        __attribute__((force))
11 # define __iomem        __attribute__((noderef, address_space(2)))
12 extern void __chk_user_ptr(void __user *);
13 extern void __chk_io_ptr(void __iomem *);
14 #else
15 # define __user
16 # define __kernel
17 # define __safe
18 # define __force
19 # define __iomem
20 # define __chk_user_ptr(x) (void)0
21 # define __chk_io_ptr(x) (void)0
22 #endif
23
24 #ifdef __KERNEL__
25
26 #if __GNUC__ > 3
27 # include <linux/compiler-gcc+.h>       /* catch-all for GCC 4, 5, etc. */
28 #elif __GNUC__ == 3
29 # include <linux/compiler-gcc3.h>
30 #elif __GNUC__ == 2
31 # include <linux/compiler-gcc2.h>
32 #else
33 # error Sorry, your compiler is too old/not recognized.
34 #endif
35
36 /* Intel compiler defines __GNUC__. So we will overwrite implementations
37  * coming from above header files here
38  */
39 #ifdef __INTEL_COMPILER
40 # include <linux/compiler-intel.h>
41 #endif
42
43 /*
44  * Generic compiler-dependent macros required for kernel
45  * build go below this comment. Actual compiler/compiler version
46  * specific implementations come from the above header files
47  */
48
49 #define likely(x)       __builtin_expect(!!(x), 1)
50 #define unlikely(x)     __builtin_expect(!!(x), 0)
51
52 /* Optimization barrier */
53 #ifndef barrier
54 # define barrier() __memory_barrier()
55 #endif
56
57 #ifndef RELOC_HIDE
58 # define RELOC_HIDE(ptr, off)                                   \
59   ({ unsigned long __ptr;                                       \
60      __ptr = (unsigned long) (ptr);                             \
61     (typeof(ptr)) (__ptr + (off)); })
62 #endif
63
64 #endif /* __ASSEMBLY__ */
65
66 #endif /* __KERNEL__ */
67
68 /*
69  * Allow us to mark functions as 'deprecated' and have gcc emit a nice
70  * warning for each use, in hopes of speeding the functions removal.
71  * Usage is:
72  *              int __deprecated foo(void)
73  */
74 #ifndef __deprecated
75 # define __deprecated           /* unimplemented */
76 #endif
77
78 #ifndef __must_check
79 #define __must_check
80 #endif
81
82 /*
83  * Allow us to avoid 'defined but not used' warnings on functions and data,
84  * as well as force them to be emitted to the assembly file.
85  *
86  * As of gcc 3.3, static functions that are not marked with attribute((used))
87  * may be elided from the assembly file.  As of gcc 3.3, static data not so
88  * marked will not be elided, but this may change in a future gcc version.
89  *
90  * In prior versions of gcc, such functions and data would be emitted, but
91  * would be warned about except with attribute((unused)).
92  */
93 #ifndef __attribute_used__
94 # define __attribute_used__     /* unimplemented */
95 #endif
96
97 /*
98  * From the GCC manual:
99  *
100  * Many functions have no effects except the return value and their
101  * return value depends only on the parameters and/or global
102  * variables.  Such a function can be subject to common subexpression
103  * elimination and loop optimization just as an arithmetic operator
104  * would be.
105  * [...]
106  */
107 #ifndef __attribute_pure__
108 # define __attribute_pure__     /* unimplemented */
109 #endif
110
111 /*
112  * From the GCC manual:
113  *
114  * Many functions do not examine any values except their arguments,
115  * and have no effects except the return value.  Basically this is
116  * just slightly more strict class than the `pure' attribute above,
117  * since function is not allowed to read global memory.
118  *
119  * Note that a function that has pointer arguments and examines the
120  * data pointed to must _not_ be declared `const'.  Likewise, a
121  * function that calls a non-`const' function usually must not be
122  * `const'.  It does not make sense for a `const' function to return
123  * `void'.
124  */
125 #ifndef __attribute_const__
126 # define __attribute_const__    /* unimplemented */
127 #endif
128
129 #ifndef noinline
130 #define noinline
131 #endif
132
133 #ifndef __always_inline
134 #define __always_inline inline
135 #endif
136
137 #endif /* __LINUX_COMPILER_H */