Merge branch 'mesa_7_7_branch'
[mesa.git] / src / gallium / include / pipe / p_compiler.h
1 /**************************************************************************
2 *
3 * Copyright 2007-2008 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28 #ifndef P_COMPILER_H
29 #define P_COMPILER_H
30
31
32 #include "p_config.h"
33
34 #ifndef XFree86Server
35 #include <stdlib.h>
36 #include <string.h>
37 #else
38 #include "xf86_ansic.h"
39 #include "xf86_libc.h"
40 #endif
41
42
43 #if defined(_WIN32) && !defined(__WIN32__)
44 #define __WIN32__
45 #endif
46
47 #if defined(_MSC_VER)
48
49 /* Avoid 'expression is always true' warning */
50 #pragma warning(disable: 4296)
51
52 #endif /* _MSC_VER */
53
54
55 /*
56 * Alternative stdint.h and stdbool.h headers are supplied in include/c99 for
57 * systems that lack it.
58 */
59 #ifndef __STDC_LIMIT_MACROS
60 #define __STDC_LIMIT_MACROS 1
61 #endif
62 #include <stdint.h>
63 #include <stdbool.h>
64
65
66 #ifndef __HAIKU__
67 typedef unsigned int uint;
68 typedef unsigned short ushort;
69 #endif
70 typedef unsigned char ubyte;
71
72 typedef unsigned char boolean;
73 #ifndef TRUE
74 #define TRUE true
75 #endif
76 #ifndef FALSE
77 #define FALSE false
78 #endif
79
80
81 /* Function inlining */
82 #ifndef INLINE
83 # ifdef __cplusplus
84 # define INLINE inline
85 # elif defined(__GNUC__)
86 # define INLINE __inline__
87 # elif defined(_MSC_VER)
88 # define INLINE __inline
89 # elif defined(__ICL)
90 # define INLINE __inline
91 # elif defined(__INTEL_COMPILER)
92 # define INLINE inline
93 # elif defined(__WATCOMC__) && (__WATCOMC__ >= 1100)
94 # define INLINE __inline
95 # elif defined(__SUNPRO_C) && defined(__C99FEATURES__)
96 # define INLINE inline
97 # elif (__STDC_VERSION__ >= 199901L) /* C99 */
98 # define INLINE inline
99 # else
100 # define INLINE
101 # endif
102 #endif
103
104
105 /* Function visibility */
106 #ifndef PUBLIC
107 # if (defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__) >= 303) \
108 || (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590))
109 # define PUBLIC __attribute__((visibility("default")))
110 # else
111 # define PUBLIC
112 # endif
113 #endif
114
115
116 /* The __FUNCTION__ gcc variable is generally only used for debugging.
117 * If we're not using gcc, define __FUNCTION__ as a cpp symbol here.
118 */
119 #ifndef __FUNCTION__
120 # if (!defined(__GNUC__) || (__GNUC__ < 2))
121 # if (__STDC_VERSION__ >= 199901L) /* C99 */ || \
122 (defined(__SUNPRO_C) && defined(__C99FEATURES__))
123 # define __FUNCTION__ __func__
124 # else
125 # define __FUNCTION__ "<unknown>"
126 # endif
127 # endif
128 #endif
129
130
131
132 /* This should match linux gcc cdecl semantics everywhere, so that we
133 * just codegen one calling convention on all platforms.
134 */
135 #ifdef _MSC_VER
136 #define PIPE_CDECL __cdecl
137 #else
138 #define PIPE_CDECL
139 #endif
140
141
142
143 /* Macros for data alignment. */
144 #if defined(__GNUC__) || (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590))
145
146 /* See http://gcc.gnu.org/onlinedocs/gcc-4.4.2/gcc/Type-Attributes.html */
147 #define PIPE_ALIGN_TYPE(_alignment, _type) _type __attribute__((aligned(_alignment)))
148
149 /* See http://gcc.gnu.org/onlinedocs/gcc-4.4.2/gcc/Variable-Attributes.html */
150 #define PIPE_ALIGN_VAR(_alignment) __attribute__((aligned(_alignment)))
151
152 #if (__GNUC__ > 4 || (__GNUC__ == 4 &&__GNUC_MINOR__>1)) && !defined(PIPE_ARCH_X86_64)
153 #define PIPE_ALIGN_STACK __attribute__((force_align_arg_pointer))
154 #else
155 #define PIPE_ALIGN_STACK
156 #endif
157
158 #elif defined(_MSC_VER)
159
160 /* See http://msdn.microsoft.com/en-us/library/83ythb65.aspx */
161 #define PIPE_ALIGN_TYPE(_alignment, _type) __declspec(align(_alignment)) _type
162 #define PIPE_ALIGN_VAR(_alignment) __declspec(align(_alignment))
163
164 #define PIPE_ALIGN_STACK
165
166 #elif defined(SWIG)
167
168 #define PIPE_ALIGN_TYPE(_alignment, _type) _type
169 #define PIPE_ALIGN_VAR(_alignment)
170
171 #define PIPE_ALIGN_STACK
172
173 #else
174
175 #error "Unsupported compiler"
176
177 #endif
178
179
180
181 #endif /* P_COMPILER_H */