mesa: only include ctype.h where it's used
[mesa.git] / src / mesa / main / compiler.h
1 /*
2 * Mesa 3-D graphics library
3 *
4 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
5 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
24 */
25
26
27 /**
28 * \file compiler.h
29 * Compiler-related stuff.
30 */
31
32
33 #ifndef COMPILER_H
34 #define COMPILER_H
35
36
37 #include <assert.h>
38 #include <math.h>
39 #include <limits.h>
40 #include <stdlib.h>
41 #include <stdio.h>
42 #include <string.h>
43 #include <float.h>
44
45 #include "util/macros.h"
46
47 #include "c99_compat.h" /* inline, __func__, etc. */
48
49
50 #ifdef __cplusplus
51 extern "C" {
52 #endif
53
54
55 /**
56 * Get standard integer types
57 */
58 #include <stdint.h>
59
60
61 /**
62 * Sun compilers define __i386 instead of the gcc-style __i386__
63 */
64 #ifdef __SUNPRO_C
65 # if !defined(__i386__) && defined(__i386)
66 # define __i386__
67 # elif !defined(__amd64__) && defined(__amd64)
68 # define __amd64__
69 # elif !defined(__sparc__) && defined(__sparc)
70 # define __sparc__
71 # endif
72 # if !defined(__volatile)
73 # define __volatile volatile
74 # endif
75 #endif
76
77
78 /**
79 * finite macro.
80 */
81 #if defined(_MSC_VER)
82 # define finite _finite
83 #endif
84
85
86 /**
87 * Disable assorted warnings
88 */
89 #if defined(_WIN32) && !defined(__CYGWIN__)
90 # if !defined(__GNUC__) /* mingw environment */
91 # pragma warning( disable : 4068 ) /* unknown pragma */
92 # pragma warning( disable : 4710 ) /* function 'foo' not inlined */
93 # pragma warning( disable : 4711 ) /* function 'foo' selected for automatic inline expansion */
94 # pragma warning( disable : 4127 ) /* conditional expression is constant */
95 # if defined(MESA_MINWARN)
96 # pragma warning( disable : 4244 ) /* '=' : conversion from 'const double ' to 'float ', possible loss of data */
97 # pragma warning( disable : 4018 ) /* '<' : signed/unsigned mismatch */
98 # pragma warning( disable : 4305 ) /* '=' : truncation from 'const double ' to 'float ' */
99 # pragma warning( disable : 4550 ) /* 'function' undefined; assuming extern returning int */
100 # pragma warning( disable : 4761 ) /* integral size mismatch in argument; conversion supplied */
101 # endif
102 # endif
103 #endif
104
105
106
107 /* XXX: Use standard `inline` keyword instead */
108 #ifndef INLINE
109 # define INLINE inline
110 #endif
111
112
113 /**
114 * PUBLIC/USED macros
115 *
116 * If we build the library with gcc's -fvisibility=hidden flag, we'll
117 * use the PUBLIC macro to mark functions that are to be exported.
118 *
119 * We also need to define a USED attribute, so the optimizer doesn't
120 * inline a static function that we later use in an alias. - ajax
121 */
122 #ifndef PUBLIC
123 # if defined(__GNUC__) || (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590))
124 # define PUBLIC __attribute__((visibility("default")))
125 # define USED __attribute__((used))
126 # else
127 # define PUBLIC
128 # define USED
129 # endif
130 #endif
131
132
133 /* XXX: Use standard `__func__` instead */
134 #ifndef __FUNCTION__
135 # define __FUNCTION__ __func__
136 #endif
137
138 /**
139 * Either define MESA_BIG_ENDIAN or MESA_LITTLE_ENDIAN, and CPU_TO_LE32.
140 * Do not use these unless absolutely necessary!
141 * Try to use a runtime test instead.
142 * For now, only used by some DRI hardware drivers for color/texel packing.
143 */
144 #if defined(BYTE_ORDER) && defined(BIG_ENDIAN) && BYTE_ORDER == BIG_ENDIAN
145 #if defined(__linux__)
146 #include <byteswap.h>
147 #define CPU_TO_LE32( x ) bswap_32( x )
148 #elif defined(__APPLE__)
149 #include <CoreFoundation/CFByteOrder.h>
150 #define CPU_TO_LE32( x ) CFSwapInt32HostToLittle( x )
151 #elif (defined(_AIX))
152 static inline GLuint CPU_TO_LE32(GLuint x)
153 {
154 return (((x & 0x000000ff) << 24) |
155 ((x & 0x0000ff00) << 8) |
156 ((x & 0x00ff0000) >> 8) |
157 ((x & 0xff000000) >> 24));
158 }
159 #elif defined(__OpenBSD__)
160 #include <sys/types.h>
161 #define CPU_TO_LE32( x ) htole32( x )
162 #else /*__linux__ */
163 #include <sys/endian.h>
164 #define CPU_TO_LE32( x ) bswap32( x )
165 #endif /*__linux__*/
166 #define MESA_BIG_ENDIAN 1
167 #else
168 #define CPU_TO_LE32( x ) ( x )
169 #define MESA_LITTLE_ENDIAN 1
170 #endif
171 #define LE32_TO_CPU( x ) CPU_TO_LE32( x )
172
173
174
175 /**
176 * Create a macro so that asm functions can be linked into compilers other
177 * than GNU C
178 */
179 #ifndef _ASMAPI
180 #if defined(_WIN32)
181 #define _ASMAPI __cdecl
182 #else
183 #define _ASMAPI
184 #endif
185 #ifdef PTR_DECL_IN_FRONT
186 #define _ASMAPIP * _ASMAPI
187 #else
188 #define _ASMAPIP _ASMAPI *
189 #endif
190 #endif
191
192 #ifdef USE_X86_ASM
193 #define _NORMAPI _ASMAPI
194 #define _NORMAPIP _ASMAPIP
195 #else
196 #define _NORMAPI
197 #define _NORMAPIP *
198 #endif
199
200
201 /*
202 * A trick to suppress uninitialized variable warning without generating any
203 * code
204 */
205 #define uninitialized_var(x) x = x
206
207
208 /**
209 * LONGSTRING macro
210 * gcc -pedantic warns about long string literals, LONGSTRING silences that.
211 */
212 #if !defined(__GNUC__)
213 # define LONGSTRING
214 #else
215 # define LONGSTRING __extension__
216 #endif
217
218 #ifndef ONE_DIV_SQRT_LN2
219 #define ONE_DIV_SQRT_LN2 (1.201122408786449815)
220 #endif
221
222 #ifndef FLT_MAX_EXP
223 #define FLT_MAX_EXP 128
224 #endif
225
226 #define IEEE_ONE 0x3f800000
227
228 #ifndef Elements
229 #define Elements(x) (sizeof(x)/sizeof(*(x)))
230 #endif
231
232 #ifdef __cplusplus
233 }
234 #endif
235
236
237 #endif /* COMPILER_H */