Chameleon

Chameleon Svn Source Tree

Root/branches/slice/i386/modules/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/* Use "extern inline" even in the gcc3+ case to avoid warnings in ctype.h */
25#ifdef __GNUC__
26# if __GNUC__ >= 3
27# ifdef __GNUC_STDC_INLINE__
28# define __must_inline extern __inline__ \
29__attribute__((__gnu_inline__,__always_inline__))
30# else
31# define __must_inline extern __inline__ __attribute__((__always_inline__))
32# endif
33# else
34# define __must_inline extern __inline__
35# endif
36#else
37# define __must_inline inline/* Just hope this works... */
38#endif
39
40/* How to declare a function that does not return */
41#ifdef __GNUC__
42# define __noreturn void __attribute__((noreturn))
43#else
44# define __noreturn void
45#endif
46
47/* "const" function:
48
49 Many functions do not examine any values except their arguments,
50 and have no effects except the return value. Basically this is
51 just slightly more strict class than the `pure' attribute above,
52 since function is not allowed to read global memory.
53
54 Note that a function that has pointer arguments and examines the
55 data pointed to must _not_ be declared `const'. Likewise, a
56 function that calls a non-`const' function usually must not be
57 `const'. It does not make sense for a `const' function to return
58 `void'.
59*/
60#ifdef __GNUC__
61# define __constfunc __attribute__((const))
62#else
63# define __constfunc
64#endif
65#undef __attribute_const__
66#define __attribute_const__ __constfunc
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 __purefunc __attribute__((pure))
79#else
80# define __purefunc
81#endif
82#undef __attribute_pure__
83#define __attribute_pure__ __purefunc
84
85/* Format attribute */
86#ifdef __GNUC__
87# define __formatfunc(t,f,a) __attribute__((format(t,f,a)))
88#else
89# define __formatfunc(t,f,a)
90#endif
91
92/* malloc() function (returns unaliased pointer) */
93#if defined(__GNUC__) && (__GNUC__ >= 3)
94# define __mallocfunc __attribute__((malloc))
95#else
96# define __mallocfunc
97#endif
98
99/* likely/unlikely */
100#if defined(__GNUC__) && (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95))
101# define __likely(x) __builtin_expect(!!(x), 1)
102# define __unlikely(x) __builtin_expect(!!(x), 0)
103#else
104# define __likely(x) (!!(x))
105# define __unlikely(x) (!!(x))
106#endif
107
108/* Possibly unused function */
109#ifdef __GNUC__
110# define __unusedfunc__attribute__((unused))
111#else
112# define __unusedfunc
113#endif
114
115/* It's all user space... */
116#define __user
117
118/* The bitwise attribute: disallow arithmetric operations */
119#ifdef __CHECKER__/* sparse only */
120# define __bitwise__attribute__((bitwise))
121#else
122# define __bitwise
123#endif
124
125/* Shut up unused warnings */
126#ifdef __GNUC__
127# define __attribute_used__ __attribute__((used))
128#else
129# define __attribute_used__
130#endif
131
132/* Compiler pragma to make an alias symbol */
133#define __ALIAS(__t, __f, __p, __a) \
134 __t __f __p __attribute__((weak, alias(#__a)));
135
136#endif
137

Archive Download this file

Revision: 676