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

Matt Turner mattst88 at gmail.com
Wed Jul 15 12:59:21 PDT 2015


On Tue, Jul 14, 2015 at 4:45 AM, Iago Toral <itoral at igalia.com> wrote:
> On Mon, 2015-07-13 at 16:22 -0700, Matt Turner wrote:
>>     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?

I think so -- I expect cosf() is faster than cos(). In essence, we're
moving the double -> float conversion from the function's result to
the function's argument, allowing us to call a cheaper function.

We additionally might want to cast (M_PI / 180.0) to float. I'm not
sure. I'll do some tests.

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

Thanks.


More information about the mesa-dev mailing list