[Mesa-dev] [PATCH 13/13] mesa: Avoid double promotion.

Iago Toral itoral at igalia.com
Tue Jul 14 04:45:17 PDT 2015


On Mon, 2015-07-13 at 16:22 -0700, Matt Turner wrote:
> ---
>  src/mesa/main/ffvertex_prog.c     | 10 +++++-----
>  src/mesa/main/fog.c               |  2 +-
>  src/mesa/main/get.c               |  2 +-
>  src/mesa/main/light.c             | 30 +++++++++++++++---------------
>  src/mesa/main/lines.c             |  4 ++--
>  src/mesa/main/multisample.c       |  4 ++--
>  src/mesa/main/pack.c              | 14 +++++++-------
>  src/mesa/main/pixel.c             |  4 ++--
>  src/mesa/main/pixeltransfer.c     |  8 ++++----
>  src/mesa/main/points.c            |  8 ++++----
>  src/mesa/main/readpix.c           |  4 ++--
>  src/mesa/main/samplerobj.c        |  2 +-
>  src/mesa/main/texparam.c          |  2 +-
>  src/mesa/swrast_setup/ss_tritmp.h |  4 ++--
>  14 files changed, 49 insertions(+), 49 deletions(-)
> 
> diff --git a/src/mesa/main/ffvertex_prog.c b/src/mesa/main/ffvertex_prog.c
> index 70adaf8..95b428d 100644
> --- a/src/mesa/main/ffvertex_prog.c
> +++ b/src/mesa/main/ffvertex_prog.c
> @@ -189,15 +189,15 @@ static void make_state_key( struct gl_context *ctx, struct state_key *key )
>  	 if (light->Enabled) {
>  	    key->unit[i].light_enabled = 1;
>  
> -	    if (light->EyePosition[3] == 0.0)
> +	    if (light->EyePosition[3] == 0.0F)
>  	       key->unit[i].light_eyepos3_is_zero = 1;
>  
> -	    if (light->SpotCutoff == 180.0)
> +	    if (light->SpotCutoff == 180.0F)
>  	       key->unit[i].light_spotcutoff_is_180 = 1;
>  
> -	    if (light->ConstantAttenuation != 1.0 ||
> -		light->LinearAttenuation != 0.0 ||
> -		light->QuadraticAttenuation != 0.0)
> +	    if (light->ConstantAttenuation != 1.0F ||
> +		light->LinearAttenuation != 0.0F ||
> +		light->QuadraticAttenuation != 0.0F)
>  	       key->unit[i].light_attenuated = 1;
>  	 }
>        }
> diff --git a/src/mesa/main/fog.c b/src/mesa/main/fog.c
> index 3bce289..45f343d 100644
> --- a/src/mesa/main/fog.c
> +++ b/src/mesa/main/fog.c
> @@ -115,7 +115,7 @@ _mesa_Fogfv( GLenum pname, const GLfloat *params )
>  	 ctx->Fog.Mode = m;
>  	 break;
>        case GL_FOG_DENSITY:
> -	 if (*params<0.0) {
> +	 if (*params<0.0F) {
>  	    _mesa_error( ctx, GL_INVALID_VALUE, "glFog" );
>              return;
>  	 }
> diff --git a/src/mesa/main/get.c b/src/mesa/main/get.c
> index 3d6d639..785a9b5 100644
> --- a/src/mesa/main/get.c
> +++ b/src/mesa/main/get.c
> @@ -626,7 +626,7 @@ find_custom_value(struct gl_context *ctx, const struct value_desc *d, union valu
>        break;
>  
>     case GL_EDGE_FLAG:
> -      v->value_bool = ctx->Current.Attrib[VERT_ATTRIB_EDGEFLAG][0] == 1.0;
> +      v->value_bool = ctx->Current.Attrib[VERT_ATTRIB_EDGEFLAG][0] == 1.0F;
>        break;
>  
>     case GL_READ_BUFFER:
> diff --git a/src/mesa/main/light.c b/src/mesa/main/light.c
> index 4021dbe..fe2ce8c 100644
> --- a/src/mesa/main/light.c
> +++ b/src/mesa/main/light.c
> @@ -143,7 +143,7 @@ _mesa_light(struct gl_context *ctx, GLuint lnum, GLenum pname, const GLfloat *pa
>        COPY_3V(light->SpotDirection, params);
>        break;
>     case GL_SPOT_EXPONENT:
> -      assert(params[0] >= 0.0);
> +      assert(params[0] >= 0.0F);
>        assert(params[0] <= ctx->Const.MaxSpotExponent);
>        if (light->SpotExponent == params[0])
>  	 return;
> @@ -151,12 +151,12 @@ _mesa_light(struct gl_context *ctx, GLuint lnum, GLenum pname, const GLfloat *pa
>        light->SpotExponent = params[0];
>        break;
>     case GL_SPOT_CUTOFF:
> -      assert(params[0] == 180.0 || (params[0] >= 0.0 && params[0] <= 90.0));
> +      assert(params[0] == 180.0F || (params[0] >= 0.0F && params[0] <= 90.0F));
>        if (light->SpotCutoff == params[0])
>           return;
>        FLUSH_VERTICES(ctx, _NEW_LIGHT);
>        light->SpotCutoff = params[0];
> -      light->_CosCutoff = (GLfloat) (cos(light->SpotCutoff * M_PI / 180.0));
> +      light->_CosCutoff = (cosf(light->SpotCutoff * M_PI / 180.0));

Same comment as in the previous patch: is there any gain here?

Other than this:
Reviewed-by: Iago Toral Quiroga <itoral at igalia.com>

>        if (light->_CosCutoff < 0)
>           light->_CosCutoff = 0;
>        if (light->SpotCutoff != 180.0F)
> @@ -165,21 +165,21 @@ _mesa_light(struct gl_context *ctx, GLuint lnum, GLenum pname, const GLfloat *pa
>           light->_Flags &= ~LIGHT_SPOT;
>        break;
>     case GL_CONSTANT_ATTENUATION:
> -      assert(params[0] >= 0.0);
> +      assert(params[0] >= 0.0F);
>        if (light->ConstantAttenuation == params[0])
>  	 return;
>        FLUSH_VERTICES(ctx, _NEW_LIGHT);
>        light->ConstantAttenuation = params[0];
>        break;
>     case GL_LINEAR_ATTENUATION:
> -      assert(params[0] >= 0.0);
> +      assert(params[0] >= 0.0F);
>        if (light->LinearAttenuation == params[0])
>  	 return;
>        FLUSH_VERTICES(ctx, _NEW_LIGHT);
>        light->LinearAttenuation = params[0];
>        break;
>     case GL_QUADRATIC_ATTENUATION:
> -      assert(params[0] >= 0.0);
> +      assert(params[0] >= 0.0F);
>        if (light->QuadraticAttenuation == params[0])
>  	 return;
>        FLUSH_VERTICES(ctx, _NEW_LIGHT);
> @@ -238,31 +238,31 @@ _mesa_Lightfv( GLenum light, GLenum pname, const GLfloat *params )
>        params = temp;
>        break;
>     case GL_SPOT_EXPONENT:
> -      if (params[0] < 0.0 || params[0] > ctx->Const.MaxSpotExponent) {
> +      if (params[0] < 0.0F || params[0] > ctx->Const.MaxSpotExponent) {
>  	 _mesa_error(ctx, GL_INVALID_VALUE, "glLight");
>  	 return;
>        }
>        break;
>     case GL_SPOT_CUTOFF:
> -      if ((params[0] < 0.0 || params[0] > 90.0) && params[0] != 180.0) {
> +      if ((params[0] < 0.0F || params[0] > 90.0F) && params[0] != 180.0F) {
>  	 _mesa_error(ctx, GL_INVALID_VALUE, "glLight");
>  	 return;
>        }
>        break;
>     case GL_CONSTANT_ATTENUATION:
> -      if (params[0] < 0.0) {
> +      if (params[0] < 0.0F) {
>  	 _mesa_error(ctx, GL_INVALID_VALUE, "glLight");
>  	 return;
>        }
>        break;
>     case GL_LINEAR_ATTENUATION:
> -      if (params[0] < 0.0) {
> +      if (params[0] < 0.0F) {
>  	 _mesa_error(ctx, GL_INVALID_VALUE, "glLight");
>  	 return;
>        }
>        break;
>     case GL_QUADRATIC_ATTENUATION:
> -      if (params[0] < 0.0) {
> +      if (params[0] < 0.0F) {
>  	 _mesa_error(ctx, GL_INVALID_VALUE, "glLight");
>  	 return;
>        }
> @@ -463,14 +463,14 @@ _mesa_LightModelfv( GLenum pname, const GLfloat *params )
>        case GL_LIGHT_MODEL_LOCAL_VIEWER:
>           if (ctx->API != API_OPENGL_COMPAT)
>              goto invalid_pname;
> -         newbool = (params[0]!=0.0);
> +         newbool = (params[0] != 0.0F);
>  	 if (ctx->Light.Model.LocalViewer == newbool)
>  	    return;
>  	 FLUSH_VERTICES(ctx, _NEW_LIGHT);
>  	 ctx->Light.Model.LocalViewer = newbool;
>           break;
>        case GL_LIGHT_MODEL_TWO_SIDE:
> -         newbool = (params[0]!=0.0);
> +         newbool = (params[0] != 0.0F);
>  	 if (ctx->Light.Model.TwoSide == newbool)
>  	    return;
>  	 FLUSH_VERTICES(ctx, _NEW_LIGHT);
> @@ -975,7 +975,7 @@ compute_light_positions( struct gl_context *ctx )
>        }
>        else {
>           /* positional light w/ homogeneous coordinate, divide by W */
> -         GLfloat wInv = (GLfloat)1.0 / light->_Position[3];
> +         GLfloat wInv = 1.0F / light->_Position[3];
>           light->_Position[0] *= wInv;
>           light->_Position[1] *= wInv;
>           light->_Position[2] *= wInv;
> @@ -1024,7 +1024,7 @@ update_modelview_scale( struct gl_context *ctx )
>     if (!_math_matrix_is_length_preserving(ctx->ModelviewMatrixStack.Top)) {
>        const GLfloat *m = ctx->ModelviewMatrixStack.Top->inv;
>        GLfloat f = m[2] * m[2] + m[6] * m[6] + m[10] * m[10];
> -      if (f < 1e-12) f = 1.0;
> +      if (f < 1e-12f) f = 1.0f;
>        if (ctx->_NeedEyeCoords)
>  	 ctx->_ModelViewInvScale = 1.0f / sqrtf(f);
>        else
> diff --git a/src/mesa/main/lines.c b/src/mesa/main/lines.c
> index 3c08ed2..c020fb3 100644
> --- a/src/mesa/main/lines.c
> +++ b/src/mesa/main/lines.c
> @@ -45,7 +45,7 @@ _mesa_LineWidth( GLfloat width )
>     if (MESA_VERBOSE & VERBOSE_API)
>        _mesa_debug(ctx, "glLineWidth %f\n", width);
>  
> -   if (width<=0.0) {
> +   if (width <= 0.0F) {
>        _mesa_error( ctx, GL_INVALID_VALUE, "glLineWidth" );
>        return;
>     }
> @@ -63,7 +63,7 @@ _mesa_LineWidth( GLfloat width )
>     if (ctx->API == API_OPENGL_CORE
>         && ((ctx->Const.ContextFlags & GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT)
>             != 0)
> -       && width > 1.0) {
> +       && width > 1.0F) {
>        _mesa_error( ctx, GL_INVALID_VALUE, "glLineWidth" );
>        return;
>     }
> diff --git a/src/mesa/main/multisample.c b/src/mesa/main/multisample.c
> index 816837b..490bad5 100644
> --- a/src/mesa/main/multisample.c
> +++ b/src/mesa/main/multisample.c
> @@ -43,7 +43,7 @@ _mesa_SampleCoverage(GLclampf value, GLboolean invert)
>  
>     FLUSH_VERTICES(ctx, 0);
>  
> -   ctx->Multisample.SampleCoverageValue = (GLfloat) CLAMP(value, 0.0, 1.0);
> +   ctx->Multisample.SampleCoverageValue = CLAMP(value, 0.0f, 1.0f);
>     ctx->Multisample.SampleCoverageInvert = invert;
>     ctx->NewState |= _NEW_MULTISAMPLE;
>  }
> @@ -134,7 +134,7 @@ _mesa_MinSampleShading(GLclampf value)
>  
>     FLUSH_VERTICES(ctx, 0);
>  
> -   ctx->Multisample.MinSampleShadingValue = CLAMP(value, 0.0, 1.0);
> +   ctx->Multisample.MinSampleShadingValue = CLAMP(value, 0.0f, 1.0f);
>     ctx->NewState |= _NEW_MULTISAMPLE;
>  }
>  
> diff --git a/src/mesa/main/pack.c b/src/mesa/main/pack.c
> index f723608..fb642b8 100644
> --- a/src/mesa/main/pack.c
> +++ b/src/mesa/main/pack.c
> @@ -796,7 +796,7 @@ _mesa_unpack_depth_span( struct gl_context *ctx, GLuint n,
>      * back to an int type can introduce errors that will show up as
>      * artifacts in things like depth peeling which uses glCopyTexImage.
>      */
> -   if (ctx->Pixel.DepthScale == 1.0 && ctx->Pixel.DepthBias == 0.0) {
> +   if (ctx->Pixel.DepthScale == 1.0F && ctx->Pixel.DepthBias == 0.0F) {
>        if (srcType == GL_UNSIGNED_INT && dstType == GL_UNSIGNED_SHORT) {
>           const GLuint *src = (const GLuint *) source;
>           GLushort *dst = (GLushort *) dest;
> @@ -874,8 +874,8 @@ _mesa_unpack_depth_span( struct gl_context *ctx, GLuint n,
>        case GL_UNSIGNED_INT_24_8_EXT: /* GL_EXT_packed_depth_stencil */
>           if (dstType == GL_UNSIGNED_INT_24_8_EXT &&
>               depthMax == 0xffffff &&
> -             ctx->Pixel.DepthScale == 1.0 &&
> -             ctx->Pixel.DepthBias == 0.0) {
> +             ctx->Pixel.DepthScale == 1.0F &&
> +             ctx->Pixel.DepthBias == 0.0F) {
>              const GLuint *src = (const GLuint *) source;
>              GLuint *zValues = (GLuint *) dest;
>              GLuint i;
> @@ -945,7 +945,7 @@ _mesa_unpack_depth_span( struct gl_context *ctx, GLuint n,
>     {
>        const GLfloat scale = ctx->Pixel.DepthScale;
>        const GLfloat bias = ctx->Pixel.DepthBias;
> -      if (scale != 1.0 || bias != 0.0) {
> +      if (scale != 1.0F || bias != 0.0F) {
>           GLuint i;
>           for (i = 0; i < n; i++) {
>              depthValues[i] = depthValues[i] * scale + bias;
> @@ -958,7 +958,7 @@ _mesa_unpack_depth_span( struct gl_context *ctx, GLuint n,
>     if (needClamp) {
>        GLuint i;
>        for (i = 0; i < n; i++) {
> -         depthValues[i] = (GLfloat)CLAMP(depthValues[i], 0.0, 1.0);
> +         depthValues[i] = CLAMP(depthValues[i], 0.0F, 1.0F);
>        }
>     }
>  
> @@ -1025,7 +1025,7 @@ _mesa_pack_depth_span( struct gl_context *ctx, GLuint n, GLvoid *dest,
>        return;
>     }
>  
> -   if (ctx->Pixel.DepthScale != 1.0 || ctx->Pixel.DepthBias != 0.0) {
> +   if (ctx->Pixel.DepthScale != 1.0F || ctx->Pixel.DepthBias != 0.0F) {
>        memcpy(depthCopy, depthSpan, n * sizeof(GLfloat));
>        _mesa_scale_and_bias_depth(ctx, n, depthCopy);
>        depthSpan = depthCopy;
> @@ -1153,7 +1153,7 @@ _mesa_pack_depth_stencil_span(struct gl_context *ctx,GLuint n,
>        return;
>     }
>  
> -   if (ctx->Pixel.DepthScale != 1.0 || ctx->Pixel.DepthBias != 0.0) {
> +   if (ctx->Pixel.DepthScale != 1.0F || ctx->Pixel.DepthBias != 0.0F) {
>        memcpy(depthCopy, depthVals, n * sizeof(GLfloat));
>        _mesa_scale_and_bias_depth(ctx, n, depthCopy);
>        depthVals = depthCopy;
> diff --git a/src/mesa/main/pixel.c b/src/mesa/main/pixel.c
> index ecda269..608a545 100644
> --- a/src/mesa/main/pixel.c
> +++ b/src/mesa/main/pixel.c
> @@ -455,12 +455,12 @@ _mesa_GetnPixelMapusvARB( GLenum map, GLsizei bufSize, GLushort *values )
>     /* special cases */
>     case GL_PIXEL_MAP_I_TO_I:
>        for (i = 0; i < mapsize; i++) {
> -         values[i] = (GLushort) CLAMP(ctx->PixelMaps.ItoI.Map[i], 0.0, 65535.);
> +         values[i] = (GLushort) CLAMP(ctx->PixelMaps.ItoI.Map[i], 0.0F, 65535.0F);
>        }
>        break;
>     case GL_PIXEL_MAP_S_TO_S:
>        for (i = 0; i < mapsize; i++) {
> -         values[i] = (GLushort) CLAMP(ctx->PixelMaps.StoS.Map[i], 0.0, 65535.);
> +         values[i] = (GLushort) CLAMP(ctx->PixelMaps.StoS.Map[i], 0.0F, 65535.0F);
>        }
>        break;
>     default:
> diff --git a/src/mesa/main/pixeltransfer.c b/src/mesa/main/pixeltransfer.c
> index 94464ea..51f2ebf 100644
> --- a/src/mesa/main/pixeltransfer.c
> +++ b/src/mesa/main/pixeltransfer.c
> @@ -47,25 +47,25 @@ _mesa_scale_and_bias_rgba(GLuint n, GLfloat rgba[][4],
>                            GLfloat rBias, GLfloat gBias,
>                            GLfloat bBias, GLfloat aBias)
>  {
> -   if (rScale != 1.0 || rBias != 0.0) {
> +   if (rScale != 1.0F || rBias != 0.0F) {
>        GLuint i;
>        for (i = 0; i < n; i++) {
>           rgba[i][RCOMP] = rgba[i][RCOMP] * rScale + rBias;
>        }
>     }
> -   if (gScale != 1.0 || gBias != 0.0) {
> +   if (gScale != 1.0F || gBias != 0.0F) {
>        GLuint i;
>        for (i = 0; i < n; i++) {
>           rgba[i][GCOMP] = rgba[i][GCOMP] * gScale + gBias;
>        }
>     }
> -   if (bScale != 1.0 || bBias != 0.0) {
> +   if (bScale != 1.0F || bBias != 0.0F) {
>        GLuint i;
>        for (i = 0; i < n; i++) {
>           rgba[i][BCOMP] = rgba[i][BCOMP] * bScale + bBias;
>        }
>     }
> -   if (aScale != 1.0 || aBias != 0.0) {
> +   if (aScale != 1.0F || aBias != 0.0F) {
>        GLuint i;
>        for (i = 0; i < n; i++) {
>           rgba[i][ACOMP] = rgba[i][ACOMP] * aScale + aBias;
> diff --git a/src/mesa/main/points.c b/src/mesa/main/points.c
> index 5ad1f38..863e3c1 100644
> --- a/src/mesa/main/points.c
> +++ b/src/mesa/main/points.c
> @@ -45,7 +45,7 @@ _mesa_PointSize( GLfloat size )
>  {
>     GET_CURRENT_CONTEXT(ctx);
>  
> -   if (size <= 0.0) {
> +   if (size <= 0.0F) {
>        _mesa_error( ctx, GL_INVALID_VALUE, "glPointSize" );
>        return;
>     }
> @@ -119,9 +119,9 @@ _mesa_PointParameterfv( GLenum pname, const GLfloat *params)
>              return;
>           FLUSH_VERTICES(ctx, _NEW_POINT);
>           COPY_3V(ctx->Point.Params, params);
> -         ctx->Point._Attenuated = (ctx->Point.Params[0] != 1.0 ||
> -                                   ctx->Point.Params[1] != 0.0 ||
> -                                   ctx->Point.Params[2] != 0.0);
> +         ctx->Point._Attenuated = (ctx->Point.Params[0] != 1.0F ||
> +                                   ctx->Point.Params[1] != 0.0F ||
> +                                   ctx->Point.Params[2] != 0.0F);
>           break;
>        case GL_POINT_SIZE_MIN_EXT:
>           if (params[0] < 0.0F) {
> diff --git a/src/mesa/main/readpix.c b/src/mesa/main/readpix.c
> index e256695..160f711 100644
> --- a/src/mesa/main/readpix.c
> +++ b/src/mesa/main/readpix.c
> @@ -247,7 +247,7 @@ read_uint_depth_pixels( struct gl_context *ctx,
>     GLubyte *map, *dst;
>     int stride, dstStride, j;
>  
> -   if (ctx->Pixel.DepthScale != 1.0 || ctx->Pixel.DepthBias != 0.0)
> +   if (ctx->Pixel.DepthScale != 1.0F || ctx->Pixel.DepthBias != 0.0F)
>        return GL_FALSE;
>  
>     if (packing->SwapBytes)
> @@ -799,7 +799,7 @@ read_depth_stencil_pixels(struct gl_context *ctx,
>                            const struct gl_pixelstore_attrib *packing )
>  {
>     const GLboolean scaleOrBias
> -      = ctx->Pixel.DepthScale != 1.0 || ctx->Pixel.DepthBias != 0.0;
> +      = ctx->Pixel.DepthScale != 1.0F || ctx->Pixel.DepthBias != 0.0F;
>     const GLboolean stencilTransfer = ctx->Pixel.IndexShift
>        || ctx->Pixel.IndexOffset || ctx->Pixel.MapStencilFlag;
>     GLubyte *dst;
> diff --git a/src/mesa/main/samplerobj.c b/src/mesa/main/samplerobj.c
> index a3aacc6..5bb09da 100644
> --- a/src/mesa/main/samplerobj.c
> +++ b/src/mesa/main/samplerobj.c
> @@ -689,7 +689,7 @@ set_sampler_max_anisotropy(struct gl_context *ctx,
>     if (samp->MaxAnisotropy == param)
>        return GL_FALSE;
>  
> -   if (param < 1.0)
> +   if (param < 1.0F)
>        return INVALID_VALUE;
>  
>     flush(ctx);
> diff --git a/src/mesa/main/texparam.c b/src/mesa/main/texparam.c
> index d74134f..03d0168 100644
> --- a/src/mesa/main/texparam.c
> +++ b/src/mesa/main/texparam.c
> @@ -683,7 +683,7 @@ set_tex_parameterf(struct gl_context *ctx,
>  
>           if (texObj->Sampler.MaxAnisotropy == params[0])
>              return GL_FALSE;
> -         if (params[0] < 1.0) {
> +         if (params[0] < 1.0F) {
>              _mesa_error(ctx, GL_INVALID_VALUE, "glTex%sParameter(param)",
>                          suffix);
>              return GL_FALSE;
> diff --git a/src/mesa/swrast_setup/ss_tritmp.h b/src/mesa/swrast_setup/ss_tritmp.h
> index c38c76a..adb77bd 100644
> --- a/src/mesa/swrast_setup/ss_tritmp.h
> +++ b/src/mesa/swrast_setup/ss_tritmp.h
> @@ -58,7 +58,7 @@ static void TAG(triangle)(struct gl_context *ctx, GLuint e0, GLuint e1, GLuint e
>  
>        if (IND & (SS_TWOSIDE_BIT | SS_UNFILLED_BIT))
>        {
> -	 facing = (cc < 0.0) ^ ctx->Polygon._FrontBit;
> +	 facing = (cc < 0.0F) ^ ctx->Polygon._FrontBit;
>  
>  	 if (IND & SS_UNFILLED_BIT)
>  	    mode = facing ? ctx->Polygon.BackMode : ctx->Polygon.FrontMode;
> @@ -138,7 +138,7 @@ static void TAG(triangle)(struct gl_context *ctx, GLuint e0, GLuint e1, GLuint e
>            * so no MRD value is used here.
>            */
>  	 offset = ctx->Polygon.OffsetUnits;
> -	 if (cc * cc > 1e-16) {
> +	 if (cc * cc > 1e-16F) {
>  	    const GLfloat ez = z[0] - z[2];
>  	    const GLfloat fz = z[1] - z[2];
>  	    const GLfloat oneOverArea = 1.0F / cc;




More information about the mesa-dev mailing list