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

Roland Scheidegger sroland at vmware.com
Mon Aug 10 07:29:35 PDT 2015


Am 10.08.2015 um 07:03 schrieb Jason Ekstrand:
> This better ensures that the src_bits == dst_bits case gets optimized away.
> ---
>  src/mesa/main/format_utils.h | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/src/mesa/main/format_utils.h b/src/mesa/main/format_utils.h
> index 00ec777..65314e6 100644
> --- a/src/mesa/main/format_utils.h
> +++ b/src/mesa/main/format_utils.h
> @@ -99,7 +99,7 @@ _mesa_unorm_to_unorm(unsigned x, unsigned src_bits, unsigned dst_bits)
>  {
>     if (src_bits < dst_bits) {
>        return EXTEND_NORMALIZED_INT(x, src_bits, dst_bits);
> -   } else {
> +   } else if (src_bits > dst_bits) {
>        unsigned src_half = (1 << (src_bits - 1)) - 1;
>  
>        if (src_bits + dst_bits > sizeof(x) * 8) {
> @@ -109,6 +109,8 @@ _mesa_unorm_to_unorm(unsigned x, unsigned src_bits, unsigned dst_bits)
>        } else {
>           return (x * MAX_UINT(dst_bits) + src_half) / MAX_UINT(src_bits);
>        }
> +   } else {
> +      return x;
>     }
>  }
>  
> @@ -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;
>  }
>  
>  static inline unsigned
> 

Reviewed-by: Roland Scheidegger <sroland at vmware.com>

(I don't care either way for the snorm case).

Roland



More information about the mesa-dev mailing list