3a73275ffd62748fd259113ac60b017d31cc79cd
2 * Mesa 3-D graphics library
4 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 * OTHER DEALINGS IN THE SOFTWARE.
28 * Standard C library function wrappers.
30 * This file provides wrappers for all the standard C library functions
31 * like malloc(), free(), printf(), getenv(), etc.
42 #include "util/compiler.h"
43 #include "util/bitscan.h"
44 #include "util/u_memory.h"
52 * For GL_ARB_vertex_buffer_object we need to treat vertex array pointers
53 * as offsets into buffer stores. Since the vertex array pointer and
54 * buffer store pointer are both pointers and we need to add them, we use
56 * Both pointers/offsets are expressed in bytes.
58 #define ADD_POINTERS(A, B) ( (uint8_t *) (A) + (uintptr_t) (B) )
62 * Sometimes we treat floats as ints. On x86 systems, moving a float
63 * as an int (thereby using integer registers instead of FP registers) is
64 * a performance win. Typically, this can be done with ordinary casts.
65 * But with gcc's -fstrict-aliasing flag (which defaults to on in gcc 3.0)
66 * these casts generate warnings.
67 * The following union typedef is used to solve that.
69 typedef union { float f
; int i
; unsigned u
; } fi_type
;
80 # define finite _finite
85 *** IS_INF_OR_NAN: test if float is infinite or NaN
88 #define IS_INF_OR_NAN(x) (!isfinite(x))
90 #define IS_INF_OR_NAN(x) (!finite(x))
91 #elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
92 #define IS_INF_OR_NAN(x) (!isfinite(x))
94 #define IS_INF_OR_NAN(x) (!finite(x))
99 * Convert float to int by rounding to nearest integer, away from zero.
101 static inline int IROUND(float f
)
103 return (int) ((f
>= 0.0F
) ? (f
+ 0.5F
) : (f
- 0.5F
));
107 * Convert float to int64 by rounding to nearest integer.
109 static inline int64_t IROUND64(float f
)
111 return (int64_t) ((f
>= 0.0F
) ? (f
+ 0.5F
) : (f
- 0.5F
));
115 /**********************************************************************
120 _mesa_align_malloc( size_t bytes
, unsigned long alignment
);
123 _mesa_align_calloc( size_t bytes
, unsigned long alignment
);
126 _mesa_align_free( void *ptr
);
129 _mesa_align_realloc(void *oldBuffer
, size_t oldSize
, size_t newSize
,
130 unsigned long alignment
);
133 _mesa_snprintf( char *str
, size_t size
, const char *fmt
, ... ) PRINTFLIKE(3, 4);
136 _mesa_vsnprintf(char *str
, size_t size
, const char *fmt
, va_list arg
);
139 #if defined(_WIN32) && !defined(HAVE_STRTOK_R)
140 #define strtok_r strtok_s
148 #endif /* IMPORTS_H */