#define LONGSTRING __extension__ in imports.h and use it to silence gcc
[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 /** 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 FLT_MAX_EXP
142 #define FLT_MAX_EXP 128
143 #endif
144
145 /* XXX this is a bit of a hack needed for compilation within XFree86 */
146 #ifndef FLT_MIN
147 #define FLT_MIN (1.0e-37)
148 #endif
149
150 /* Degrees to radians conversion: */
151 #define DEG2RAD (M_PI/180.0)
152
153
154 /***
155 *** USE_IEEE: Determine if we're using IEEE floating point
156 ***/
157 #if defined(__i386__) || defined(__386__) || defined(__sparc__) || \
158 defined(__s390x__) || defined(__powerpc__) || \
159 defined(__amd64__) || \
160 defined(ia64) || defined(__ia64__) || \
161 defined(__hppa__) || defined(hpux) || \
162 defined(__mips) || defined(_MIPS_ARCH) || \
163 defined(__arm__) || \
164 defined(__sh__) || defined(__m32r__) || \
165 (defined(__alpha__) && (defined(__IEEE_FLOAT) || !defined(VMS)))
166 #define USE_IEEE
167 #define IEEE_ONE 0x3f800000
168 #endif
169
170
171 /***
172 *** SQRTF: single-precision square root
173 ***/
174 #if 0 /* _mesa_sqrtf() not accurate enough - temporarily disabled */
175 # define SQRTF(X) _mesa_sqrtf(X)
176 #elif defined(XFree86LOADER) && defined(IN_MODULE) && !defined(NO_LIBCWRAPPER)
177 # define SQRTF(X) (float) xf86sqrt((float) (X))
178 #else
179 # define SQRTF(X) (float) sqrt((float) (X))
180 #endif
181
182
183 /***
184 *** INV_SQRTF: single-precision inverse square root
185 ***/
186 #if 0
187 #define INV_SQRTF(X) _mesa_inv_sqrt(X)
188 #else
189 #define INV_SQRTF(X) (1.0F / SQRTF(X)) /* this is faster on a P4 */
190 #endif
191
192
193 /***
194 *** LOG2: Log base 2 of float
195 ***/
196 #ifdef USE_IEEE
197 #if 0
198 /* This is pretty fast, but not accurate enough (only 2 fractional bits).
199 * Based on code from http://www.stereopsis.com/log2.html
200 */
201 static INLINE GLfloat LOG2(GLfloat x)
202 {
203 const GLfloat y = x * x * x * x;
204 const GLuint ix = *((GLuint *) &y);
205 const GLuint exp = (ix >> 23) & 0xFF;
206 const GLint log2 = ((GLint) exp) - 127;
207 return (GLfloat) log2 * (1.0 / 4.0); /* 4, because of x^4 above */
208 }
209 #endif
210 /* Pretty fast, and accurate.
211 * Based on code from http://www.flipcode.com/totd/
212 */
213 static INLINE GLfloat LOG2(GLfloat val)
214 {
215 fi_type num;
216 GLint log_2;
217 num.f = val;
218 log_2 = ((num.i >> 23) & 255) - 128;
219 num.i &= ~(255 << 23);
220 num.i += 127 << 23;
221 num.f = ((-1.0f/3) * num.f + 2) * num.f - 2.0f/3;
222 return num.f + log_2;
223 }
224 #elif defined(XFree86LOADER) && defined(IN_MODULE) && !defined(NO_LIBCWRAPPER)
225 #define LOG2(x) ((GLfloat) (xf86log(x) * 1.442695))
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(XFree86LOADER) && defined(IN_MODULE) && !defined(NO_LIBCWRAPPER)
297 #define CEILF(x) ((GLfloat) xf86ceil(x))
298 #define FLOORF(x) ((GLfloat) xf86floor(x))
299 #define FABSF(x) ((GLfloat) xf86fabs(x))
300 #define LOGF(x) ((GLfloat) xf86log(x))
301 #define EXPF(x) ((GLfloat) xf86exp(x))
302 #define LDEXPF(x,y) ((GLfloat) xf86ldexp(x,y))
303 #define FREXPF(x,y) ((GLfloat) xf86frexp(x,y))
304 #elif defined(__gnu_linux__)
305 /* C99 functions */
306 #define CEILF(x) ceilf(x)
307 #define FLOORF(x) floorf(x)
308 #define FABSF(x) fabsf(x)
309 #define LOGF(x) logf(x)
310 #define EXPF(x) expf(x)
311 #define LDEXPF(x,y) ldexpf(x,y)
312 #define FREXPF(x,y) frexpf(x,y)
313 #else
314 #define CEILF(x) ((GLfloat) ceil(x))
315 #define FLOORF(x) ((GLfloat) floor(x))
316 #define FABSF(x) ((GLfloat) fabs(x))
317 #define LOGF(x) ((GLfloat) log(x))
318 #define EXPF(x) ((GLfloat) exp(x))
319 #define LDEXPF(x,y) ((GLfloat) ldexp(x,y))
320 #define FREXPF(x,y) ((GLfloat) frexp(x,y))
321 #endif
322
323
324 /***
325 *** IROUND: return (as an integer) float rounded to nearest integer
326 ***/
327 #if defined(USE_SPARC_ASM) && defined(__GNUC__) && defined(__sparc__)
328 static INLINE int iround(float f)
329 {
330 int r;
331 __asm__ ("fstoi %1, %0" : "=f" (r) : "f" (f));
332 return r;
333 }
334 #define IROUND(x) iround(x)
335 #elif defined(USE_X86_ASM) && defined(__GNUC__) && defined(__i386__) && \
336 (!defined(__BEOS__) || (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95)))
337 static INLINE int iround(float f)
338 {
339 int r;
340 __asm__ ("fistpl %0" : "=m" (r) : "t" (f) : "st");
341 return r;
342 }
343 #define IROUND(x) iround(x)
344 #elif defined(USE_X86_ASM) && defined(__MSC__) && defined(__WIN32__)
345 static INLINE int iround(float f)
346 {
347 int r;
348 _asm {
349 fld f
350 fistp r
351 }
352 return r;
353 }
354 #define IROUND(x) iround(x)
355 #elif defined(__WATCOMC__) && defined(__386__)
356 long iround(float f);
357 #pragma aux iround = \
358 "push eax" \
359 "fistp dword ptr [esp]" \
360 "pop eax" \
361 parm [8087] \
362 value [eax] \
363 modify exact [eax];
364 #define IROUND(x) iround(x)
365 #else
366 #define IROUND(f) ((int) (((f) >= 0.0F) ? ((f) + 0.5F) : ((f) - 0.5F)))
367 #endif
368
369
370 /***
371 *** IROUND_POS: return (as an integer) positive float rounded to nearest int
372 ***/
373 #ifdef DEBUG
374 #define IROUND_POS(f) (assert((f) >= 0.0F), IROUND(f))
375 #else
376 #define IROUND_POS(f) (IROUND(f))
377 #endif
378
379
380 /***
381 *** IFLOOR: return (as an integer) floor of float
382 ***/
383 #if defined(USE_X86_ASM) && defined(__GNUC__) && defined(__i386__)
384 /*
385 * IEEE floor for computers that round to nearest or even.
386 * 'f' must be between -4194304 and 4194303.
387 * This floor operation is done by "(iround(f + .5) + iround(f - .5)) >> 1",
388 * but uses some IEEE specific tricks for better speed.
389 * Contributed by Josh Vanderhoof
390 */
391 static INLINE int ifloor(float f)
392 {
393 int ai, bi;
394 double af, bf;
395 af = (3 << 22) + 0.5 + (double)f;
396 bf = (3 << 22) + 0.5 - (double)f;
397 /* GCC generates an extra fstp/fld without this. */
398 __asm__ ("fstps %0" : "=m" (ai) : "t" (af) : "st");
399 __asm__ ("fstps %0" : "=m" (bi) : "t" (bf) : "st");
400 return (ai - bi) >> 1;
401 }
402 #define IFLOOR(x) ifloor(x)
403 #elif defined(USE_IEEE)
404 static INLINE int ifloor(float f)
405 {
406 int ai, bi;
407 double af, bf;
408 fi_type u;
409
410 af = (3 << 22) + 0.5 + (double)f;
411 bf = (3 << 22) + 0.5 - (double)f;
412 u.f = (float) af; ai = u.i;
413 u.f = (float) bf; bi = u.i;
414 return (ai - bi) >> 1;
415 }
416 #define IFLOOR(x) ifloor(x)
417 #else
418 static INLINE int ifloor(float f)
419 {
420 int i = IROUND(f);
421 return (i > f) ? i - 1 : i;
422 }
423 #define IFLOOR(x) ifloor(x)
424 #endif
425
426
427 /***
428 *** ICEIL: return (as an integer) ceiling of float
429 ***/
430 #if defined(USE_X86_ASM) && defined(__GNUC__) && defined(__i386__)
431 /*
432 * IEEE ceil for computers that round to nearest or even.
433 * 'f' must be between -4194304 and 4194303.
434 * This ceil operation is done by "(iround(f + .5) + iround(f - .5) + 1) >> 1",
435 * but uses some IEEE specific tricks for better speed.
436 * Contributed by Josh Vanderhoof
437 */
438 static INLINE int iceil(float f)
439 {
440 int ai, bi;
441 double af, bf;
442 af = (3 << 22) + 0.5 + (double)f;
443 bf = (3 << 22) + 0.5 - (double)f;
444 /* GCC generates an extra fstp/fld without this. */
445 __asm__ ("fstps %0" : "=m" (ai) : "t" (af) : "st");
446 __asm__ ("fstps %0" : "=m" (bi) : "t" (bf) : "st");
447 return (ai - bi + 1) >> 1;
448 }
449 #define ICEIL(x) iceil(x)
450 #elif defined(USE_IEEE)
451 static INLINE int iceil(float f)
452 {
453 int ai, bi;
454 double af, bf;
455 fi_type u;
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) >> 1;
461 }
462 #define ICEIL(x) iceil(x)
463 #else
464 static INLINE int iceil(float f)
465 {
466 int i = IROUND(f);
467 return (i < f) ? i + 1 : i;
468 }
469 #define ICEIL(x) iceil(x)
470 #endif
471
472
473 /***
474 *** UNCLAMPED_FLOAT_TO_UBYTE: clamp float to [0,1] and map to ubyte in [0,255]
475 *** CLAMPED_FLOAT_TO_UBYTE: map float known to be in [0,1] to ubyte in [0,255]
476 ***/
477 #if defined(USE_IEEE) && !defined(DEBUG)
478 #define IEEE_0996 0x3f7f0000 /* 0.996 or so */
479 /* This function/macro is sensitive to precision. Test very carefully
480 * if you change it!
481 */
482 #define UNCLAMPED_FLOAT_TO_UBYTE(UB, F) \
483 do { \
484 fi_type __tmp; \
485 __tmp.f = (F); \
486 if (__tmp.i < 0) \
487 UB = (GLubyte) 0; \
488 else if (__tmp.i >= IEEE_0996) \
489 UB = (GLubyte) 255; \
490 else { \
491 __tmp.f = __tmp.f * (255.0F/256.0F) + 32768.0F; \
492 UB = (GLubyte) __tmp.i; \
493 } \
494 } while (0)
495 #define CLAMPED_FLOAT_TO_UBYTE(UB, F) \
496 do { \
497 fi_type __tmp; \
498 __tmp.f = (F) * (255.0F/256.0F) + 32768.0F; \
499 UB = (GLubyte) __tmp.i; \
500 } while (0)
501 #else
502 #define UNCLAMPED_FLOAT_TO_UBYTE(ub, f) \
503 ub = ((GLubyte) IROUND(CLAMP((f), 0.0F, 1.0F) * 255.0F))
504 #define CLAMPED_FLOAT_TO_UBYTE(ub, f) \
505 ub = ((GLubyte) IROUND((f) * 255.0F))
506 #endif
507
508
509 /***
510 *** START_FAST_MATH: Set x86 FPU to faster, 32-bit precision mode (and save
511 *** original mode to a temporary).
512 *** END_FAST_MATH: Restore x86 FPU to original mode.
513 ***/
514 #if defined(__GNUC__) && defined(__i386__)
515 /*
516 * Set the x86 FPU control word to guarentee only 32 bits of precision
517 * are stored in registers. Allowing the FPU to store more introduces
518 * differences between situations where numbers are pulled out of memory
519 * vs. situations where the compiler is able to optimize register usage.
520 *
521 * In the worst case, we force the compiler to use a memory access to
522 * truncate the float, by specifying the 'volatile' keyword.
523 */
524 /* Hardware default: All exceptions masked, extended double precision,
525 * round to nearest (IEEE compliant):
526 */
527 #define DEFAULT_X86_FPU 0x037f
528 /* All exceptions masked, single precision, round to nearest:
529 */
530 #define FAST_X86_FPU 0x003f
531 /* The fldcw instruction will cause any pending FP exceptions to be
532 * raised prior to entering the block, and we clear any pending
533 * exceptions before exiting the block. Hence, asm code has free
534 * reign over the FPU while in the fast math block.
535 */
536 #if defined(NO_FAST_MATH)
537 #define START_FAST_MATH(x) \
538 do { \
539 static GLuint mask = DEFAULT_X86_FPU; \
540 __asm__ ( "fnstcw %0" : "=m" (*&(x)) ); \
541 __asm__ ( "fldcw %0" : : "m" (mask) ); \
542 } while (0)
543 #else
544 #define START_FAST_MATH(x) \
545 do { \
546 static GLuint mask = FAST_X86_FPU; \
547 __asm__ ( "fnstcw %0" : "=m" (*&(x)) ); \
548 __asm__ ( "fldcw %0" : : "m" (mask) ); \
549 } while (0)
550 #endif
551 /* Restore original FPU mode, and clear any exceptions that may have
552 * occurred in the FAST_MATH block.
553 */
554 #define END_FAST_MATH(x) \
555 do { \
556 __asm__ ( "fnclex ; fldcw %0" : : "m" (*&(x)) ); \
557 } while (0)
558
559 #elif defined(__WATCOMC__) && defined(__386__)
560 #define DEFAULT_X86_FPU 0x037f /* See GCC comments above */
561 #define FAST_X86_FPU 0x003f /* See GCC comments above */
562 void _watcom_start_fast_math(unsigned short *x,unsigned short *mask);
563 #pragma aux _watcom_start_fast_math = \
564 "fnstcw word ptr [eax]" \
565 "fldcw word ptr [ecx]" \
566 parm [eax] [ecx] \
567 modify exact [];
568 void _watcom_end_fast_math(unsigned short *x);
569 #pragma aux _watcom_end_fast_math = \
570 "fnclex" \
571 "fldcw word ptr [eax]" \
572 parm [eax] \
573 modify exact [];
574 #if defined(NO_FAST_MATH)
575 #define START_FAST_MATH(x) \
576 do { \
577 static GLushort mask = DEFAULT_X86_FPU; \
578 _watcom_start_fast_math(&x,&mask); \
579 } while (0)
580 #else
581 #define START_FAST_MATH(x) \
582 do { \
583 static GLushort mask = FAST_X86_FPU; \
584 _watcom_start_fast_math(&x,&mask); \
585 } while (0)
586 #endif
587 #define END_FAST_MATH(x) _watcom_end_fast_math(&x)
588
589 #elif defined(_MSC_VER) && defined(_M_IX86)
590 #define DEFAULT_X86_FPU 0x037f /* See GCC comments above */
591 #define FAST_X86_FPU 0x003f /* See GCC comments above */
592 #if defined(NO_FAST_MATH)
593 #define START_FAST_MATH(x) do {\
594 static GLuint mask = DEFAULT_X86_FPU;\
595 __asm fnstcw word ptr [x]\
596 __asm fldcw word ptr [mask]\
597 } while(0)
598 #else
599 #define START_FAST_MATH(x) do {\
600 static GLuint mask = FAST_X86_FPU;\
601 __asm fnstcw word ptr [x]\
602 __asm fldcw word ptr [mask]\
603 } while(0)
604 #endif
605 #define END_FAST_MATH(x) do {\
606 __asm fnclex\
607 __asm fldcw word ptr [x]\
608 } while(0)
609
610 #else
611 #define START_FAST_MATH(x) x = 0
612 #define END_FAST_MATH(x) (void)(x)
613 #endif
614
615
616 /**
617 * Return 1 if this is a little endian machine, 0 if big endian.
618 */
619 static INLINE GLboolean
620 _mesa_little_endian(void)
621 {
622 const GLuint ui = 1; /* intentionally not static */
623 return *((const GLubyte *) &ui);
624 }
625
626
627
628 /**********************************************************************
629 * Functions
630 */
631
632 extern void *
633 _mesa_malloc( size_t bytes );
634
635 extern void *
636 _mesa_calloc( size_t bytes );
637
638 extern void
639 _mesa_free( void *ptr );
640
641 extern void *
642 _mesa_align_malloc( size_t bytes, unsigned long alignment );
643
644 extern void *
645 _mesa_align_calloc( size_t bytes, unsigned long alignment );
646
647 extern void
648 _mesa_align_free( void *ptr );
649
650 extern void *
651 _mesa_align_realloc(void *oldBuffer, size_t oldSize, size_t newSize,
652 unsigned long alignment);
653
654 extern void *
655 _mesa_exec_malloc( GLuint size );
656
657 extern void
658 _mesa_exec_free( void *addr );
659
660 extern void *
661 _mesa_realloc( void *oldBuffer, size_t oldSize, size_t newSize );
662
663 extern void *
664 _mesa_memcpy( void *dest, const void *src, size_t n );
665
666 extern void
667 _mesa_memset( void *dst, int val, size_t n );
668
669 extern void
670 _mesa_memset16( unsigned short *dst, unsigned short val, size_t n );
671
672 extern void
673 _mesa_bzero( void *dst, size_t n );
674
675 extern int
676 _mesa_memcmp( const void *s1, const void *s2, size_t n );
677
678 extern double
679 _mesa_sin(double a);
680
681 extern float
682 _mesa_sinf(float a);
683
684 extern double
685 _mesa_cos(double a);
686
687 extern float
688 _mesa_asinf(float x);
689
690 extern float
691 _mesa_atanf(float x);
692
693 extern double
694 _mesa_sqrtd(double x);
695
696 extern float
697 _mesa_sqrtf(float x);
698
699 extern float
700 _mesa_inv_sqrtf(float x);
701
702 extern double
703 _mesa_pow(double x, double y);
704
705 extern int
706 _mesa_ffs(int i);
707
708 extern unsigned int
709 _mesa_bitcount(unsigned int n);
710
711 extern GLhalfARB
712 _mesa_float_to_half(float f);
713
714 extern float
715 _mesa_half_to_float(GLhalfARB h);
716
717
718 extern void *
719 _mesa_bsearch( const void *key, const void *base, size_t nmemb, size_t size,
720 int (*compar)(const void *, const void *) );
721
722 extern char *
723 _mesa_getenv( const char *var );
724
725 extern char *
726 _mesa_strstr( const char *haystack, const char *needle );
727
728 extern char *
729 _mesa_strncat( char *dest, const char *src, size_t n );
730
731 extern char *
732 _mesa_strcpy( char *dest, const char *src );
733
734 extern char *
735 _mesa_strncpy( char *dest, const char *src, size_t n );
736
737 extern size_t
738 _mesa_strlen( const char *s );
739
740 extern int
741 _mesa_strcmp( const char *s1, const char *s2 );
742
743 extern int
744 _mesa_strncmp( const char *s1, const char *s2, size_t n );
745
746 extern char *
747 _mesa_strdup( const char *s );
748
749 extern int
750 _mesa_atoi( const char *s );
751
752 extern double
753 _mesa_strtod( const char *s, char **end );
754
755 extern int
756 _mesa_sprintf( char *str, const char *fmt, ... );
757
758 extern void
759 _mesa_printf( const char *fmtString, ... );
760
761 extern int
762 _mesa_vsprintf( char *str, const char *fmt, va_list args );
763
764
765 extern void
766 _mesa_warning( __GLcontext *gc, const char *fmtString, ... );
767
768 extern void
769 _mesa_problem( const __GLcontext *ctx, const char *fmtString, ... );
770
771 extern void
772 _mesa_error( __GLcontext *ctx, GLenum error, const char *fmtString, ... );
773
774 extern void
775 _mesa_debug( const __GLcontext *ctx, const char *fmtString, ... );
776
777 extern void
778 _mesa_exit( int status );
779
780
781 extern void
782 _mesa_init_default_imports( __GLimports *imports, void *driverCtx );
783
784
785 #ifdef __cplusplus
786 }
787 #endif
788
789
790 #endif /* IMPORTS_H */