From: Brian Paul Date: Mon, 3 Sep 2012 18:19:15 +0000 (-0600) Subject: mesa: remove SQRTF, use sqrtf. Convert INV_SQRT() to inline function. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=56ccdf7e30f5bc1bc6b71d49bad2a9049ae170c4;p=mesa.git mesa: remove SQRTF, use sqrtf. Convert INV_SQRT() to inline function. We were already defining sqrtf where we don't have the C99 version. Reviewed-by: Kenneth Graunke Reviewed-by: Matt Turner --- diff --git a/src/mesa/main/imports.h b/src/mesa/main/imports.h index 60b0f11af86..abf216c99ac 100644 --- a/src/mesa/main/imports.h +++ b/src/mesa/main/imports.h @@ -96,18 +96,6 @@ typedef union { GLfloat f; GLint i; } fi_type; #define DEG2RAD (M_PI/180.0) -/*** - *** SQRTF: single-precision square root - ***/ -#define SQRTF(X) (float) sqrt((float) (X)) - - -/*** - *** INV_SQRTF: single-precision inverse square root - ***/ -#define INV_SQRTF(X) (1.0F / SQRTF(X)) - - /** * \name Work-arounds for platforms that lack C99 math functions */ @@ -157,6 +145,16 @@ static inline int isblank(int ch) { return ch == ' ' || ch == '\t'; } /*@}*/ + +/** single-precision inverse square root */ +static inline float +INV_SQRTF(float x) +{ + /* XXX we could try Quake's fast inverse square root function here */ + return 1.0F / sqrtf(x); +} + + /*** *** LOG2: Log base 2 of float ***/ diff --git a/src/mesa/main/light.c b/src/mesa/main/light.c index cfb53dc061c..042ed1cb858 100644 --- a/src/mesa/main/light.c +++ b/src/mesa/main/light.c @@ -1038,7 +1038,7 @@ update_modelview_scale( struct gl_context *ctx ) if (ctx->_NeedEyeCoords) ctx->_ModelViewInvScale = (GLfloat) INV_SQRTF(f); else - ctx->_ModelViewInvScale = (GLfloat) SQRTF(f); + ctx->_ModelViewInvScale = (GLfloat) sqrtf(f); } } diff --git a/src/mesa/main/macros.h b/src/mesa/main/macros.h index 7d0a375d138..fc6f2a28f20 100644 --- a/src/mesa/main/macros.h +++ b/src/mesa/main/macros.h @@ -665,13 +665,13 @@ LEN_SQUARED_2FV(const GLfloat v[2]) static inline GLfloat LEN_3FV(const GLfloat v[3]) { - return SQRTF(LEN_SQUARED_3FV(v)); + return sqrtf(LEN_SQUARED_3FV(v)); } static inline GLfloat LEN_2FV(const GLfloat v[2]) { - return SQRTF(LEN_SQUARED_2FV(v)); + return sqrtf(LEN_SQUARED_2FV(v)); } diff --git a/src/mesa/math/m_matrix.c b/src/mesa/math/m_matrix.c index 00a6c814fe3..b9f22d796b7 100644 --- a/src/mesa/math/m_matrix.c +++ b/src/mesa/math/m_matrix.c @@ -856,7 +856,7 @@ _math_matrix_rotate( GLmatrix *mat, } if (!optimized) { - const GLfloat mag = SQRTF(x * x + y * y + z * z); + const GLfloat mag = sqrtf(x * x + y * y + z * z); if (mag <= 1.0e-4) { /* no rotation, leave mat as-is */ diff --git a/src/mesa/swrast/s_aalinetemp.h b/src/mesa/swrast/s_aalinetemp.h index a517fb69732..6cfd3bc28a4 100644 --- a/src/mesa/swrast/s_aalinetemp.h +++ b/src/mesa/swrast/s_aalinetemp.h @@ -118,7 +118,7 @@ NAME(line)(struct gl_context *ctx, const SWvertex *v0, const SWvertex *v1) line.y1 = v1->attrib[FRAG_ATTRIB_WPOS][1]; line.dx = line.x1 - line.x0; line.dy = line.y1 - line.y0; - line.len = SQRTF(line.dx * line.dx + line.dy * line.dy); + line.len = sqrtf(line.dx * line.dx + line.dy * line.dy); line.halfWidth = 0.5F * CLAMP(ctx->Line.Width, ctx->Const.MinLineWidthAA, ctx->Const.MaxLineWidthAA); diff --git a/src/mesa/swrast/s_span.c b/src/mesa/swrast/s_span.c index ef51479fdcf..ff653a62257 100644 --- a/src/mesa/swrast/s_span.c +++ b/src/mesa/swrast/s_span.c @@ -419,8 +419,8 @@ _swrast_compute_lambda(GLfloat dsdx, GLfloat dsdy, GLfloat dtdx, GLfloat dtdy, GLfloat dvdx = texH * ((t + dtdx) / (q + dqdx) - t * invQ); GLfloat dudy = texW * ((s + dsdy) / (q + dqdy) - s * invQ); GLfloat dvdy = texH * ((t + dtdy) / (q + dqdy) - t * invQ); - GLfloat x = SQRTF(dudx * dudx + dvdx * dvdx); - GLfloat y = SQRTF(dudy * dudy + dvdy * dvdy); + GLfloat x = sqrtf(dudx * dudx + dvdx * dvdx); + GLfloat y = sqrtf(dudy * dudy + dvdy * dvdy); GLfloat rho = MAX2(x, y); GLfloat lambda = LOG2(rho); return lambda; diff --git a/src/mesa/swrast/s_texfilter.c b/src/mesa/swrast/s_texfilter.c index d116a059dca..152b1ff3efa 100644 --- a/src/mesa/swrast/s_texfilter.c +++ b/src/mesa/swrast/s_texfilter.c @@ -1795,12 +1795,12 @@ sample_2d_footprint(struct gl_context *ctx, /* Calculate the per anisotropic sample offsets in s,t space. */ if (Px2 > Py2) { - numSamples = ceil(SQRTF(Px2)); + numSamples = ceil(sqrtf(Px2)); ds = ux / ((GLfloat) img->Width2); dt = vx / ((GLfloat) img->Height2); } else { - numSamples = ceil(SQRTF(Py2)); + numSamples = ceil(sqrtf(Py2)); ds = uy / ((GLfloat) img->Width2); dt = vy / ((GLfloat) img->Height2); } diff --git a/src/mesa/tnl/t_rasterpos.c b/src/mesa/tnl/t_rasterpos.c index a28ad0daf80..1673b81ef99 100644 --- a/src/mesa/tnl/t_rasterpos.c +++ b/src/mesa/tnl/t_rasterpos.c @@ -429,7 +429,7 @@ _tnl_RasterPos(struct gl_context *ctx, const GLfloat vObj[4]) ctx->Current.RasterDistance = ctx->Current.Attrib[VERT_ATTRIB_FOG][0]; else ctx->Current.RasterDistance = - SQRTF( eye[0]*eye[0] + eye[1]*eye[1] + eye[2]*eye[2] ); + sqrtf( eye[0]*eye[0] + eye[1]*eye[1] + eye[2]*eye[2] ); /* compute transformed normal vector (for lighting or texgen) */ if (ctx->_NeedEyeCoords) {