Debian Codegraph @

nx-X11/extras/Mesa/src/mesa/main/imports.h

raw
1 /*
2 * Mesa 3-D graphics library
3 * Version: 6.4.1
4 *
5 * Copyright (C) 1999-2005 Brian Paul 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 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25
26 /**
27 * \file imports.h
28 * Standard C library function wrappers.
29 *
30 * This file provides wrappers for all the standard C library functions
31 * like malloc(), free(), printf(), getenv(), etc.
32 */
33
34
35 #ifndef IMPORTS_H
36 #define IMPORTS_H
37
38
39 /* XXX some of the stuff in glheader.h should be moved into this file.
40 */
41 #include "glheader.h"
42
43
44 #ifdef __cplusplus
45 extern "C" {
46 #endif
47
48
49 /**********************************************************************/
50 /** \name General macros */
51 /*@{*/
52
53 #ifndef NULL
54 #define NULL 0
55 #endif
56
57 /*@}*/
58
59
60 /**********************************************************************/
61 /** Memory macros */
62 /*@{*/
63
64 /** Allocate \p BYTES bytes */
65 #define MALLOC(BYTES) _mesa_malloc(BYTES)
66 /** Allocate and zero \p BYTES bytes */
67 #define CALLOC(BYTES) _mesa_calloc(BYTES)
68 /** Allocate a structure of type \p T */
69 #define MALLOC_STRUCT(T) (struct T *) _mesa_malloc(sizeof(struct T))
70 /** Allocate and zero a structure of type \p T */
71 #define CALLOC_STRUCT(T) (struct T *) _mesa_calloc(sizeof(struct T))
72 /** Free memory */
73 #define FREE(PTR) _mesa_free(PTR)
74
75 /** Allocate \p BYTES aligned at \p N bytes */
76 #define ALIGN_MALLOC(BYTES, N) _mesa_align_malloc(BYTES, N)
77 /** Allocate and zero \p BYTES bytes aligned at \p N bytes */
78 #define ALIGN_CALLOC(BYTES, N) _mesa_align_calloc(BYTES, N)
79 /** Allocate a structure of type \p T aligned at \p N bytes */
80 #define ALIGN_MALLOC_STRUCT(T, N) (struct T *) _mesa_align_malloc(sizeof(struct T), N)
81 /** Allocate and zero a structure of type \p T aligned at \p N bytes */
82 #define ALIGN_CALLOC_STRUCT(T, N) (struct T *) _mesa_align_calloc(sizeof(struct T), N)
83 /** Free aligned memory */
84 #define ALIGN_FREE(PTR) _mesa_align_free(PTR)
85
86 /** Copy \p BYTES bytes from \p SRC into \p DST */
87 #define MEMCPY( DST, SRC, BYTES) _mesa_memcpy(DST, SRC, BYTES)
88 /** Set \p N bytes in \p DST to \p VAL */
89 #define MEMSET( DST, VAL, N ) _mesa_memset(DST, VAL, N)
90
91 /*@}*/
92
93
94 /*
95 * For GL_ARB_vertex_buffer_object we need to treat vertex array pointers
96 * as offsets into buffer stores. Since the vertex array pointer and
97 * buffer store pointer are both pointers and we need to add them, we use
98 * this macro.
99 * Both pointers/offsets are expressed in bytes.
100 */
101 #define ADD_POINTERS(A, B) ( (GLubyte *) (A) + (uintptr_t) (B) )
102
103
104 /**********************************************************************/
105 /** \name [Pseudo] static array declaration.
106 *
107 * MACs and BeOS don't support static larger than 32kb, so ...
108 */
109 /*@{*/
110
111 /**
112 * \def DEFARRAY
113 * Define a [static] unidimensional array
114 */
115
116 /**
117 * \def DEFMARRAY
118 * Define a [static] bi-dimensional array
119 */
120
121 /**
122 * \def DEFMNARRAY
123 * Define a [static] tri-dimensional array
124 */
125
126 /**
127 * \def CHECKARRAY
128 * Verifies a [static] array was properly allocated.
129 */
130
131 /**
132 * \def UNDEFARRAY
133 * Undefine (free) a [static] array.
134 */
135
136 #if defined(macintosh) && !defined(__MRC__)
137 /*extern char *AGLAlloc(int size);*/
138 /*extern void AGLFree(char* ptr);*/
139 # define DEFARRAY(TYPE,NAME,SIZE) TYPE *NAME = (TYPE*)_mesa_alloc(sizeof(TYPE)*(SIZE))
140 # define DEFMARRAY(TYPE,NAME,SIZE1,SIZE2) TYPE (*NAME)[SIZE2] = (TYPE(*)[SIZE2])_mesa_alloc(sizeof(TYPE)*(SIZE1)*(SIZE2))
141 # define DEFMNARRAY(TYPE,NAME,SIZE1,SIZE2,SIZE3) TYPE (*NAME)[SIZE2][SIZE3] = (TYPE(*)[SIZE2][SIZE3])_mesa_alloc(sizeof(TYPE)*(SIZE1)*(SIZE2)*(SIZE3))
142 # define CHECKARRAY(NAME,CMD) do {if (!(NAME)) {CMD;}} while (0)
143 # define UNDEFARRAY(NAME) do {if ((NAME)) {_mesa_free((char*)NAME);} }while (0)
144 #elif defined(__BEOS__)
145 # define DEFARRAY(TYPE,NAME,SIZE) TYPE *NAME = (TYPE*)_mesa_malloc(sizeof(TYPE)*(SIZE))
146 # define DEFMARRAY(TYPE,NAME,SIZE1,SIZE2) TYPE (*NAME)[SIZE2] = (TYPE(*)[SIZE2])_mesa_malloc(sizeof(TYPE)*(SIZE1)*(SIZE2))
147 # define DEFMNARRAY(TYPE,NAME,SIZE1,SIZE2,SIZE3) TYPE (*NAME)[SIZE2][SIZE3] = (TYPE(*)[SIZE2][SIZE3])_mesa_malloc(sizeof(TYPE)*(SIZE1)*(SIZE2)*(SIZE3))
148 # define CHECKARRAY(NAME,CMD) do {if (!(NAME)) {CMD;}} while (0)
149 # define UNDEFARRAY(NAME) do {if ((NAME)) {_mesa_free((char*)NAME);} }while (0)
150 #else
151 # define DEFARRAY(TYPE,NAME,SIZE) TYPE NAME[SIZE]
152 # define DEFMARRAY(TYPE,NAME,SIZE1,SIZE2) TYPE NAME[SIZE1][SIZE2]
153 # define DEFMNARRAY(TYPE,NAME,SIZE1,SIZE2,SIZE3) TYPE NAME[SIZE1][SIZE2][SIZE3]
154 # define CHECKARRAY(NAME,CMD) do {} while(0)
155 # define UNDEFARRAY(NAME)
156 #endif
157
158 /*@}*/
159
160
161 /**
162 * Sometimes we treat GLfloats as GLints. On x86 systems, moving a float
163 * as a int (thereby using integer registers instead of FP registers) is
164 * a performance win. Typically, this can be done with ordinary casts.
165 * But with gcc's -fstrict-aliasing flag (which defaults to on in gcc 3.0)
166 * these casts generate warnings.
167 * The following union typedef is used to solve that.
168 */
169 typedef union { GLfloat f; GLint i; } fi_type;
170
171
172
173 /**********************************************************************
174 * Math macros
175 */
176
177 #define MAX_GLUSHORT 0xffff
178 #define MAX_GLUINT 0xffffffff
179
180 #ifndef M_PI
181 #define M_PI (3.1415926536)
182 #endif
183
184 #ifndef M_E
185 #define M_E (2.7182818284590452354)
186 #endif
187
188
189 /* XXX this is a bit of a hack needed for compilation within XFree86 */
190 #ifndef FLT_MIN
191 #define FLT_MIN (1.0e-37)
192 #endif
193
194 /* Degrees to radians conversion: */
195 #define DEG2RAD (M_PI/180.0)
196
197
198 /***
199 *** USE_IEEE: Determine if we're using IEEE floating point
200 ***/
201 #if defined(__i386__) || defined(__386__) || defined(__sparc__) || \
202 defined(__s390x__) || defined(__powerpc__) || \
203 defined(__amd64__) || \
204 defined(ia64) || defined(__ia64__) || \
205 defined(__hppa__) || defined(hpux) || \
206 defined(__mips) || defined(_MIPS_ARCH) || \
207 defined(__arm__) || \
208 defined(__sh__) || \
209 (defined(__alpha__) && (defined(__IEEE_FLOAT) || !defined(VMS)))
210 #define USE_IEEE
211 #define IEEE_ONE 0x3f800000
212 #endif
213
214
215 /***
216 *** SQRTF: single-precision square root
217 ***/
218 #if 0 /* _mesa_sqrtf() not accurate enough - temporarily disabled */
219 # define SQRTF(X) _mesa_sqrtf(X)
220 #elif defined(XFree86LOADER) && defined(IN_MODULE)
221 # define SQRTF(X) (float) xf86sqrt((float) (X))
222 #else
223 # define SQRTF(X) (float) sqrt((float) (X))
224 #endif
225
226
227 /***
228 *** INV_SQRTF: single-precision inverse square root
229 ***/
230 #if 0
231 #define INV_SQRTF(X) _mesa_inv_sqrt(X)
232 #else
233 #define INV_SQRTF(X) (1.0F / SQRTF(X)) /* this is faster on a P4 */
234 #endif
235
236
237 /***
238 *** LOG2: Log base 2 of float
239 ***/
240 #ifdef USE_IEEE
241 #if 0
242 /* This is pretty fast, but not accurate enough (only 2 fractional bits).
243 * Based on code from http://www.stereopsis.com/log2.html
244 */
245 static INLINE GLfloat LOG2(GLfloat x)
246 {
247 const GLfloat y = x * x * x * x;
248 const GLuint ix = *((GLuint *) &y);
249 const GLuint exp = (ix >> 23) & 0xFF;
250 const GLint log2 = ((GLint) exp) - 127;
251 return (GLfloat) log2 * (1.0 / 4.0); /* 4, because of x^4 above */
252 }
253 #endif
254 /* Pretty fast, and accurate.
255 * Based on code from http://www.flipcode.com/totd/
256 */
257 static INLINE GLfloat LOG2(GLfloat val)
258 {
259 fi_type num;
260 GLint log_2;
261 num.f = val;
262 log_2 = ((num.i >> 23) & 255) - 128;
263 num.i &= ~(255 << 23);
264 num.i += 127 << 23;
265 num.f = ((-1.0f/3) * num.f + 2) * num.f - 2.0f/3;
266 return num.f + log_2;
267 }
268 #elif defined(XFree86LOADER) && defined(IN_MODULE)
269 #define LOG2(x) ((GLfloat) (xf86log(x) * 1.442695))
270 #else
271 /*
272 * NOTE: log_base_2(x) = log(x) / log(2)
273 * NOTE: 1.442695 = 1/log(2).
274 */
275 #define LOG2(x) ((GLfloat) (log(x) * 1.442695F))
276 #endif
277
278
279 /***
280 *** IS_INF_OR_NAN: test if float is infinite or NaN
281 ***/
282 #ifdef USE_IEEE
283 static INLINE int IS_INF_OR_NAN( float x )
284 {
285 fi_type tmp;
286 tmp.f = x;
287 return !(int)((unsigned int)((tmp.i & 0x7fffffff)-0x7f800000) >> 31);
288 }
289 #elif defined(isfinite)
290 #define IS_INF_OR_NAN(x) (!isfinite(x))
291 #elif defined(finite)
292 #define IS_INF_OR_NAN(x) (!finite(x))
293 #elif defined(__VMS)
294 #define IS_INF_OR_NAN(x) (!finite(x))
295 #elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
296 #define IS_INF_OR_NAN(x) (!isfinite(x))
297 #else
298 #define IS_INF_OR_NAN(x) (!finite(x))
299 #endif
300
301
302 /***
303 *** IS_NEGATIVE: test if float is negative
304 ***/
305 #if defined(USE_IEEE)
306 static INLINE int GET_FLOAT_BITS( float x )
307 {
308 fi_type fi;
309 fi.f = x;
310 return fi.i;
311 }
312 #define IS_NEGATIVE(x) (GET_FLOAT_BITS(x) < 0)
313 #else
314 #define IS_NEGATIVE(x) (x < 0.0F)
315 #endif
316
317
318 /***
319 *** DIFFERENT_SIGNS: test if two floats have opposite signs
320 ***/
321 #if defined(USE_IEEE)
322 #define DIFFERENT_SIGNS(x,y) ((GET_FLOAT_BITS(x) ^ GET_FLOAT_BITS(y)) & (1<<31))
323 #else
324 /* Could just use (x*y<0) except for the flatshading requirements.
325 * Maybe there's a better way?
326 */
327 #define DIFFERENT_SIGNS(x,y) ((x) * (y) <= 0.0F && (x) - (y) != 0.0F)
328 #endif
329
330
331 /***
332 *** CEILF: ceiling of float
333 *** FLOORF: floor of float
334 *** FABSF: absolute value of float
335 *** LOGF: the natural logarithm (base e) of the value
336 *** EXPF: raise e to the value
337 *** LDEXPF: multiply value by an integral power of two
338 *** FREXPF: extract mantissa and exponent from value
339 ***/
340 #if defined(XFree86LOADER) && defined(IN_MODULE)
341 #define CEILF(x) ((GLfloat) xf86ceil(x))
342 #define FLOORF(x) ((GLfloat) xf86floor(x))
343 #define FABSF(x) ((GLfloat) xf86fabs(x))
344 #define LOGF(x) ((GLfloat) xf86log(x))
345 #define EXPF(x) ((GLfloat) xf86exp(x))
346 #define LDEXPF(x,y) ((GLfloat) xf86ldexp(x,y))
347 #define FREXPF(x,y) ((GLfloat) xf86frexp(x,y))
348 #elif defined(__gnu_linux__)
349 /* C99 functions */
350 #define CEILF(x) ceilf(x)
351 #define FLOORF(x) floorf(x)
352 #define FABSF(x) fabsf(x)
353 #define LOGF(x) logf(x)
354 #define EXPF(x) expf(x)
355 #define LDEXPF(x,y) ldexpf(x,y)
356 #define FREXPF(x,y) frexpf(x,y)
357 #else
358 #define CEILF(x) ((GLfloat) ceil(x))
359 #define FLOORF(x) ((GLfloat) floor(x))
360 #define FABSF(x) ((GLfloat) fabs(x))
361 #define LOGF(x) ((GLfloat) log(x))
362 #define EXPF(x) ((GLfloat) exp(x))
363 #define LDEXPF(x,y) ((GLfloat) ldexp(x,y))
364 #define FREXPF(x,y) ((GLfloat) frexp(x,y))
365 #endif
366
367
368 /***
369 *** IROUND: return (as an integer) float rounded to nearest integer
370 ***/
371 #if defined(USE_SPARC_ASM) && defined(__GNUC__) && defined(__sparc__)
372 static INLINE int iround(float f)
373 {
374 int r;
375 __asm__ ("fstoi %1, %0" : "=f" (r) : "f" (f));
376 return r;
377 }
378 #define IROUND(x) iround(x)
379 #elif defined(USE_X86_ASM) && defined(__GNUC__) && defined(__i386__) && \
380 (!defined(__BEOS__) || (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95)))
381 static INLINE int iround(float f)
382 {
383 int r;
384 __asm__ ("fistpl %0" : "=m" (r) : "t" (f) : "st");
385 return r;
386 }
387 #define IROUND(x) iround(x)
388 #elif defined(USE_X86_ASM) && defined(__MSC__) && defined(__WIN32__)
389 static INLINE int iround(float f)
390 {
391 int r;
392 _asm {
393 fld f
394 fistp r
395 }
396 return r;
397 }
398 #define IROUND(x) iround(x)
399 #elif defined(__WATCOMC__) && defined(__386__)
400 long iround(float f);
401 #pragma aux iround = \
402 "push eax" \
403 "fistp dword ptr [esp]" \
404 "pop eax" \
405 parm [8087] \
406 value [eax] \
407 modify exact [eax];
408 #define IROUND(x) iround(x)
409 #else
410 #define IROUND(f) ((int) (((f) >= 0.0F) ? ((f) + 0.5F) : ((f) - 0.5F)))
411 #endif
412
413
414 /***
415 *** IROUND_POS: return (as an integer) positive float rounded to nearest int
416 ***/
417 #ifdef DEBUG
418 #define IROUND_POS(f) (assert((f) >= 0.0F), IROUND(f))
419 #else
420 #define IROUND_POS(f) (IROUND(f))
421 #endif
422
423
424 /***
425 *** IFLOOR: return (as an integer) floor of float
426 ***/
427 #if defined(USE_X86_ASM) && defined(__GNUC__) && defined(__i386__)
428 /*
429 * IEEE floor for computers that round to nearest or even.
430 * 'f' must be between -4194304 and 4194303.
431 * This floor operation is done by "(iround(f + .5) + iround(f - .5)) >> 1",
432 * but uses some IEEE specific tricks for better speed.
433 * Contributed by Josh Vanderhoof
434 */
435 static INLINE int ifloor(float f)
436 {
437 int ai, bi;
438 double af, bf;
439 af = (3 << 22) + 0.5 + (double)f;
440 bf = (3 << 22) + 0.5 - (double)f;
441 /* GCC generates an extra fstp/fld without this. */
442 __asm__ ("fstps %0" : "=m" (ai) : "t" (af) : "st");
443 __asm__ ("fstps %0" : "=m" (bi) : "t" (bf) : "st");
444 return (ai - bi) >> 1;
445 }
446 #define IFLOOR(x) ifloor(x)
447 #elif defined(USE_IEEE)
448 static INLINE int ifloor(float f)
449 {
450 int ai, bi;
451 double af, bf;
452 fi_type u;
453
454 af = (3 << 22) + 0.5 + (double)f;
455 bf = (3 << 22) + 0.5 - (double)f;
456 u.f = (float) af; ai = u.i;
457 u.f = (float) bf; bi = u.i;
458 return (ai - bi) >> 1;
459 }
460 #define IFLOOR(x) ifloor(x)
461 #else
462 static INLINE int ifloor(float f)
463 {
464 int i = IROUND(f);
465 return (i > f) ? i - 1 : i;
466 }
467 #define IFLOOR(x) ifloor(x)
468 #endif
469
470
471 /***
472 *** ICEIL: return (as an integer) ceiling of float
473 ***/
474 #if defined(USE_X86_ASM) && defined(__GNUC__) && defined(__i386__)
475 /*
476 * IEEE ceil for computers that round to nearest or even.
477 * 'f' must be between -4194304 and 4194303.
478 * This ceil operation is done by "(iround(f + .5) + iround(f - .5) + 1) >> 1",
479 * but uses some IEEE specific tricks for better speed.
480 * Contributed by Josh Vanderhoof
481 */
482 static INLINE int iceil(float f)
483 {
484 int ai, bi;
485 double af, bf;
486 af = (3 << 22) + 0.5 + (double)f;
487 bf = (3 << 22) + 0.5 - (double)f;
488 /* GCC generates an extra fstp/fld without this. */
489 __asm__ ("fstps %0" : "=m" (ai) : "t" (af) : "st");
490 __asm__ ("fstps %0" : "=m" (bi) : "t" (bf) : "st");
491 return (ai - bi + 1) >> 1;
492 }
493 #define ICEIL(x) iceil(x)
494 #elif defined(USE_IEEE)
495 static INLINE int iceil(float f)
496 {
497 int ai, bi;
498 double af, bf;
499 fi_type u;
500 af = (3 << 22) + 0.5 + (double)f;
501 bf = (3 << 22) + 0.5 - (double)f;
502 u.f = (float) af; ai = u.i;
503 u.f = (float) bf; bi = u.i;
504 return (ai - bi + 1) >> 1;
505 }
506 #define ICEIL(x) iceil(x)
507 #else
508 static INLINE int iceil(float f)
509 {
510 int i = IROUND(f);
511 return (i < f) ? i + 1 : i;
512 }
513 #define ICEIL(x) iceil(x)
514 #endif
515
516
517 /***
518 *** UNCLAMPED_FLOAT_TO_UBYTE: clamp float to [0,1] and map to ubyte in [0,255]
519 *** CLAMPED_FLOAT_TO_UBYTE: map float known to be in [0,1] to ubyte in [0,255]
520 ***/
521 #if defined(USE_IEEE) && !defined(DEBUG)
522 #define IEEE_0996 0x3f7f0000 /* 0.996 or so */
523 /* This function/macro is sensitive to precision. Test very carefully
524 * if you change it!
525 */
526 #define UNCLAMPED_FLOAT_TO_UBYTE(UB, F) \
527 do { \
528 fi_type __tmp; \
529 __tmp.f = (F); \
530 if (__tmp.i < 0) \
531 UB = (GLubyte) 0; \
532 else if (__tmp.i >= IEEE_0996) \
533 UB = (GLubyte) 255; \
534 else { \
535 __tmp.f = __tmp.f * (255.0F/256.0F) + 32768.0F; \
536 UB = (GLubyte) __tmp.i; \
537 } \
538 } while (0)
539 #define CLAMPED_FLOAT_TO_UBYTE(UB, F) \
540 do { \
541 fi_type __tmp; \
542 __tmp.f = (F) * (255.0F/256.0F) + 32768.0F; \
543 UB = (GLubyte) __tmp.i; \
544 } while (0)
545 #else
546 #define UNCLAMPED_FLOAT_TO_UBYTE(ub, f) \
547 ub = ((GLubyte) IROUND(CLAMP((f), 0.0F, 1.0F) * 255.0F))
548 #define CLAMPED_FLOAT_TO_UBYTE(ub, f) \
549 ub = ((GLubyte) IROUND((f) * 255.0F))
550 #endif
551
552
553 /***
554 *** COPY_FLOAT: copy a float from src to dest.
555 ***/
556 #define COPY_FLOAT( dst, src ) (dst) = (src)
557
558
559 /***
560 *** START_FAST_MATH: Set x86 FPU to faster, 32-bit precision mode (and save
561 *** original mode to a temporary).
562 *** END_FAST_MATH: Restore x86 FPU to original mode.
563 ***/
564 #if defined(__GNUC__) && defined(__i386__)
565 /*
566 * Set the x86 FPU control word to guarentee only 32 bits of precision
567 * are stored in registers. Allowing the FPU to store more introduces
568 * differences between situations where numbers are pulled out of memory
569 * vs. situations where the compiler is able to optimize register usage.
570 *
571 * In the worst case, we force the compiler to use a memory access to
572 * truncate the float, by specifying the 'volatile' keyword.
573 */
574 /* Hardware default: All exceptions masked, extended double precision,
575 * round to nearest (IEEE compliant):
576 */
577 #define DEFAULT_X86_FPU 0x037f
578 /* All exceptions masked, single precision, round to nearest:
579 */
580 #define FAST_X86_FPU 0x003f
581 /* The fldcw instruction will cause any pending FP exceptions to be
582 * raised prior to entering the block, and we clear any pending
583 * exceptions before exiting the block. Hence, asm code has free
584 * reign over the FPU while in the fast math block.
585 */
586 #if defined(NO_FAST_MATH)
587 #define START_FAST_MATH(x) \
588 do { \
589 static GLuint mask = DEFAULT_X86_FPU; \
590 __asm__ ( "fnstcw %0" : "=m" (*&(x)) ); \
591 __asm__ ( "fldcw %0" : : "m" (mask) ); \
592 } while (0)
593 #else
594 #define START_FAST_MATH(x) \
595 do { \
596 static GLuint mask = FAST_X86_FPU; \
597 __asm__ ( "fnstcw %0" : "=m" (*&(x)) ); \
598 __asm__ ( "fldcw %0" : : "m" (mask) ); \
599 } while (0)
600 #endif
601 /* Restore original FPU mode, and clear any exceptions that may have
602 * occurred in the FAST_MATH block.
603 */
604 #define END_FAST_MATH(x) \
605 do { \
606 __asm__ ( "fnclex ; fldcw %0" : : "m" (*&(x)) ); \
607 } while (0)
608
609 #elif defined(__WATCOMC__) && defined(__386__)
610 #define DEFAULT_X86_FPU 0x037f /* See GCC comments above */
611 #define FAST_X86_FPU 0x003f /* See GCC comments above */
612 void _watcom_start_fast_math(unsigned short *x,unsigned short *mask);
613 #pragma aux _watcom_start_fast_math = \
614 "fnstcw word ptr [eax]" \
615 "fldcw word ptr [ecx]" \
616 parm [eax] [ecx] \
617 modify exact [];
618 void _watcom_end_fast_math(unsigned short *x);
619 #pragma aux _watcom_end_fast_math = \
620 "fnclex" \
621 "fldcw word ptr [eax]" \
622 parm [eax] \
623 modify exact [];
624 #if defined(NO_FAST_MATH)
625 #define START_FAST_MATH(x) \
626 do { \
627 static GLushort mask = DEFAULT_X86_FPU; \
628 _watcom_start_fast_math(&x,&mask); \
629 } while (0)
630 #else
631 #define START_FAST_MATH(x) \
632 do { \
633 static GLushort mask = FAST_X86_FPU; \
634 _watcom_start_fast_math(&x,&mask); \
635 } while (0)
636 #endif
637 #define END_FAST_MATH(x) _watcom_end_fast_math(&x)
638 #else
639 #define START_FAST_MATH(x) x = 0
640 #define END_FAST_MATH(x) (void)(x)
641 #endif
642
643
644
645 /**********************************************************************
646 * Functions
647 */
648
649 extern void *
650 _mesa_malloc( size_t bytes );
651
652 extern void *
653 _mesa_calloc( size_t bytes );
654
655 extern void
656 _mesa_free( void *ptr );
657
658 extern void *
659 _mesa_align_malloc( size_t bytes, unsigned long alignment );
660
661 extern void *
662 _mesa_align_calloc( size_t bytes, unsigned long alignment );
663
664 extern void
665 _mesa_align_free( void *ptr );
666
667 extern void *
668 _mesa_exec_malloc( GLuint size );
669
670 extern void
671 _mesa_exec_free( void *addr );
672
673 extern void *
674 _mesa_realloc( void *oldBuffer, size_t oldSize, size_t newSize );
675
676 extern void *
677 _mesa_memcpy( void *dest, const void *src, size_t n );
678
679 extern void
680 _mesa_memset( void *dst, int val, size_t n );
681
682 extern void
683 _mesa_memset16( unsigned short *dst, unsigned short val, size_t n );
684
685 extern void
686 _mesa_bzero( void *dst, size_t n );
687
688
689 extern double
690 _mesa_sin(double a);
691
692 extern double
693 _mesa_cos(double a);
694
695 extern double
696 _mesa_sqrtd(double x);
697
698 extern float
699 _mesa_sqrtf(float x);
700
701 extern float
702 _mesa_inv_sqrtf(float x);
703
704 extern double
705 _mesa_pow(double x, double y);
706
707 extern float
708 _mesa_log2(float x);
709
710 extern unsigned int
711 _mesa_bitcount(unsigned int n);
712
713 extern GLhalfARB
714 _mesa_float_to_half(float f);
715
716 extern float
717 _mesa_half_to_float(GLhalfARB h);
718
719
720 extern char *
721 _mesa_getenv( const char *var );
722
723 extern char *
724 _mesa_strstr( const char *haystack, const char *needle );
725
726 extern char *
727 _mesa_strncat( char *dest, const char *src, size_t n );
728
729 extern char *
730 _mesa_strcpy( char *dest, const char *src );
731
732 extern char *
733 _mesa_strncpy( char *dest, const char *src, size_t n );
734
735 extern size_t
736 _mesa_strlen( const char *s );
737
738 extern int
739 _mesa_strcmp( const char *s1, const char *s2 );
740
741 extern int
742 _mesa_strncmp( const char *s1, const char *s2, size_t n );
743
744 extern char *
745 _mesa_strdup( const char *s );
746
747 extern int
748 _mesa_atoi( const char *s );
749
750 extern double
751 _mesa_strtod( const char *s, char **end );
752
753 extern int
754 _mesa_sprintf( char *str, const char *fmt, ... );
755
756 extern void
757 _mesa_printf( const char *fmtString, ... );
758
759
760 extern void
761 _mesa_warning( __GLcontext *gc, const char *fmtString, ... );
762
763 extern void
764 _mesa_problem( const __GLcontext *ctx, const char *fmtString, ... );
765
766 extern void
767 _mesa_error( __GLcontext *ctx, GLenum error, const char *fmtString, ... );
768
769 extern void
770 _mesa_debug( const __GLcontext *ctx, const char *fmtString, ... );
771
772
773 extern void
774 _mesa_init_default_imports( __GLimports *imports, void *driverCtx );
775
776
777 #ifdef __cplusplus
778 }
779 #endif
780
781
782 #endif /* IMPORTS_H */