2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
6 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 * Compiler-related stuff.
39 #if defined(__alpha__) && defined(CCPML)
40 #include <cpml.h> /* use Compaq's Fast Math Library on Alpha */
48 #if defined(__linux__) && defined(__i386__)
49 #include <fpu_control.h>
61 * Get standard integer types
64 typedef __int8
int8_t;
65 typedef unsigned __int8
uint8_t;
66 typedef __int16
int16_t;
67 typedef unsigned __int16
uint16_t;
68 # ifndef __eglplatform_h_
69 typedef __int32
int32_t;
71 typedef unsigned __int32
uint32_t;
72 typedef __int64
int64_t;
73 typedef unsigned __int64
uint64_t;
76 typedef __int64
intptr_t;
77 typedef unsigned __int64
uintptr_t;
79 typedef __int32
intptr_t;
80 typedef unsigned __int32
uintptr_t;
83 # define INT64_C(__val) __val##i64
84 # define UINT64_C(__val) __val##ui64
91 * Sun compilers define __i386 instead of the gcc-style __i386__
94 # if !defined(__i386__) && defined(__i386)
96 # elif !defined(__amd64__) && defined(__amd64)
98 # elif !defined(__sparc__) && defined(__sparc)
101 # if !defined(__volatile)
102 # define __volatile volatile
110 #if defined(_WIN32) && !defined(__WIN32__) && !defined(__CYGWIN__) && !defined(BUILD_FOR_SNAP)
112 # define finite _finite
113 #elif defined(__WATCOMC__)
114 # define finite _finite
119 * Disable assorted warnings
121 #if !defined(OPENSTEP) && (defined(__WIN32__) && !defined(__CYGWIN__)) && !defined(BUILD_FOR_SNAP)
122 # if !defined(__GNUC__) /* mingw environment */
123 # pragma warning( disable : 4068 ) /* unknown pragma */
124 # pragma warning( disable : 4710 ) /* function 'foo' not inlined */
125 # pragma warning( disable : 4711 ) /* function 'foo' selected for automatic inline expansion */
126 # pragma warning( disable : 4127 ) /* conditional expression is constant */
127 # if defined(MESA_MINWARN)
128 # pragma warning( disable : 4244 ) /* '=' : conversion from 'const double ' to 'float ', possible loss of data */
129 # pragma warning( disable : 4018 ) /* '<' : signed/unsigned mismatch */
130 # pragma warning( disable : 4305 ) /* '=' : truncation from 'const double ' to 'float ' */
131 # pragma warning( disable : 4550 ) /* 'function' undefined; assuming extern returning int */
132 # pragma warning( disable : 4761 ) /* integral size mismatch in argument; conversion supplied */
136 #if defined(__WATCOMC__)
137 # pragma disable_message(201) /* Disable unreachable code warnings */
145 #if defined(__GNUC__)
146 # define INLINE __inline__
147 #elif defined(__MSC__)
148 # define INLINE __inline
149 #elif defined(_MSC_VER)
150 # define INLINE __inline
152 # define INLINE __inline
153 #elif defined(__INTEL_COMPILER)
154 # define INLINE inline
155 #elif defined(__WATCOMC__) && (__WATCOMC__ >= 1100)
156 # define INLINE __inline
157 #elif defined(__SUNPRO_C) && defined(__C99FEATURES__)
158 # define INLINE inline
159 # define __inline inline
160 # define __inline__ inline
161 #elif (__STDC_VERSION__ >= 199901L) /* C99 */
162 # define INLINE inline
171 * If we build the library with gcc's -fvisibility=hidden flag, we'll
172 * use the PUBLIC macro to mark functions that are to be exported.
174 * We also need to define a USED attribute, so the optimizer doesn't
175 * inline a static function that we later use in an alias. - ajax
177 #if defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__) >= 303
178 # define PUBLIC __attribute__((visibility("default")))
179 # define USED __attribute__((used))
187 * Some compilers don't like some of Mesa's const usage. In those places use
188 * CONST instead of const. Pass -DNO_CONST to compilers where this matters.
198 * __builtin_expect macros
200 #if (!defined(__GNUC__) || __GNUC__ < 3) && (!defined(__IBMC__) || __IBMC__ < 900)
201 # define __builtin_expect(x, y) x
206 * The __FUNCTION__ gcc variable is generally only used for debugging.
207 * If we're not using gcc, define __FUNCTION__ as a cpp symbol here.
208 * Don't define it if using a newer Windows compiler.
212 # define __FUNCTION__ "VMS$NL:"
213 # elif ((!defined __GNUC__) || (__GNUC__ < 2)) && (!defined __xlC__) && \
214 (!defined(_MSC_VER) || _MSC_VER < 1300)
215 # if (__STDC_VERSION__ >= 199901L) /* C99 */ || \
216 (defined(__SUNPRO_C) && defined(__C99FEATURES__))
217 # define __FUNCTION__ __func__
219 # define __FUNCTION__ "<unknown>"
226 * Either define MESA_BIG_ENDIAN or MESA_LITTLE_ENDIAN.
227 * Do not use them unless absolutely necessary!
228 * Try to use a runtime test instead.
229 * For now, only used by some DRI hardware drivers for color/texel packing.
231 #if defined(BYTE_ORDER) && defined(BIG_ENDIAN) && BYTE_ORDER == BIG_ENDIAN
232 #if defined(__linux__)
233 #include <byteswap.h>
234 #define CPU_TO_LE32( x ) bswap_32( x )
235 #elif defined(__APPLE__)
236 #include <CoreFoundation/CFByteOrder.h>
237 #define CPU_TO_LE32( x ) CFSwapInt32HostToLittle( x )
238 #else /*__linux__ __APPLE__*/
239 #include <sys/endian.h>
240 #define CPU_TO_LE32( x ) bswap32( x )
242 #define MESA_BIG_ENDIAN 1
244 #define CPU_TO_LE32( x ) ( x )
245 #define MESA_LITTLE_ENDIAN 1
247 #define LE32_TO_CPU( x ) CPU_TO_LE32( x )
251 #if !defined(CAPI) && defined(WIN32) && !defined(BUILD_FOR_SNAP)
257 * Create a macro so that asm functions can be linked into compilers other
261 #if defined(WIN32) && !defined(BUILD_FOR_SNAP)/* was: !defined( __GNUC__ ) && !defined( VMS ) && !defined( __INTEL_COMPILER )*/
262 #define _ASMAPI __cdecl
266 #ifdef PTR_DECL_IN_FRONT
267 #define _ASMAPIP * _ASMAPI
269 #define _ASMAPIP _ASMAPI *
274 #define _NORMAPI _ASMAPI
275 #define _NORMAPIP _ASMAPIP
282 /* This is a macro on IRIX */
288 /* Turn off macro checking systems used by other libraries */
297 #if !defined(_WIN32_WCE)
298 #if defined(BUILD_FOR_SNAP) && defined(CHECKED)
299 # define ASSERT(X) _CHECK(X)
301 # define ASSERT(X) assert(X)
315 * gcc -pedantic warns about long string literals, LONGSTRING silences that.
317 #if !defined(__GNUC__) || (__GNUC__ < 2) || \
318 ((__GNUC__ == 2) && (__GNUC_MINOR__ <= 7))
321 # define LONGSTRING __extension__
326 #define M_PI (3.1415926536)
330 #define M_E (2.7182818284590452354)
334 #define ONE_DIV_LN2 (1.442695040888963456)
337 #ifndef ONE_DIV_SQRT_LN2
338 #define ONE_DIV_SQRT_LN2 (1.201122408786449815)
342 #define FLT_MAX_EXP 128
347 * USE_IEEE: Determine if we're using IEEE floating point
349 #if defined(__i386__) || defined(__386__) || defined(__sparc__) || \
350 defined(__s390x__) || defined(__powerpc__) || \
351 defined(__x86_64__) || \
352 defined(ia64) || defined(__ia64__) || \
353 defined(__hppa__) || defined(hpux) || \
354 defined(__mips) || defined(_MIPS_ARCH) || \
355 defined(__arm__) || \
356 defined(__sh__) || defined(__m32r__) || \
357 (defined(__sun) && defined(_IEEE_754)) || \
358 (defined(__alpha__) && (defined(__IEEE_FLOAT) || !defined(VMS)))
360 #define IEEE_ONE 0x3f800000
365 * START/END_FAST_MATH macros:
367 * START_FAST_MATH: Set x86 FPU to faster, 32-bit precision mode (and save
368 * original mode to a temporary).
369 * END_FAST_MATH: Restore x86 FPU to original mode.
371 #if defined(__GNUC__) && defined(__i386__)
373 * Set the x86 FPU control word to guarentee only 32 bits of precision
374 * are stored in registers. Allowing the FPU to store more introduces
375 * differences between situations where numbers are pulled out of memory
376 * vs. situations where the compiler is able to optimize register usage.
378 * In the worst case, we force the compiler to use a memory access to
379 * truncate the float, by specifying the 'volatile' keyword.
381 /* Hardware default: All exceptions masked, extended double precision,
382 * round to nearest (IEEE compliant):
384 #define DEFAULT_X86_FPU 0x037f
385 /* All exceptions masked, single precision, round to nearest:
387 #define FAST_X86_FPU 0x003f
388 /* The fldcw instruction will cause any pending FP exceptions to be
389 * raised prior to entering the block, and we clear any pending
390 * exceptions before exiting the block. Hence, asm code has free
391 * reign over the FPU while in the fast math block.
393 #if defined(NO_FAST_MATH)
394 #define START_FAST_MATH(x) \
396 static GLuint mask = DEFAULT_X86_FPU; \
397 __asm__ ( "fnstcw %0" : "=m" (*&(x)) ); \
398 __asm__ ( "fldcw %0" : : "m" (mask) ); \
401 #define START_FAST_MATH(x) \
403 static GLuint mask = FAST_X86_FPU; \
404 __asm__ ( "fnstcw %0" : "=m" (*&(x)) ); \
405 __asm__ ( "fldcw %0" : : "m" (mask) ); \
408 /* Restore original FPU mode, and clear any exceptions that may have
409 * occurred in the FAST_MATH block.
411 #define END_FAST_MATH(x) \
413 __asm__ ( "fnclex ; fldcw %0" : : "m" (*&(x)) ); \
416 #elif defined(__WATCOMC__) && defined(__386__)
417 #define DEFAULT_X86_FPU 0x037f /* See GCC comments above */
418 #define FAST_X86_FPU 0x003f /* See GCC comments above */
419 void _watcom_start_fast_math(unsigned short *x
,unsigned short *mask
);
420 #pragma aux _watcom_start_fast_math = \
421 "fnstcw word ptr [eax]" \
422 "fldcw word ptr [ecx]" \
425 void _watcom_end_fast_math(unsigned short *x
);
426 #pragma aux _watcom_end_fast_math = \
428 "fldcw word ptr [eax]" \
431 #if defined(NO_FAST_MATH)
432 #define START_FAST_MATH(x) \
434 static GLushort mask = DEFAULT_X86_FPU; \
435 _watcom_start_fast_math(&x,&mask); \
438 #define START_FAST_MATH(x) \
440 static GLushort mask = FAST_X86_FPU; \
441 _watcom_start_fast_math(&x,&mask); \
444 #define END_FAST_MATH(x) _watcom_end_fast_math(&x)
446 #elif defined(_MSC_VER) && defined(_M_IX86)
447 #define DEFAULT_X86_FPU 0x037f /* See GCC comments above */
448 #define FAST_X86_FPU 0x003f /* See GCC comments above */
449 #if defined(NO_FAST_MATH)
450 #define START_FAST_MATH(x) do {\
451 static GLuint mask = DEFAULT_X86_FPU;\
452 __asm fnstcw word ptr [x]\
453 __asm fldcw word ptr [mask]\
456 #define START_FAST_MATH(x) do {\
457 static GLuint mask = FAST_X86_FPU;\
458 __asm fnstcw word ptr [x]\
459 __asm fldcw word ptr [mask]\
462 #define END_FAST_MATH(x) do {\
464 __asm fldcw word ptr [x]\
468 #define START_FAST_MATH(x) x = 0
469 #define END_FAST_MATH(x) (void)(x)
474 #define Elements(x) (sizeof(x)/sizeof(*(x)))
484 #endif /* COMPILER_H */