replace color table FloatTable boolean with Type enum
[mesa.git] / src / mesa / main / imports.h
1 /**
2 * \file imports.h
3 * Standard C library function wrappers.
4 *
5 * This file provides wrappers for all the standard C library functions
6 * like malloc(), free(), printf(), getenv(), etc.
7 */
8
9 /*
10 * Mesa 3-D graphics library
11 * Version: 6.0
12 *
13 * Copyright (C) 1999-2004 Brian Paul All Rights Reserved.
14 *
15 * Permission is hereby granted, free of charge, to any person obtaining a
16 * copy of this software and associated documentation files (the "Software"),
17 * to deal in the Software without restriction, including without limitation
18 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
19 * and/or sell copies of the Software, and to permit persons to whom the
20 * Software is furnished to do so, subject to the following conditions:
21 *
22 * The above copyright notice and this permission notice shall be included
23 * in all copies or substantial portions of the Software.
24 *
25 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
26 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
27 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
28 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
29 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
30 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 */
32
33
34 #ifndef IMPORTS_H
35 #define IMPORTS_H
36
37
38 /* XXX some of the stuff in glheader.h should be moved into this file.
39 */
40 #include "glheader.h"
41
42
43 #ifdef __cplusplus
44 extern "C" {
45 #endif
46
47
48 /**********************************************************************/
49 /** \name General macros */
50 /*@{*/
51
52 #ifndef NULL
53 #define NULL 0
54 #endif
55
56 /*@}*/
57
58
59 /**********************************************************************/
60 /** Memory macros */
61 /*@{*/
62
63 /** Allocate \p BYTES bytes */
64 #define MALLOC(BYTES) _mesa_malloc(BYTES)
65 /** Allocate and zero \p BYTES bytes */
66 #define CALLOC(BYTES) _mesa_calloc(BYTES)
67 /** Allocate a structure of type \p T */
68 #define MALLOC_STRUCT(T) (struct T *) _mesa_malloc(sizeof(struct T))
69 /** Allocate and zero a structure of type \p T */
70 #define CALLOC_STRUCT(T) (struct T *) _mesa_calloc(sizeof(struct T))
71 /** Free memory */
72 #define FREE(PTR) _mesa_free(PTR)
73
74 /** Allocate \p BYTES aligned at \p N bytes */
75 #define ALIGN_MALLOC(BYTES, N) _mesa_align_malloc(BYTES, N)
76 /** Allocate and zero \p BYTES bytes aligned at \p N bytes */
77 #define ALIGN_CALLOC(BYTES, N) _mesa_align_calloc(BYTES, N)
78 /** Allocate a structure of type \p T aligned at \p N bytes */
79 #define ALIGN_MALLOC_STRUCT(T, N) (struct T *) _mesa_align_malloc(sizeof(struct T), N)
80 /** Allocate and zero a structure of type \p T aligned at \p N bytes */
81 #define ALIGN_CALLOC_STRUCT(T, N) (struct T *) _mesa_align_calloc(sizeof(struct T), N)
82 /** Free aligned memory */
83 #define ALIGN_FREE(PTR) _mesa_align_free(PTR)
84
85 /** Copy \p BYTES bytes from \p SRC into \p DST */
86 #define MEMCPY( DST, SRC, BYTES) _mesa_memcpy(DST, SRC, BYTES)
87 /** Set \p N bytes in \p DST to \p VAL */
88 #define MEMSET( DST, VAL, N ) _mesa_memset(DST, VAL, N)
89
90 #define MEMSET16( DST, VAL, N ) _mesa_memset16( (DST), (VAL), (size_t) (N) )
91
92 /*@}*/
93
94
95 /*
96 * For GL_ARB_vertex_buffer_object we need to treat vertex array pointers
97 * as offsets into buffer stores. Since the vertex array pointer and
98 * buffer store pointer are both pointers and we need to add them, we use
99 * this macro.
100 * Both pointers/offsets are expressed in bytes.
101 */
102 #define ADD_POINTERS(A, B) ( (A) + (unsigned long) (B) )
103
104
105 /**********************************************************************/
106 /** \name [Pseudo] static array declaration.
107 *
108 * MACs and BeOS don't support static larger than 32kb, so ...
109 */
110 /*@{*/
111
112 /**
113 * \def DEFARRAY
114 * Define a [static] unidimensional array
115 */
116
117 /**
118 * \def DEFMARRAY
119 * Define a [static] bi-dimensional array
120 */
121
122 /**
123 * \def DEFMNARRAY
124 * Define a [static] tri-dimensional array
125 */
126
127 /**
128 * \def CHECKARRAY
129 * Verifies a [static] array was properly allocated.
130 */
131
132 /**
133 * \def UNDEFARRAY
134 * Undefine (free) a [static] array.
135 */
136
137 #if defined(macintosh) && !defined(__MRC__)
138 /*extern char *AGLAlloc(int size);*/
139 /*extern void AGLFree(char* ptr);*/
140 # define DEFARRAY(TYPE,NAME,SIZE) TYPE *NAME = (TYPE*)_mesa_alloc(sizeof(TYPE)*(SIZE))
141 # define DEFMARRAY(TYPE,NAME,SIZE1,SIZE2) TYPE (*NAME)[SIZE2] = (TYPE(*)[SIZE2])_mesa_alloc(sizeof(TYPE)*(SIZE1)*(SIZE2))
142 # define DEFMNARRAY(TYPE,NAME,SIZE1,SIZE2,SIZE3) TYPE (*NAME)[SIZE2][SIZE3] = (TYPE(*)[SIZE2][SIZE3])_mesa_alloc(sizeof(TYPE)*(SIZE1)*(SIZE2)*(SIZE3))
143 # define CHECKARRAY(NAME,CMD) do {if (!(NAME)) {CMD;}} while (0)
144 # define UNDEFARRAY(NAME) do {if ((NAME)) {_mesa_free((char*)NAME);} }while (0)
145 #elif defined(__BEOS__)
146 # define DEFARRAY(TYPE,NAME,SIZE) TYPE *NAME = (TYPE*)_mesa_malloc(sizeof(TYPE)*(SIZE))
147 # define DEFMARRAY(TYPE,NAME,SIZE1,SIZE2) TYPE (*NAME)[SIZE2] = (TYPE(*)[SIZE2])_mesa_malloc(sizeof(TYPE)*(SIZE1)*(SIZE2))
148 # define DEFMNARRAY(TYPE,NAME,SIZE1,SIZE2,SIZE3) TYPE (*NAME)[SIZE2][SIZE3] = (TYPE(*)[SIZE2][SIZE3])_mesa_malloc(sizeof(TYPE)*(SIZE1)*(SIZE2)*(SIZE3))
149 # define CHECKARRAY(NAME,CMD) do {if (!(NAME)) {CMD;}} while (0)
150 # define UNDEFARRAY(NAME) do {if ((NAME)) {_mesa_free((char*)NAME);} }while (0)
151 #else
152 # define DEFARRAY(TYPE,NAME,SIZE) TYPE NAME[SIZE]
153 # define DEFMARRAY(TYPE,NAME,SIZE1,SIZE2) TYPE NAME[SIZE1][SIZE2]
154 # define DEFMNARRAY(TYPE,NAME,SIZE1,SIZE2,SIZE3) TYPE NAME[SIZE1][SIZE2][SIZE3]
155 # define CHECKARRAY(NAME,CMD) do {} while(0)
156 # define UNDEFARRAY(NAME)
157 #endif
158
159 /*@}*/
160
161
162 /**********************************************************************/
163 /** \name External pixel buffer allocation.
164 *
165 * If you want Mesa's depth/stencil/accum/etc buffers to be allocated with a
166 * specialized allocator you can define MESA_EXTERNAL_BUFFERALLOC and implement
167 * _ext_mesa_alloc_pixelbuffer() _ext_mesa_free_pixelbuffer() in your
168 * application.
169 *
170 * \author
171 * Contributed by Gerk Huisma (gerk@five-d.demon.nl).
172 */
173 /*@{*/
174
175 /**
176 * \def MESA_PBUFFER_ALLOC
177 * Allocate a pixel buffer.
178 */
179
180 /**
181 * \def MESA_PBUFFER_FREE
182 * Free a pixel buffer.
183 */
184
185 #ifdef MESA_EXTERNAL_BUFFERALLOC
186 extern void *_ext_mesa_alloc_pixelbuffer( unsigned int size );
187 extern void _ext_mesa_free_pixelbuffer( void *pb );
188
189 #define MESA_PBUFFER_ALLOC(BYTES) (void *) _ext_mesa_alloc_pixelbuffer(BYTES)
190 #define MESA_PBUFFER_FREE(PTR) _ext_mesa_free_pixelbuffer(PTR)
191 #else
192 /* Default buffer allocation uses the aligned allocation routines: */
193 #define MESA_PBUFFER_ALLOC(BYTES) (void *) _mesa_align_malloc(BYTES, 512)
194 #define MESA_PBUFFER_FREE(PTR) _mesa_align_free(PTR)
195 #endif
196
197 /*@}*/
198
199
200
201 /**********************************************************************
202 * Math macros
203 */
204
205 #define MAX_GLUSHORT 0xffff
206 #define MAX_GLUINT 0xffffffff
207
208 #ifndef M_PI
209 #define M_PI (3.1415926536)
210 #endif
211
212 /* XXX this is a bit of a hack needed for compilation within XFree86 */
213 #ifndef FLT_MIN
214 #define FLT_MIN (1.0e-37)
215 #endif
216
217 /* Degrees to radians conversion: */
218 #define DEG2RAD (M_PI/180.0)
219
220
221 /***
222 *** USE_IEEE: Determine if we're using IEEE floating point
223 ***/
224 #if defined(__i386__) || defined(__386__) || defined(__sparc__) || \
225 defined(__s390x__) || defined(__powerpc__) || \
226 ( defined(__alpha__) && ( defined(__IEEE_FLOAT) || !defined(VMS) ) )
227 #define USE_IEEE
228 #define IEEE_ONE 0x3f800000
229 #endif
230
231
232 /***
233 *** SQRTF: single-precision square root
234 ***/
235 #if 0 /* _mesa_sqrtf() not accurate enough - temporarily disabled */
236 # define SQRTF(X) _mesa_sqrtf(X)
237 #elif defined(XFree86LOADER) && defined(IN_MODULE)
238 # define SQRTF(X) (float) xf86sqrt((float) (X))
239 #else
240 # define SQRTF(X) (float) sqrt((float) (X))
241 #endif
242
243
244 /***
245 *** INV_SQRTF: single-precision inverse square root
246 ***/
247 #if 0
248 #define INV_SQRTF(X) _mesa_inv_sqrt(X)
249 #else
250 #define INV_SQRTF(X) (1.0F / SQRTF(X)) /* this is faster on a P4 */
251 #endif
252
253
254 /***
255 *** LOG2: Log base 2 of float
256 ***/
257 #ifdef USE_IEEE
258 #if 0
259 /* This is pretty fast, but not accurate enough (only 2 fractional bits).
260 * Based on code from http://www.stereopsis.com/log2.html
261 */
262 static INLINE GLfloat LOG2(GLfloat x)
263 {
264 const GLfloat y = x * x * x * x;
265 const GLuint ix = *((GLuint *) &y);
266 const GLuint exp = (ix >> 23) & 0xFF;
267 const GLint log2 = ((GLint) exp) - 127;
268 return (GLfloat) log2 * (1.0 / 4.0); /* 4, because of x^4 above */
269 }
270 #endif
271 /* Pretty fast, and accurate.
272 * Based on code from http://www.flipcode.com/totd/
273 */
274 static INLINE GLfloat LOG2(GLfloat val)
275 {
276 fi_type num;
277 GLint log_2;
278 num.f = val;
279 log_2 = ((num.i >> 23) & 255) - 128;
280 num.i &= ~(255 << 23);
281 num.i += 127 << 23;
282 num.f = ((-1.0f/3) * num.f + 2) * num.f - 2.0f/3;
283 return num.f + log_2;
284 }
285 #elif defined(XFree86LOADER) && defined(IN_MODULE)
286 #define LOG2(x) ((GLfloat) (xf86log(x) * 1.442695))
287 #else
288 /*
289 * NOTE: log_base_2(x) = log(x) / log(2)
290 * NOTE: 1.442695 = 1/log(2).
291 */
292 #define LOG2(x) ((GLfloat) (log(x) * 1.442695F))
293 #endif
294
295
296 /***
297 *** IS_INF_OR_NAN: test if float is infinite or NaN
298 ***/
299 #ifdef USE_IEEE
300 static INLINE int IS_INF_OR_NAN( float x )
301 {
302 fi_type tmp;
303 tmp.f = x;
304 return !(int)((unsigned int)((tmp.i & 0x7fffffff)-0x7f800000) >> 31);
305 }
306 #elif defined(isfinite)
307 #define IS_INF_OR_NAN(x) (!isfinite(x))
308 #elif defined(finite)
309 #define IS_INF_OR_NAN(x) (!finite(x))
310 #elif __VMS
311 #define IS_INF_OR_NAN(x) (!finite(x))
312 #elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
313 #define IS_INF_OR_NAN(x) (!isfinite(x))
314 #else
315 #define IS_INF_OR_NAN(x) (!finite(x))
316 #endif
317
318
319 /***
320 *** IS_NEGATIVE: test if float is negative
321 ***/
322 #if defined(USE_IEEE)
323 #define GET_FLOAT_BITS(x) ((fi_type *) &(x))->i
324 #define IS_NEGATIVE(x) (GET_FLOAT_BITS(x) & (1<<31))
325 #else
326 #define IS_NEGATIVE(x) (x < 0.0F)
327 #endif
328
329
330 /***
331 *** DIFFERENT_SIGNS: test if two floats have opposite signs
332 ***/
333 #if defined(USE_IEEE)
334 #define DIFFERENT_SIGNS(x,y) ((GET_FLOAT_BITS(x) ^ GET_FLOAT_BITS(y)) & (1<<31))
335 #else
336 /* Could just use (x*y<0) except for the flatshading requirements.
337 * Maybe there's a better way?
338 */
339 #define DIFFERENT_SIGNS(x,y) ((x) * (y) <= 0.0F && (x) - (y) != 0.0F)
340 #endif
341
342
343 /***
344 *** CEILF: ceiling of float
345 *** FLOORF: floor of float
346 *** FABSF: absolute value of float
347 ***/
348 #if defined(XFree86LOADER) && defined(IN_MODULE)
349 #define CEILF(x) ((GLfloat) xf86ceil(x))
350 #define FLOORF(x) ((GLfloat) xf86floor(x))
351 #define FABSF(x) ((GLfloat) xf86fabs(x))
352 #elif defined(__gnu_linux__)
353 /* C99 functions */
354 #define CEILF(x) ceilf(x)
355 #define FLOORF(x) floorf(x)
356 #define FABSF(x) fabsf(x)
357 #else
358 #define CEILF(x) ((GLfloat) ceil(x))
359 #define FLOORF(x) ((GLfloat) floor(x))
360 #define FABSF(x) ((GLfloat) fabs(x))
361 #endif
362
363
364 /***
365 *** IROUND: return (as an integer) float rounded to nearest integer
366 ***/
367 #if defined(USE_SPARC_ASM) && defined(__GNUC__) && defined(__sparc__)
368 static INLINE int iround(float f)
369 {
370 int r;
371 __asm__ ("fstoi %1, %0" : "=f" (r) : "f" (f));
372 return r;
373 }
374 #define IROUND(x) iround(x)
375 #elif defined(USE_X86_ASM) && defined(__GNUC__) && defined(__i386__)
376 static INLINE int iround(float f)
377 {
378 int r;
379 __asm__ ("fistpl %0" : "=m" (r) : "t" (f) : "st");
380 return r;
381 }
382 #define IROUND(x) iround(x)
383 #elif defined(USE_X86_ASM) && defined(__MSC__) && defined(__WIN32__)
384 static INLINE int iround(float f)
385 {
386 int r;
387 _asm {
388 fld f
389 fistp r
390 }
391 return r;
392 }
393 #define IROUND(x) iround(x)
394 #elif defined(__WATCOMC__) && defined(__386__)
395 long iround(float f);
396 #pragma aux iround = \
397 "push eax" \
398 "fistp dword ptr [esp]" \
399 "pop eax" \
400 parm [8087] \
401 value [eax] \
402 modify exact [eax];
403 #define IROUND(x) iround(x)
404 #else
405 #define IROUND(f) ((int) (((f) >= 0.0F) ? ((f) + 0.5F) : ((f) - 0.5F)))
406 #endif
407
408
409 /***
410 *** IROUND_POS: return (as an integer) positive float rounded to nearest int
411 ***/
412 #ifdef DEBUG
413 #define IROUND_POS(f) (assert((f) >= 0.0F), IROUND(f))
414 #else
415 #define IROUND_POS(f) (IROUND(f))
416 #endif
417
418
419 /***
420 *** IFLOOR: return (as an integer) floor of float
421 ***/
422 #if defined(USE_X86_ASM) && defined(__GNUC__) && defined(__i386__)
423 /*
424 * IEEE floor for computers that round to nearest or even.
425 * 'f' must be between -4194304 and 4194303.
426 * This floor operation is done by "(iround(f + .5) + iround(f - .5)) >> 1",
427 * but uses some IEEE specific tricks for better speed.
428 * Contributed by Josh Vanderhoof
429 */
430 static INLINE int ifloor(float f)
431 {
432 int ai, bi;
433 double af, bf;
434 af = (3 << 22) + 0.5 + (double)f;
435 bf = (3 << 22) + 0.5 - (double)f;
436 /* GCC generates an extra fstp/fld without this. */
437 __asm__ ("fstps %0" : "=m" (ai) : "t" (af) : "st");
438 __asm__ ("fstps %0" : "=m" (bi) : "t" (bf) : "st");
439 return (ai - bi) >> 1;
440 }
441 #define IFLOOR(x) ifloor(x)
442 #elif defined(USE_IEEE)
443 static INLINE int ifloor(float f)
444 {
445 int ai, bi;
446 double af, bf;
447 fi_type u;
448
449 af = (3 << 22) + 0.5 + (double)f;
450 bf = (3 << 22) + 0.5 - (double)f;
451 u.f = (float) af; ai = u.i;
452 u.f = (float) bf; bi = u.i;
453 return (ai - bi) >> 1;
454 }
455 #define IFLOOR(x) ifloor(x)
456 #else
457 static INLINE int ifloor(float f)
458 {
459 int i = IROUND(f);
460 return (i > f) ? i - 1 : i;
461 }
462 #define IFLOOR(x) ifloor(x)
463 #endif
464
465
466 /***
467 *** ICEIL: return (as an integer) ceiling of float
468 ***/
469 #if defined(USE_X86_ASM) && defined(__GNUC__) && defined(__i386__)
470 /*
471 * IEEE ceil for computers that round to nearest or even.
472 * 'f' must be between -4194304 and 4194303.
473 * This ceil operation is done by "(iround(f + .5) + iround(f - .5) + 1) >> 1",
474 * but uses some IEEE specific tricks for better speed.
475 * Contributed by Josh Vanderhoof
476 */
477 static INLINE int iceil(float f)
478 {
479 int ai, bi;
480 double af, bf;
481 af = (3 << 22) + 0.5 + (double)f;
482 bf = (3 << 22) + 0.5 - (double)f;
483 /* GCC generates an extra fstp/fld without this. */
484 __asm__ ("fstps %0" : "=m" (ai) : "t" (af) : "st");
485 __asm__ ("fstps %0" : "=m" (bi) : "t" (bf) : "st");
486 return (ai - bi + 1) >> 1;
487 }
488 #define ICEIL(x) iceil(x)
489 #elif defined(USE_IEEE)
490 static INLINE int iceil(float f)
491 {
492 int ai, bi;
493 double af, bf;
494 fi_type u;
495 af = (3 << 22) + 0.5 + (double)f;
496 bf = (3 << 22) + 0.5 - (double)f;
497 u.f = (float) af; ai = u.i;
498 u.f = (float) bf; bi = u.i;
499 return (ai - bi + 1) >> 1;
500 }
501 #define ICEIL(x) iceil(x)
502 #else
503 static INLINE int iceil(float f)
504 {
505 int i = IROUND(f);
506 return (i < f) ? i + 1 : i;
507 }
508 #define ICEIL(x) iceil(x)
509 #endif
510
511
512 /***
513 *** UNCLAMPED_FLOAT_TO_UBYTE: clamp float to [0,1] and map to ubyte in [0,255]
514 *** CLAMPED_FLOAT_TO_UBYTE: map float known to be in [0,1] to ubyte in [0,255]
515 ***/
516 #if defined(USE_IEEE) && !defined(DEBUG)
517 #define IEEE_0996 0x3f7f0000 /* 0.996 or so */
518 /* This function/macro is sensitive to precision. Test very carefully
519 * if you change it!
520 */
521 #define UNCLAMPED_FLOAT_TO_UBYTE(UB, F) \
522 do { \
523 fi_type __tmp; \
524 __tmp.f = (F); \
525 if (__tmp.i < 0) \
526 UB = (GLubyte) 0; \
527 else if (__tmp.i >= IEEE_0996) \
528 UB = (GLubyte) 255; \
529 else { \
530 __tmp.f = __tmp.f * (255.0F/256.0F) + 32768.0F; \
531 UB = (GLubyte) __tmp.i; \
532 } \
533 } while (0)
534 #define CLAMPED_FLOAT_TO_UBYTE(UB, F) \
535 do { \
536 fi_type __tmp; \
537 __tmp.f = (F) * (255.0F/256.0F) + 32768.0F; \
538 UB = (GLubyte) __tmp.i; \
539 } while (0)
540 #else
541 #define UNCLAMPED_FLOAT_TO_UBYTE(ub, f) \
542 ub = ((GLubyte) IROUND(CLAMP((f), 0.0F, 1.0F) * 255.0F))
543 #define CLAMPED_FLOAT_TO_UBYTE(ub, f) \
544 ub = ((GLubyte) IROUND((f) * 255.0F))
545 #endif
546
547
548 /***
549 *** COPY_FLOAT: copy a float from src to dest, avoid slow FP regs if possible
550 ***/
551 #if defined(USE_IEEE) && !defined(DEBUG)
552 #define COPY_FLOAT( dst, src ) \
553 ((fi_type *) &(dst))->i = ((fi_type *) &(src))->i
554 #else
555 #define COPY_FLOAT( dst, src ) (dst) = (src)
556 #endif
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_realloc( void *oldBuffer, size_t oldSize, size_t newSize );
669
670 extern void *
671 _mesa_memcpy( void *dest, const void *src, size_t n );
672
673 extern void
674 _mesa_memset( void *dst, int val, size_t n );
675
676 extern void
677 _mesa_memset16( unsigned short *dst, unsigned short val, size_t n );
678
679 extern void
680 _mesa_bzero( void *dst, size_t n );
681
682
683 extern double
684 _mesa_sin(double a);
685
686 extern double
687 _mesa_cos(double a);
688
689 extern double
690 _mesa_sqrtd(double x);
691
692 extern float
693 _mesa_sqrtf(float x);
694
695 extern float
696 _mesa_inv_sqrtf(float x);
697
698 extern double
699 _mesa_pow(double x, double y);
700
701 extern float
702 _mesa_log2(float x);
703
704 extern unsigned int
705 _mesa_bitcount(unsigned int n);
706
707 extern GLhalfNV
708 _mesa_float_to_half(float f);
709
710 extern float
711 _mesa_half_to_float(GLhalfNV h);
712
713
714 extern char *
715 _mesa_getenv( const char *var );
716
717 extern char *
718 _mesa_strstr( const char *haystack, const char *needle );
719
720 extern char *
721 _mesa_strncat( char *dest, const char *src, size_t n );
722
723 extern char *
724 _mesa_strcpy( char *dest, const char *src );
725
726 extern char *
727 _mesa_strncpy( char *dest, const char *src, size_t n );
728
729 extern size_t
730 _mesa_strlen( const char *s );
731
732 extern int
733 _mesa_strcmp( const char *s1, const char *s2 );
734
735 extern int
736 _mesa_strncmp( const char *s1, const char *s2, size_t n );
737
738 extern char *
739 _mesa_strdup( const char *s );
740
741 extern int
742 _mesa_atoi( const char *s );
743
744 extern double
745 _mesa_strtod( const char *s, char **end );
746
747 extern int
748 _mesa_sprintf( char *str, const char *fmt, ... );
749
750 extern void
751 _mesa_printf( const char *fmtString, ... );
752
753
754 extern void
755 _mesa_warning( __GLcontext *gc, const char *fmtString, ... );
756
757 extern void
758 _mesa_problem( const __GLcontext *ctx, const char *fmtString, ... );
759
760 extern void
761 _mesa_error( __GLcontext *ctx, GLenum error, const char *fmtString, ... );
762
763 extern void
764 _mesa_debug( const __GLcontext *ctx, const char *fmtString, ... );
765
766
767 extern void
768 _mesa_init_default_imports( __GLimports *imports, void *driverCtx );
769
770
771 #ifdef __cplusplus
772 }
773 #endif
774
775
776 #endif /* IMPORTS_H */