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