remove ^M chars, disable shading language extensions
[mesa.git] / src / mesa / 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 /*@}*/
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(__alpha__) && (defined(__IEEE_FLOAT) || !defined(VMS)))
209 #define USE_IEEE
210 #define IEEE_ONE 0x3f800000
211 #endif
212
213
214 /***
215 *** SQRTF: single-precision square root
216 ***/
217 #if 0 /* _mesa_sqrtf() not accurate enough - temporarily disabled */
218 # define SQRTF(X) _mesa_sqrtf(X)
219 #elif defined(XFree86LOADER) && defined(IN_MODULE)
220 # define SQRTF(X) (float) xf86sqrt((float) (X))
221 #else
222 # define SQRTF(X) (float) sqrt((float) (X))
223 #endif
224
225
226 /***
227 *** INV_SQRTF: single-precision inverse square root
228 ***/
229 #if 0
230 #define INV_SQRTF(X) _mesa_inv_sqrt(X)
231 #else
232 #define INV_SQRTF(X) (1.0F / SQRTF(X)) /* this is faster on a P4 */
233 #endif
234
235
236 /***
237 *** LOG2: Log base 2 of float
238 ***/
239 #ifdef USE_IEEE
240 #if 0
241 /* This is pretty fast, but not accurate enough (only 2 fractional bits).
242 * Based on code from http://www.stereopsis.com/log2.html
243 */
244 static INLINE GLfloat LOG2(GLfloat x)
245 {
246 const GLfloat y = x * x * x * x;
247 const GLuint ix = *((GLuint *) &y);
248 const GLuint exp = (ix >> 23) & 0xFF;
249 const GLint log2 = ((GLint) exp) - 127;
250 return (GLfloat) log2 * (1.0 / 4.0); /* 4, because of x^4 above */
251 }
252 #endif
253 /* Pretty fast, and accurate.
254 * Based on code from http://www.flipcode.com/totd/
255 */
256 static INLINE GLfloat LOG2(GLfloat val)
257 {
258 fi_type num;
259 GLint log_2;
260 num.f = val;
261 log_2 = ((num.i >> 23) & 255) - 128;
262 num.i &= ~(255 << 23);
263 num.i += 127 << 23;
264 num.f = ((-1.0f/3) * num.f + 2) * num.f - 2.0f/3;
265 return num.f + log_2;
266 }
267 #elif defined(XFree86LOADER) && defined(IN_MODULE)
268 #define LOG2(x) ((GLfloat) (xf86log(x) * 1.442695))
269 #else
270 /*
271 * NOTE: log_base_2(x) = log(x) / log(2)
272 * NOTE: 1.442695 = 1/log(2).
273 */
274 #define LOG2(x) ((GLfloat) (log(x) * 1.442695F))
275 #endif
276
277
278 /***
279 *** IS_INF_OR_NAN: test if float is infinite or NaN
280 ***/
281 #ifdef USE_IEEE
282 static INLINE int IS_INF_OR_NAN( float x )
283 {
284 fi_type tmp;
285 tmp.f = x;
286 return !(int)((unsigned int)((tmp.i & 0x7fffffff)-0x7f800000) >> 31);
287 }
288 #elif defined(isfinite)
289 #define IS_INF_OR_NAN(x) (!isfinite(x))
290 #elif defined(finite)
291 #define IS_INF_OR_NAN(x) (!finite(x))
292 #elif defined(__VMS)
293 #define IS_INF_OR_NAN(x) (!finite(x))
294 #elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
295 #define IS_INF_OR_NAN(x) (!isfinite(x))
296 #else
297 #define IS_INF_OR_NAN(x) (!finite(x))
298 #endif
299
300
301 /***
302 *** IS_NEGATIVE: test if float is negative
303 ***/
304 #if defined(USE_IEEE)
305 static INLINE int GET_FLOAT_BITS( float x )
306 {
307 fi_type fi;
308 fi.f = x;
309 return fi.i;
310 }
311 #define IS_NEGATIVE(x) (GET_FLOAT_BITS(x) < 0)
312 #else
313 #define IS_NEGATIVE(x) (x < 0.0F)
314 #endif
315
316
317 /***
318 *** DIFFERENT_SIGNS: test if two floats have opposite signs
319 ***/
320 #if defined(USE_IEEE)
321 #define DIFFERENT_SIGNS(x,y) ((GET_FLOAT_BITS(x) ^ GET_FLOAT_BITS(y)) & (1<<31))
322 #else
323 /* Could just use (x*y<0) except for the flatshading requirements.
324 * Maybe there's a better way?
325 */
326 #define DIFFERENT_SIGNS(x,y) ((x) * (y) <= 0.0F && (x) - (y) != 0.0F)
327 #endif
328
329
330 /***
331 *** CEILF: ceiling of float
332 *** FLOORF: floor of float
333 *** FABSF: absolute value of float
334 ***/
335 #if defined(XFree86LOADER) && defined(IN_MODULE)
336 #define CEILF(x) ((GLfloat) xf86ceil(x))
337 #define FLOORF(x) ((GLfloat) xf86floor(x))
338 #define FABSF(x) ((GLfloat) xf86fabs(x))
339 #define LDEXPF(x,y) ((GLfloat) xf86ldexp(x,y))
340 #elif defined(__gnu_linux__)
341 /* C99 functions */
342 #define CEILF(x) ceilf(x)
343 #define FLOORF(x) floorf(x)
344 #define FABSF(x) fabsf(x)
345 #define LDEXPF(x,y) ldexpf(x,y)
346 #else
347 #define CEILF(x) ((GLfloat) ceil(x))
348 #define FLOORF(x) ((GLfloat) floor(x))
349 #define FABSF(x) ((GLfloat) fabs(x))
350 #define LDEXPF(x,y) ((GLfloat) ldexp(x,y))
351 #endif
352
353
354 /***
355 *** IROUND: return (as an integer) float rounded to nearest integer
356 ***/
357 #if defined(USE_SPARC_ASM) && defined(__GNUC__) && defined(__sparc__)
358 static INLINE int iround(float f)
359 {
360 int r;
361 __asm__ ("fstoi %1, %0" : "=f" (r) : "f" (f));
362 return r;
363 }
364 #define IROUND(x) iround(x)
365 #elif defined(USE_X86_ASM) && defined(__GNUC__) && defined(__i386__) && \
366 (!defined(__BEOS__) || (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95)))
367 static INLINE int iround(float f)
368 {
369 int r;
370 __asm__ ("fistpl %0" : "=m" (r) : "t" (f) : "st");
371 return r;
372 }
373 #define IROUND(x) iround(x)
374 #elif defined(USE_X86_ASM) && defined(__MSC__) && defined(__WIN32__)
375 static INLINE int iround(float f)
376 {
377 int r;
378 _asm {
379 fld f
380 fistp r
381 }
382 return r;
383 }
384 #define IROUND(x) iround(x)
385 #elif defined(__WATCOMC__) && defined(__386__)
386 long iround(float f);
387 #pragma aux iround = \
388 "push eax" \
389 "fistp dword ptr [esp]" \
390 "pop eax" \
391 parm [8087] \
392 value [eax] \
393 modify exact [eax];
394 #define IROUND(x) iround(x)
395 #else
396 #define IROUND(f) ((int) (((f) >= 0.0F) ? ((f) + 0.5F) : ((f) - 0.5F)))
397 #endif
398
399
400 /***
401 *** IROUND_POS: return (as an integer) positive float rounded to nearest int
402 ***/
403 #ifdef DEBUG
404 #define IROUND_POS(f) (assert((f) >= 0.0F), IROUND(f))
405 #else
406 #define IROUND_POS(f) (IROUND(f))
407 #endif
408
409
410 /***
411 *** IFLOOR: return (as an integer) floor of float
412 ***/
413 #if defined(USE_X86_ASM) && defined(__GNUC__) && defined(__i386__)
414 /*
415 * IEEE floor for computers that round to nearest or even.
416 * 'f' must be between -4194304 and 4194303.
417 * This floor operation is done by "(iround(f + .5) + iround(f - .5)) >> 1",
418 * but uses some IEEE specific tricks for better speed.
419 * Contributed by Josh Vanderhoof
420 */
421 static INLINE int ifloor(float f)
422 {
423 int ai, bi;
424 double af, bf;
425 af = (3 << 22) + 0.5 + (double)f;
426 bf = (3 << 22) + 0.5 - (double)f;
427 /* GCC generates an extra fstp/fld without this. */
428 __asm__ ("fstps %0" : "=m" (ai) : "t" (af) : "st");
429 __asm__ ("fstps %0" : "=m" (bi) : "t" (bf) : "st");
430 return (ai - bi) >> 1;
431 }
432 #define IFLOOR(x) ifloor(x)
433 #elif defined(USE_IEEE)
434 static INLINE int ifloor(float f)
435 {
436 int ai, bi;
437 double af, bf;
438 fi_type u;
439
440 af = (3 << 22) + 0.5 + (double)f;
441 bf = (3 << 22) + 0.5 - (double)f;
442 u.f = (float) af; ai = u.i;
443 u.f = (float) bf; bi = u.i;
444 return (ai - bi) >> 1;
445 }
446 #define IFLOOR(x) ifloor(x)
447 #else
448 static INLINE int ifloor(float f)
449 {
450 int i = IROUND(f);
451 return (i > f) ? i - 1 : i;
452 }
453 #define IFLOOR(x) ifloor(x)
454 #endif
455
456
457 /***
458 *** ICEIL: return (as an integer) ceiling of float
459 ***/
460 #if defined(USE_X86_ASM) && defined(__GNUC__) && defined(__i386__)
461 /*
462 * IEEE ceil for computers that round to nearest or even.
463 * 'f' must be between -4194304 and 4194303.
464 * This ceil operation is done by "(iround(f + .5) + iround(f - .5) + 1) >> 1",
465 * but uses some IEEE specific tricks for better speed.
466 * Contributed by Josh Vanderhoof
467 */
468 static INLINE int iceil(float f)
469 {
470 int ai, bi;
471 double af, bf;
472 af = (3 << 22) + 0.5 + (double)f;
473 bf = (3 << 22) + 0.5 - (double)f;
474 /* GCC generates an extra fstp/fld without this. */
475 __asm__ ("fstps %0" : "=m" (ai) : "t" (af) : "st");
476 __asm__ ("fstps %0" : "=m" (bi) : "t" (bf) : "st");
477 return (ai - bi + 1) >> 1;
478 }
479 #define ICEIL(x) iceil(x)
480 #elif defined(USE_IEEE)
481 static INLINE int iceil(float f)
482 {
483 int ai, bi;
484 double af, bf;
485 fi_type u;
486 af = (3 << 22) + 0.5 + (double)f;
487 bf = (3 << 22) + 0.5 - (double)f;
488 u.f = (float) af; ai = u.i;
489 u.f = (float) bf; bi = u.i;
490 return (ai - bi + 1) >> 1;
491 }
492 #define ICEIL(x) iceil(x)
493 #else
494 static INLINE int iceil(float f)
495 {
496 int i = IROUND(f);
497 return (i < f) ? i + 1 : i;
498 }
499 #define ICEIL(x) iceil(x)
500 #endif
501
502
503 /***
504 *** UNCLAMPED_FLOAT_TO_UBYTE: clamp float to [0,1] and map to ubyte in [0,255]
505 *** CLAMPED_FLOAT_TO_UBYTE: map float known to be in [0,1] to ubyte in [0,255]
506 ***/
507 #if defined(USE_IEEE) && !defined(DEBUG)
508 #define IEEE_0996 0x3f7f0000 /* 0.996 or so */
509 /* This function/macro is sensitive to precision. Test very carefully
510 * if you change it!
511 */
512 #define UNCLAMPED_FLOAT_TO_UBYTE(UB, F) \
513 do { \
514 fi_type __tmp; \
515 __tmp.f = (F); \
516 if (__tmp.i < 0) \
517 UB = (GLubyte) 0; \
518 else if (__tmp.i >= IEEE_0996) \
519 UB = (GLubyte) 255; \
520 else { \
521 __tmp.f = __tmp.f * (255.0F/256.0F) + 32768.0F; \
522 UB = (GLubyte) __tmp.i; \
523 } \
524 } while (0)
525 #define CLAMPED_FLOAT_TO_UBYTE(UB, F) \
526 do { \
527 fi_type __tmp; \
528 __tmp.f = (F) * (255.0F/256.0F) + 32768.0F; \
529 UB = (GLubyte) __tmp.i; \
530 } while (0)
531 #else
532 #define UNCLAMPED_FLOAT_TO_UBYTE(ub, f) \
533 ub = ((GLubyte) IROUND(CLAMP((f), 0.0F, 1.0F) * 255.0F))
534 #define CLAMPED_FLOAT_TO_UBYTE(ub, f) \
535 ub = ((GLubyte) IROUND((f) * 255.0F))
536 #endif
537
538
539 /***
540 *** COPY_FLOAT: copy a float from src to dest.
541 ***/
542 #define COPY_FLOAT( dst, src ) (dst) = (src)
543
544
545 /***
546 *** START_FAST_MATH: Set x86 FPU to faster, 32-bit precision mode (and save
547 *** original mode to a temporary).
548 *** END_FAST_MATH: Restore x86 FPU to original mode.
549 ***/
550 #if defined(__GNUC__) && defined(__i386__)
551 /*
552 * Set the x86 FPU control word to guarentee only 32 bits of precision
553 * are stored in registers. Allowing the FPU to store more introduces
554 * differences between situations where numbers are pulled out of memory
555 * vs. situations where the compiler is able to optimize register usage.
556 *
557 * In the worst case, we force the compiler to use a memory access to
558 * truncate the float, by specifying the 'volatile' keyword.
559 */
560 /* Hardware default: All exceptions masked, extended double precision,
561 * round to nearest (IEEE compliant):
562 */
563 #define DEFAULT_X86_FPU 0x037f
564 /* All exceptions masked, single precision, round to nearest:
565 */
566 #define FAST_X86_FPU 0x003f
567 /* The fldcw instruction will cause any pending FP exceptions to be
568 * raised prior to entering the block, and we clear any pending
569 * exceptions before exiting the block. Hence, asm code has free
570 * reign over the FPU while in the fast math block.
571 */
572 #if defined(NO_FAST_MATH)
573 #define START_FAST_MATH(x) \
574 do { \
575 static GLuint mask = DEFAULT_X86_FPU; \
576 __asm__ ( "fnstcw %0" : "=m" (*&(x)) ); \
577 __asm__ ( "fldcw %0" : : "m" (mask) ); \
578 } while (0)
579 #else
580 #define START_FAST_MATH(x) \
581 do { \
582 static GLuint mask = FAST_X86_FPU; \
583 __asm__ ( "fnstcw %0" : "=m" (*&(x)) ); \
584 __asm__ ( "fldcw %0" : : "m" (mask) ); \
585 } while (0)
586 #endif
587 /* Restore original FPU mode, and clear any exceptions that may have
588 * occurred in the FAST_MATH block.
589 */
590 #define END_FAST_MATH(x) \
591 do { \
592 __asm__ ( "fnclex ; fldcw %0" : : "m" (*&(x)) ); \
593 } while (0)
594
595 #elif defined(__WATCOMC__) && defined(__386__)
596 #define DEFAULT_X86_FPU 0x037f /* See GCC comments above */
597 #define FAST_X86_FPU 0x003f /* See GCC comments above */
598 void _watcom_start_fast_math(unsigned short *x,unsigned short *mask);
599 #pragma aux _watcom_start_fast_math = \
600 "fnstcw word ptr [eax]" \
601 "fldcw word ptr [ecx]" \
602 parm [eax] [ecx] \
603 modify exact [];
604 void _watcom_end_fast_math(unsigned short *x);
605 #pragma aux _watcom_end_fast_math = \
606 "fnclex" \
607 "fldcw word ptr [eax]" \
608 parm [eax] \
609 modify exact [];
610 #if defined(NO_FAST_MATH)
611 #define START_FAST_MATH(x) \
612 do { \
613 static GLushort mask = DEFAULT_X86_FPU; \
614 _watcom_start_fast_math(&x,&mask); \
615 } while (0)
616 #else
617 #define START_FAST_MATH(x) \
618 do { \
619 static GLushort mask = FAST_X86_FPU; \
620 _watcom_start_fast_math(&x,&mask); \
621 } while (0)
622 #endif
623 #define END_FAST_MATH(x) _watcom_end_fast_math(&x)
624 #else
625 #define START_FAST_MATH(x) x = 0
626 #define END_FAST_MATH(x) (void)(x)
627 #endif
628
629
630
631 /**********************************************************************
632 * Functions
633 */
634
635 extern void *
636 _mesa_malloc( size_t bytes );
637
638 extern void *
639 _mesa_calloc( size_t bytes );
640
641 extern void
642 _mesa_free( void *ptr );
643
644 extern void *
645 _mesa_align_malloc( size_t bytes, unsigned long alignment );
646
647 extern void *
648 _mesa_align_calloc( size_t bytes, unsigned long alignment );
649
650 extern void
651 _mesa_align_free( void *ptr );
652
653 extern void *
654 _mesa_realloc( void *oldBuffer, size_t oldSize, size_t newSize );
655
656 extern void *
657 _mesa_memcpy( void *dest, const void *src, size_t n );
658
659 extern void
660 _mesa_memset( void *dst, int val, size_t n );
661
662 extern void
663 _mesa_memset16( unsigned short *dst, unsigned short val, size_t n );
664
665 extern void
666 _mesa_bzero( void *dst, size_t n );
667
668
669 extern double
670 _mesa_sin(double a);
671
672 extern double
673 _mesa_cos(double a);
674
675 extern double
676 _mesa_sqrtd(double x);
677
678 extern float
679 _mesa_sqrtf(float x);
680
681 extern float
682 _mesa_inv_sqrtf(float x);
683
684 extern double
685 _mesa_pow(double x, double y);
686
687 extern float
688 _mesa_log2(float x);
689
690 extern unsigned int
691 _mesa_bitcount(unsigned int n);
692
693 extern GLhalfARB
694 _mesa_float_to_half(float f);
695
696 extern float
697 _mesa_half_to_float(GLhalfARB h);
698
699
700 extern char *
701 _mesa_getenv( const char *var );
702
703 extern char *
704 _mesa_strstr( const char *haystack, const char *needle );
705
706 extern char *
707 _mesa_strncat( char *dest, const char *src, size_t n );
708
709 extern char *
710 _mesa_strcpy( char *dest, const char *src );
711
712 extern char *
713 _mesa_strncpy( char *dest, const char *src, size_t n );
714
715 extern size_t
716 _mesa_strlen( const char *s );
717
718 extern int
719 _mesa_strcmp( const char *s1, const char *s2 );
720
721 extern int
722 _mesa_strncmp( const char *s1, const char *s2, size_t n );
723
724 extern char *
725 _mesa_strdup( const char *s );
726
727 extern int
728 _mesa_atoi( const char *s );
729
730 extern double
731 _mesa_strtod( const char *s, char **end );
732
733 extern int
734 _mesa_sprintf( char *str, const char *fmt, ... );
735
736 extern void
737 _mesa_printf( const char *fmtString, ... );
738
739
740 extern void
741 _mesa_warning( __GLcontext *gc, const char *fmtString, ... );
742
743 extern void
744 _mesa_problem( const __GLcontext *ctx, const char *fmtString, ... );
745
746 extern void
747 _mesa_error( __GLcontext *ctx, GLenum error, const char *fmtString, ... );
748
749 extern void
750 _mesa_debug( const __GLcontext *ctx, const char *fmtString, ... );
751
752
753 extern void
754 _mesa_init_default_imports( __GLimports *imports, void *driverCtx );
755
756
757 #ifdef __cplusplus
758 }
759 #endif
760
761
762 #endif /* IMPORTS_H */