mesa: move FLT_MAX_EXP to c99_math.h
[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
39 #include "util/macros.h"
40
41 #include "c99_compat.h" /* inline, __func__, etc. */
42
43
44 #ifdef __cplusplus
45 extern "C" {
46 #endif
47
48
49 /**
50 * Sun compilers define __i386 instead of the gcc-style __i386__
51 */
52 #ifdef __SUNPRO_C
53 # if !defined(__i386__) && defined(__i386)
54 # define __i386__
55 # elif !defined(__amd64__) && defined(__amd64)
56 # define __amd64__
57 # elif !defined(__sparc__) && defined(__sparc)
58 # define __sparc__
59 # endif
60 # if !defined(__volatile)
61 # define __volatile volatile
62 # endif
63 #endif
64
65
66 /**
67 * finite macro.
68 */
69 #if defined(_MSC_VER)
70 # define finite _finite
71 #endif
72
73
74 /**
75 * Disable assorted warnings
76 */
77 #if defined(_WIN32) && !defined(__CYGWIN__)
78 # if !defined(__GNUC__) /* mingw environment */
79 # pragma warning( disable : 4068 ) /* unknown pragma */
80 # pragma warning( disable : 4710 ) /* function 'foo' not inlined */
81 # pragma warning( disable : 4711 ) /* function 'foo' selected for automatic inline expansion */
82 # pragma warning( disable : 4127 ) /* conditional expression is constant */
83 # if defined(MESA_MINWARN)
84 # pragma warning( disable : 4244 ) /* '=' : conversion from 'const double ' to 'float ', possible loss of data */
85 # pragma warning( disable : 4018 ) /* '<' : signed/unsigned mismatch */
86 # pragma warning( disable : 4305 ) /* '=' : truncation from 'const double ' to 'float ' */
87 # pragma warning( disable : 4550 ) /* 'function' undefined; assuming extern returning int */
88 # pragma warning( disable : 4761 ) /* integral size mismatch in argument; conversion supplied */
89 # endif
90 # endif
91 #endif
92
93
94 /**
95 * PUBLIC/USED macros
96 *
97 * If we build the library with gcc's -fvisibility=hidden flag, we'll
98 * use the PUBLIC macro to mark functions that are to be exported.
99 *
100 * We also need to define a USED attribute, so the optimizer doesn't
101 * inline a static function that we later use in an alias. - ajax
102 */
103 #ifndef PUBLIC
104 # if defined(__GNUC__) || (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590))
105 # define PUBLIC __attribute__((visibility("default")))
106 # define USED __attribute__((used))
107 # else
108 # define PUBLIC
109 # define USED
110 # endif
111 #endif
112
113
114 /* XXX: Use standard `__func__` instead */
115 #ifndef __FUNCTION__
116 # define __FUNCTION__ __func__
117 #endif
118
119 /**
120 * Either define MESA_BIG_ENDIAN or MESA_LITTLE_ENDIAN, and CPU_TO_LE32.
121 * Do not use these unless absolutely necessary!
122 * Try to use a runtime test instead.
123 * For now, only used by some DRI hardware drivers for color/texel packing.
124 */
125 #if defined(BYTE_ORDER) && defined(BIG_ENDIAN) && BYTE_ORDER == BIG_ENDIAN
126 #if defined(__linux__)
127 #include <byteswap.h>
128 #define CPU_TO_LE32( x ) bswap_32( x )
129 #elif defined(__APPLE__)
130 #include <CoreFoundation/CFByteOrder.h>
131 #define CPU_TO_LE32( x ) CFSwapInt32HostToLittle( x )
132 #elif (defined(_AIX))
133 static inline GLuint CPU_TO_LE32(GLuint x)
134 {
135 return (((x & 0x000000ff) << 24) |
136 ((x & 0x0000ff00) << 8) |
137 ((x & 0x00ff0000) >> 8) |
138 ((x & 0xff000000) >> 24));
139 }
140 #elif defined(__OpenBSD__)
141 #include <sys/types.h>
142 #define CPU_TO_LE32( x ) htole32( x )
143 #else /*__linux__ */
144 #include <sys/endian.h>
145 #define CPU_TO_LE32( x ) bswap32( x )
146 #endif /*__linux__*/
147 #define MESA_BIG_ENDIAN 1
148 #else
149 #define CPU_TO_LE32( x ) ( x )
150 #define MESA_LITTLE_ENDIAN 1
151 #endif
152 #define LE32_TO_CPU( x ) CPU_TO_LE32( x )
153
154
155
156 /**
157 * Create a macro so that asm functions can be linked into compilers other
158 * than GNU C
159 */
160 #ifndef _ASMAPI
161 #if defined(_WIN32)
162 #define _ASMAPI __cdecl
163 #else
164 #define _ASMAPI
165 #endif
166 #ifdef PTR_DECL_IN_FRONT
167 #define _ASMAPIP * _ASMAPI
168 #else
169 #define _ASMAPIP _ASMAPI *
170 #endif
171 #endif
172
173 #ifdef USE_X86_ASM
174 #define _NORMAPI _ASMAPI
175 #define _NORMAPIP _ASMAPIP
176 #else
177 #define _NORMAPI
178 #define _NORMAPIP *
179 #endif
180
181 /**
182 * LONGSTRING macro
183 * gcc -pedantic warns about long string literals, LONGSTRING silences that.
184 */
185 #if !defined(__GNUC__)
186 # define LONGSTRING
187 #else
188 # define LONGSTRING __extension__
189 #endif
190
191 #define IEEE_ONE 0x3f800000
192
193 #ifndef Elements
194 #define Elements(x) (sizeof(x)/sizeof(*(x)))
195 #endif
196
197 #ifdef __cplusplus
198 }
199 #endif
200
201
202 #endif /* COMPILER_H */