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