[Mesa-dev] [PATCH] mesa/format_utils: Add src_bits == dst_bits cases to [us]norm functions

Jason Ekstrand jason at jlekstrand.net
Mon Aug 10 11:09:14 PDT 2015


On Mon, Aug 10, 2015 at 4:35 AM, Neil Roberts <neil at linux.intel.com> wrote:
> Jason Ekstrand <jason at jlekstrand.net> writes:
>
>> @@ -151,8 +153,10 @@ _mesa_snorm_to_snorm(int x, unsigned src_bits, unsigned dst_bits)
>>        return -MAX_INT(dst_bits);
>>     else if (src_bits < dst_bits)
>>        return EXTEND_NORMALIZED_INT(x, src_bits - 1, dst_bits - 1);
>> -   else
>> +   else if (src_bits > dst_bits)
>>        return x >> (src_bits - dst_bits);
>> +   else
>> +      return x;
>>  }
>
> This part seems pretty unnecessary as it seems pretty unlikely that a
> compiler couldn't optimise away x >> 0. However I'm happy if you want to
> land it anyway for consistency.

You're right.  I probably shouldn't worry about x >> 0.

> If you wanted to optimise it a bit more you could move the
> if(src_bits==dst_bits) to above the first if statement because I think
> it would be tricky the for the compiler to optimise that away.

That's not quite right. The first if statement is to "sanitize" the
value.  For an 8-bit snorm, they could pass in -128 which is slightly
less than -1.0 and we want them to get -127 (-1.0) back out.

> Either way,
>
> Reviewed-by: Neil Roberts <neil at linux.intel.com>

Thanks!

>
> Regards,
> - Neil


More information about the mesa-dev mailing list