Index: src/mesa/main/enums.c =================================================================== RCS file: /cvs/mesa/Mesa/src/mesa/main/enums.c,v retrieving revision 1.40 diff -u -r1.40 enums.c --- src/mesa/main/enums.c 26 Aug 2005 17:50:39 -0000 1.40 +++ src/mesa/main/enums.c 16 Sep 2005 20:59:35 -0000 @@ -4542,7 +4542,7 @@ { unsigned * i; - i = (unsigned *)bsearch( & nr, reduced_enums, Elements(reduced_enums), + i = (unsigned *)_mesa_bsearch( & nr, reduced_enums, Elements(reduced_enums), sizeof(reduced_enums[0]), (cfunc) compar_nr ); if ( i != NULL ) { @@ -4560,7 +4560,7 @@ enum_elt * f = NULL; if ( symbol != NULL ) { - f = (enum_elt *)bsearch( symbol, all_enums, Elements(all_enums), + f = (enum_elt *)_mesa_bsearch( symbol, all_enums, Elements(all_enums), sizeof( enum_elt ), (cfunc) compar_name ); } Index: src/mesa/main/imports.c =================================================================== RCS file: /cvs/mesa/Mesa/src/mesa/main/imports.c,v retrieving revision 1.51 diff -u -r1.51 imports.c --- src/mesa/main/imports.c 16 Sep 2005 18:14:24 -0000 1.51 +++ src/mesa/main/imports.c 16 Sep 2005 20:59:40 -0000 @@ -23,7 +23,6 @@ * \todo Functions still needed: * - scanf * - qsort - * - bsearch * - rand and RAND_MAX * * \note When compiled into a XFree86 module these functions wrap around @@ -530,6 +529,20 @@ /** + * Wrapper around either ffs() or xf86ffs(). + */ +int +_mesa_ffs(int i) +{ +#if defined(XFree86LOADER) && defined(IN_MODULE) + return xf86ffs(i); +#else + return ffs(i); +#endif +} + + +/** * Return number of bits set in given GLuint. */ unsigned int @@ -685,6 +698,27 @@ /**********************************************************************/ +/** \name Sort & Search */ +/*@{*/ + +/** + * Wrapper for bsearch(). + */ +void * +_mesa_bsearch( const void *key, const void *base, size_t nmemb, size_t size, + int (*compar)(const void *, const void *) ) +{ +#if defined(XFree86LOADER) && defined(IN_MODULE) + return xf86bsearch(key, base, nmemb, size, compar); +#else + return bsearch(key, base, nmemb, size, compar); +#endif +} + +/*@}*/ + + +/**********************************************************************/ /** \name Environment vars */ /*@{*/ Index: src/mesa/main/imports.h =================================================================== RCS file: /cvs/mesa/Mesa/src/mesa/main/imports.h,v retrieving revision 1.56 diff -u -r1.56 imports.h --- src/mesa/main/imports.h 16 Sep 2005 18:14:24 -0000 1.56 +++ src/mesa/main/imports.h 16 Sep 2005 20:59:42 -0000 @@ -274,6 +274,8 @@ *** CEILF: ceiling of float *** FLOORF: floor of float *** FABSF: absolute value of float + *** LOGF: the natural logarithm (base e) of the value + *** EXPF: raise e to the value *** LDEXPF: multiply value by an integral power of two *** FREXPF: extract mantissa and exponent from value ***/ @@ -281,6 +283,8 @@ #define CEILF(x) ((GLfloat) xf86ceil(x)) #define FLOORF(x) ((GLfloat) xf86floor(x)) #define FABSF(x) ((GLfloat) xf86fabs(x)) +#define LOGF(x) ((GLfloat) xf86log(x)) +#define EXPF(x) ((GLfloat) xf86exp(x)) #define LDEXPF(x,y) ((GLfloat) xf86ldexp(x,y)) #define FREXPF(x,y) ((GLfloat) xf86frexp(x,y)) #elif defined(__gnu_linux__) @@ -288,12 +292,16 @@ #define CEILF(x) ceilf(x) #define FLOORF(x) floorf(x) #define FABSF(x) fabsf(x) +#define LOGF(x) logf(x) +#define EXPF(x) expf(x) #define LDEXPF(x,y) ldexpf(x,y) #define FREXPF(x,y) frexpf(x,y) #else #define CEILF(x) ((GLfloat) ceil(x)) #define FLOORF(x) ((GLfloat) floor(x)) #define FABSF(x) ((GLfloat) fabs(x)) +#define LOGF(x) ((GLfloat) log(x)) +#define EXPF(x) ((GLfloat) exp(x)) #define LDEXPF(x,y) ((GLfloat) ldexp(x,y)) #define FREXPF(x,y) ((GLfloat) frexp(x,y)) #endif @@ -637,6 +645,9 @@ extern float _mesa_log2(float x); +extern int +_mesa_ffs(int i); + extern unsigned int _mesa_bitcount(unsigned int n); @@ -647,6 +658,10 @@ _mesa_half_to_float(GLhalfARB h); +extern void * +_mesa_bsearch( const void *key, const void *base, size_t nmemb, size_t size, + int (*compar)(const void *, const void *) ); + extern char * _mesa_getenv( const char *var ); Index: src/mesa/main/texenvprogram.c =================================================================== RCS file: /cvs/mesa/Mesa/src/mesa/main/texenvprogram.c,v retrieving revision 1.23 diff -u -r1.23 texenvprogram.c --- src/mesa/main/texenvprogram.c 16 Sep 2005 18:14:24 -0000 1.23 +++ src/mesa/main/texenvprogram.c 16 Sep 2005 20:59:45 -0000 @@ -350,12 +350,12 @@ /* First try and reuse temps which have been used already: */ - bit = ffs( ~p->temp_in_use & p->alu_temps ); + bit = _mesa_ffs( ~p->temp_in_use & p->alu_temps ); /* Then any unused temporary: */ if (!bit) - bit = ffs( ~p->temp_in_use ); + bit = _mesa_ffs( ~p->temp_in_use ); if (!bit) { _mesa_problem(NULL, "%s: out of temporaries\n", __FILE__); @@ -378,12 +378,12 @@ * ~p->temps_output isn't necessary, but will keep it there for * now: */ - bit = ffs( ~p->temp_in_use & ~p->alu_temps & ~p->temps_output ); + bit = _mesa_ffs( ~p->temp_in_use & ~p->alu_temps & ~p->temps_output ); /* Then any unused temporary: */ if (!bit) - bit = ffs( ~p->temp_in_use ); + bit = _mesa_ffs( ~p->temp_in_use ); if (!bit) { _mesa_problem(NULL, "%s: out of temporaries\n", __FILE__); Index: src/mesa/math/m_matrix.c =================================================================== RCS file: /cvs/mesa/Mesa/src/mesa/math/m_matrix.c,v retrieving revision 1.23 diff -u -r1.23 m_matrix.c --- src/mesa/math/m_matrix.c 16 Sep 2005 18:14:24 -0000 1.23 +++ src/mesa/math/m_matrix.c 16 Sep 2005 20:59:49 -0000 @@ -382,9 +382,9 @@ r3[7] = 1.0, r3[4] = r3[5] = r3[6] = 0.0; /* choose pivot - or die */ - if (fabs(r3[0])>fabs(r2[0])) SWAP_ROWS(r3, r2); - if (fabs(r2[0])>fabs(r1[0])) SWAP_ROWS(r2, r1); - if (fabs(r1[0])>fabs(r0[0])) SWAP_ROWS(r1, r0); + if (FABSF(r3[0])>FABSF(r2[0])) SWAP_ROWS(r3, r2); + if (FABSF(r2[0])>FABSF(r1[0])) SWAP_ROWS(r2, r1); + if (FABSF(r1[0])>FABSF(r0[0])) SWAP_ROWS(r1, r0); if (0.0 == r0[0]) return GL_FALSE; /* eliminate first variable */ @@ -402,8 +402,8 @@ if (s != 0.0) { r1[7] -= m1 * s; r2[7] -= m2 * s; r3[7] -= m3 * s; } /* choose pivot - or die */ - if (fabs(r3[1])>fabs(r2[1])) SWAP_ROWS(r3, r2); - if (fabs(r2[1])>fabs(r1[1])) SWAP_ROWS(r2, r1); + if (FABSF(r3[1])>FABSF(r2[1])) SWAP_ROWS(r3, r2); + if (FABSF(r2[1])>FABSF(r1[1])) SWAP_ROWS(r2, r1); if (0.0 == r1[1]) return GL_FALSE; /* eliminate second variable */ @@ -416,7 +416,7 @@ s = r1[7]; if (0.0 != s) { r2[7] -= m2 * s; r3[7] -= m3 * s; } /* choose pivot - or die */ - if (fabs(r3[2])>fabs(r2[2])) SWAP_ROWS(r3, r2); + if (FABSF(r3[2])>FABSF(r2[2])) SWAP_ROWS(r3, r2); if (0.0 == r2[2]) return GL_FALSE; /* eliminate third variable */ @@ -1075,7 +1075,7 @@ m[2] *= x; m[6] *= y; m[10] *= z; m[3] *= x; m[7] *= y; m[11] *= z; - if (fabs(x - y) < 1e-8 && fabs(x - z) < 1e-8) + if (FABSF(x - y) < 1e-8 && FABSF(x - z) < 1e-8) mat->flags |= MAT_FLAG_UNIFORM_SCALE; else mat->flags |= MAT_FLAG_GENERAL_SCALE; Index: src/mesa/shader/arbprogparse.c =================================================================== RCS file: /cvs/mesa/Mesa/src/mesa/shader/arbprogparse.c,v retrieving revision 1.34 diff -u -r1.34 arbprogparse.c --- src/mesa/shader/arbprogparse.c 16 Sep 2005 18:18:47 -0000 1.34 +++ src/mesa/shader/arbprogparse.c 16 Sep 2005 20:59:58 -0000 @@ -3886,7 +3886,7 @@ while (extensions < end) { - const GLubyte *name_end = (const GLubyte *) strchr ((const char *) extensions, ' '); + const GLubyte *name_end = (const GLubyte *) _mesa_strstr ((const char *) extensions, " "); if (name_end == NULL) name_end = end; if (name_end - extensions == ext_len && _mesa_strncmp ((const char *) ext, @@ -4053,10 +4053,10 @@ if (0) { int line, col; char *s; - printf("Program: %s\n", (char *) strz); - printf("Error Pos: %d\n", ctx->Program.ErrorPos); + _mesa_printf("Program: %s\n", (char *) strz); + _mesa_printf("Error Pos: %d\n", ctx->Program.ErrorPos); s = (char *) _mesa_find_line_column(strz, strz+ctx->Program.ErrorPos, &line, &col); - printf("line %d col %d: %s\n", line, col, s); + _mesa_printf("line %d col %d: %s\n", line, col, s); } grammar_destroy (arbprogram_syn_id); @@ -4064,7 +4064,7 @@ } #if DEBUG_PARSING - printf ("Destroying grammer dict [parse retval: %d]\n", err); + _mesa_printf ("Destroying grammer dict [parse retval: %d]\n", err); #endif grammar_destroy (arbprogram_syn_id); @@ -4109,7 +4109,7 @@ err = parse_arb_program (ctx, inst, &vc_head, program); #if DEBUG_PARSING - fprintf (stderr, "Symantic analysis returns %d [1 is bad!]\n", err); + _mesa_printf ("Symantic analysis returns %d [1 is bad!]\n", err); #endif } @@ -4120,7 +4120,7 @@ _mesa_free (parsed); #if DEBUG_PARSING - printf ("_mesa_parse_arb_program() done\n"); + _mesa_printf ("_mesa_parse_arb_program() done\n"); #endif return err; } Index: src/mesa/shader/nvvertexec.c =================================================================== RCS file: /cvs/mesa/Mesa/src/mesa/shader/nvvertexec.c,v retrieving revision 1.12 diff -u -r1.12 nvvertexec.c --- src/mesa/shader/nvvertexec.c 1 Jul 2005 01:30:03 -0000 1.12 +++ src/mesa/shader/nvvertexec.c 16 Sep 2005 21:00:00 -0000 @@ -452,7 +452,7 @@ { GLfloat t[4], q[4], floor_t0; fetch_vector1( &inst->SrcReg[0], state, t ); - floor_t0 = (float) floor(t[0]); + floor_t0 = FLOORF(t[0]); if (floor_t0 > FLT_MAX_EXP) { SET_POS_INFINITY(q[0]); SET_POS_INFINITY(q[2]); @@ -481,7 +481,7 @@ { GLfloat t[4], q[4], abs_t0; fetch_vector1( &inst->SrcReg[0], state, t ); - abs_t0 = (GLfloat) fabs(t[0]); + abs_t0 = FABSF(t[0]); if (abs_t0 != 0.0F) { /* Since we really can't handle infinite values on VMS * like other OSes we'll use __MAXFLOAT to represent @@ -499,7 +499,7 @@ } else { int exponent; - double mantissa = frexp(t[0], &exponent); + GLfloat mantissa = FREXPF(t[0], &exponent); q[0] = (GLfloat) (exponent - 1); q[1] = (GLfloat) (2.0 * mantissa); /* map [.5, 1) -> [1, 2) */ q[2] = (GLfloat) (q[0] + LOG2(q[1])); @@ -635,7 +635,7 @@ { GLfloat t[4]; fetch_vector4( &inst->SrcReg[0], state, t ); - state->AddressReg[0] = (GLint) floor(t[0]); + state->AddressReg[0] = (GLint) FLOORF(t[0]); } break; case VP_OPCODE_DPH: Index: src/mesa/shader/slang/slang_compile.c =================================================================== RCS file: /cvs/mesa/Mesa/src/mesa/shader/slang/slang_compile.c,v retrieving revision 1.10 diff -u -r1.10 slang_compile.c --- src/mesa/shader/slang/slang_compile.c 16 Sep 2005 18:14:25 -0000 1.10 +++ src/mesa/shader/slang/slang_compile.c 16 Sep 2005 21:00:05 -0000 @@ -635,7 +635,7 @@ char buf[1024]; va_start (va, msg); - _mesa_sprintf (buf, msg, va); + vsprintf (buf, msg, va); if (slang_info_log_message (log, "error", buf)) return 1; slang_info_log_memory (log); @@ -649,7 +649,7 @@ char buf[1024]; va_start (va, msg); - _mesa_sprintf (buf, msg, va); + vsprintf (buf, msg, va); if (slang_info_log_message (log, "warning", buf)) return 1; slang_info_log_memory (log); @@ -685,7 +685,7 @@ slang_info_log_memory (C->L); return 0; } - C->I += strlen ((const char *) C->I) + 1; + C->I += _mesa_strlen ((const char *) C->I) + 1; return 1; } @@ -734,8 +734,9 @@ return 0; } - whole = (char *) (slang_alloc_malloc ((strlen (integral) + strlen (fractional) + strlen ( - exponent) + 3) * sizeof (char))); + whole = (char *) (slang_alloc_malloc ((_mesa_strlen (integral) + + _mesa_strlen (fractional) + _mesa_strlen (exponent) + 3) * + sizeof (char))); if (whole == NULL) { slang_alloc_free (exponent); @@ -751,7 +752,7 @@ slang_string_concat (whole, "E"); slang_string_concat (whole, exponent); - *number = (float) (atof (whole)); + *number = (float) (_mesa_strtod(whole, (char **)NULL)); slang_alloc_free (whole); slang_alloc_free (exponent); Index: src/mesa/swrast/s_aaline.c =================================================================== RCS file: /cvs/mesa/Mesa/src/mesa/swrast/s_aaline.c,v retrieving revision 1.23 diff -u -r1.23 s_aaline.c --- src/mesa/swrast/s_aaline.c 9 Mar 2004 16:58:26 -0000 1.23 +++ src/mesa/swrast/s_aaline.c 16 Sep 2005 21:00:07 -0000 @@ -210,7 +210,7 @@ if (rho2 == 0.0F) return 0.0; else - return (GLfloat) (log(rho2) * 1.442695 * 0.5);/* 1.442695 = 1/log(2) */ + return (GLfloat) (LOGF(rho2) * 1.442695 * 0.5);/* 1.442695 = 1/log(2) */ } Index: src/mesa/swrast/s_fog.c =================================================================== RCS file: /cvs/mesa/Mesa/src/mesa/swrast/s_fog.c,v retrieving revision 1.30 diff -u -r1.30 s_fog.c --- src/mesa/swrast/s_fog.c 17 Jan 2005 16:16:35 -0000 1.30 +++ src/mesa/swrast/s_fog.c 16 Sep 2005 21:00:07 -0000 @@ -51,12 +51,12 @@ return CLAMP(f, 0.0F, 1.0F); case GL_EXP: d = ctx->Fog.Density; - f = (GLfloat) exp(-d * z); + f = EXPF(-d * z); f = CLAMP(f, 0.0F, 1.0F); return f; case GL_EXP2: d = ctx->Fog.Density; - f = (GLfloat) exp(-(d * d * z * z)); + f = EXPF(-(d * d * z * z)); f = CLAMP(f, 0.0F, 1.0F); return f; default: @@ -130,7 +130,7 @@ GLuint i; for (i = 0; i < span->end; i++) { GLfloat f, oneMinusF; - f = (GLfloat) exp(density * FABSF(fogCoord) / w); + f = EXPF(density * FABSF(fogCoord) / w); f = CLAMP(f, 0.0F, 1.0F); oneMinusF = 1.0F - f; rgba[i][RCOMP] = (GLchan) (f * rgba[i][RCOMP] + oneMinusF * rFog); @@ -158,7 +158,7 @@ if (tmp < FLT_MIN_10_EXP) tmp = FLT_MIN_10_EXP; #endif - f = (GLfloat) exp(tmp); + f = EXPF(tmp); f = CLAMP(f, 0.0F, 1.0F); oneMinusF = 1.0F - f; rgba[i][RCOMP] = (GLchan) (f * rgba[i][RCOMP] + oneMinusF * rFog); @@ -259,7 +259,7 @@ GLfloat w = haveW ? span->w : 1.0F; GLuint i; for (i = 0; i < span->end; i++) { - GLfloat f = (GLfloat) exp(density * fogCoord / w); + GLfloat f = EXPF(density * fogCoord / w); f = CLAMP(f, 0.0F, 1.0F); index[i] = (GLuint) ((GLfloat) index[i] + (1.0F - f) * fogIndex); fogCoord += fogStep; @@ -284,7 +284,7 @@ if (tmp < FLT_MIN_10_EXP) tmp = FLT_MIN_10_EXP; #endif - f = (GLfloat) exp(tmp); + f = EXPF(tmp); f = CLAMP(f, 0.0F, 1.0F); index[i] = (GLuint) ((GLfloat) index[i] + (1.0F - f) * fogIndex); fogCoord += fogStep; Index: src/mesa/swrast/s_nvfragprog.c =================================================================== RCS file: /cvs/mesa/Mesa/src/mesa/swrast/s_nvfragprog.c,v retrieving revision 1.56 diff -u -r1.56 s_nvfragprog.c --- src/mesa/swrast/s_nvfragprog.c 16 Sep 2005 18:14:25 -0000 1.56 +++ src/mesa/swrast/s_nvfragprog.c 16 Sep 2005 21:00:11 -0000 @@ -821,7 +821,7 @@ result[0] = 1.0F; result[1] = a[0]; /* XXX we could probably just use pow() here */ - result[2] = (a[0] > 0.0F) ? (GLfloat) exp(a[3] * log(a[1])) : 0.0F; + result[2] = (a[0] > 0.0F) ? EXPF(a[3] * LOGF(a[1])) : 0.0F; result[3] = 1.0F; store_vector4( inst, machine, result ); } Index: src/mesa/swrast/s_texfilter.c =================================================================== RCS file: /cvs/mesa/Mesa/src/mesa/swrast/s_texfilter.c,v retrieving revision 1.4 diff -u -r1.4 s_texfilter.c --- src/mesa/swrast/s_texfilter.c 16 Sep 2005 04:16:48 -0000 1.4 +++ src/mesa/swrast/s_texfilter.c 16 Sep 2005 21:00:16 -0000 @@ -297,7 +297,7 @@ } \ break; \ case GL_MIRROR_CLAMP_EXT: \ - U = (GLfloat) fabs(S); \ + U = FABSF(S); \ if (U >= 1.0F) \ U = (GLfloat) SIZE; \ else \ @@ -307,7 +307,7 @@ I1 = I0 + 1; \ break; \ case GL_MIRROR_CLAMP_TO_EDGE_EXT: \ - U = (GLfloat) fabs(S); \ + U = FABSF(S); \ if (U >= 1.0F) \ U = (GLfloat) SIZE; \ else \ @@ -324,7 +324,7 @@ { \ const GLfloat min = -1.0F / (2.0F * SIZE); \ const GLfloat max = 1.0F - min; \ - U = (GLfloat) fabs(S); \ + U = FABSF(S); \ if (U <= min) \ U = min * SIZE; \ else if (U >= max) \ @@ -418,7 +418,7 @@ { \ /* s limited to [0,1] */ \ /* i limited to [0,size-1] */ \ - const GLfloat u = (GLfloat) fabs(S); \ + const GLfloat u = FABSF(S); \ if (u <= 0.0F) \ I = 0; \ else if (u >= 1.0F) \ @@ -433,7 +433,7 @@ /* i limited to [0, size-1] */ \ const GLfloat min = 1.0F / (2.0F * SIZE); \ const GLfloat max = 1.0F - min; \ - const GLfloat u = (GLfloat) fabs(S); \ + const GLfloat u = FABSF(S); \ if (u < min) \ I = 0; \ else if (u > max) \ @@ -448,7 +448,7 @@ /* i limited to [0, size-1] */ \ const GLfloat min = -1.0F / (2.0F * SIZE); \ const GLfloat max = 1.0F - min; \ - const GLfloat u = (GLfloat) fabs(S); \ + const GLfloat u = FABSF(S); \ if (u < min) \ I = -1; \ else if (u > max) \ Index: src/mesa/tnl/t_vb_arbprogram.c =================================================================== RCS file: /cvs/mesa/Mesa/src/mesa/tnl/t_vb_arbprogram.c,v retrieving revision 1.25 diff -u -r1.25 t_vb_arbprogram.c --- src/mesa/tnl/t_vb_arbprogram.c 16 Sep 2005 18:14:25 -0000 1.25 +++ src/mesa/tnl/t_vb_arbprogram.c 16 Sep 2005 21:00:19 -0000 @@ -97,7 +97,7 @@ */ static GLfloat ApproxLog2(GLfloat t) { - return (GLfloat) (log(t) * 1.442695F); + return (GLfloat) (LOGF(t) * 1.442695F); } static GLfloat ApproxExp2(GLfloat t) Index: src/mesa/tnl/t_vb_fog.c =================================================================== RCS file: /cvs/mesa/Mesa/src/mesa/tnl/t_vb_fog.c,v retrieving revision 1.31 diff -u -r1.31 t_vb_fog.c --- src/mesa/tnl/t_vb_fog.c 22 Apr 2005 12:51:19 -0000 1.31 +++ src/mesa/tnl/t_vb_fog.c 16 Sep 2005 21:00:20 -0000 @@ -80,7 +80,7 @@ GLfloat f = 0.0F; GLint i = 0; for ( ; i < FOG_EXP_TABLE_SIZE ; i++, f += FOG_INCR) { - exp_table[i] = (GLfloat) exp(-f); + exp_table[i] = EXPF(-f); } inited = 1; } Index: src/mesa/tnl/t_vp_build.c =================================================================== RCS file: /cvs/mesa/Mesa/src/mesa/tnl/t_vp_build.c,v retrieving revision 1.27 diff -u -r1.27 t_vp_build.c --- src/mesa/tnl/t_vp_build.c 16 Sep 2005 18:14:25 -0000 1.27 +++ src/mesa/tnl/t_vp_build.c 16 Sep 2005 21:00:24 -0000 @@ -326,9 +326,9 @@ static struct ureg get_temp( struct tnl_program *p ) { - int bit = ffs( ~p->temp_in_use ); + int bit = _mesa_ffs( ~p->temp_in_use ); if (!bit) { - fprintf(stderr, "%s: out of temporaries\n", __FILE__); + _mesa_problem(NULL, "%s: out of temporaries\n", __FILE__); exit(1); } Index: src/mesa/x86/common_x86.c =================================================================== RCS file: /cvs/mesa/Mesa/src/mesa/x86/common_x86.c,v retrieving revision 1.36 diff -u -r1.36 common_x86.c --- src/mesa/x86/common_x86.c 24 Jul 2005 06:29:16 -0000 1.36 +++ src/mesa/x86/common_x86.c 16 Sep 2005 21:00:26 -0000 @@ -71,7 +71,7 @@ } #endif if ( debug ) { - fprintf( stderr, "%s", msg ); + _mesa_debug( NULL, "%s", msg ); } }