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