[Mesa-dev] [PATCH 03/13] gallium/auxiliary: Use exp2(x) instead of pow(2.0, x).

Roland Scheidegger sroland at vmware.com
Mon Jul 13 17:13:06 PDT 2015


Did you replace 2 of them by exp2f but one by exp2f on purpose?

I don't think we can use exp2/exp2f in gallium. This requires msvc 2013
(all of exp2, exp2f, powf are c99, powf is supported by older msvc but
the others are not). I guess though could throw some wrappers into
c99_math.h.

Roland

Am 14.07.2015 um 01:22 schrieb Matt Turner:
> ---
>  src/gallium/auxiliary/util/u_format_rgb9e5.h | 6 +++---
>  src/gallium/auxiliary/util/u_math.c          | 2 +-
>  2 files changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/src/gallium/auxiliary/util/u_format_rgb9e5.h b/src/gallium/auxiliary/util/u_format_rgb9e5.h
> index c2a3f6f..7a01f7f 100644
> --- a/src/gallium/auxiliary/util/u_format_rgb9e5.h
> +++ b/src/gallium/auxiliary/util/u_format_rgb9e5.h
> @@ -115,8 +115,8 @@ static INLINE unsigned float3_to_rgb9e5(const float rgb[3])
>     exp_shared = MAX2(-RGB9E5_EXP_BIAS-1, rgb9e5_FloorLog2(maxrgb)) + 1 + RGB9E5_EXP_BIAS;
>     assert(exp_shared <= RGB9E5_MAX_VALID_BIASED_EXP);
>     assert(exp_shared >= 0);
> -   /* This pow function could be replaced by a table. */
> -   denom = pow(2, exp_shared - RGB9E5_EXP_BIAS - RGB9E5_MANTISSA_BITS);
> +   /* This exp2 function could be replaced by a table. */
> +   denom = exp2(exp_shared - RGB9E5_EXP_BIAS - RGB9E5_MANTISSA_BITS);
>  
>     maxm = (int) floor(maxrgb / denom + 0.5);
>     if (maxm == MAX_RGB9E5_MANTISSA+1) {
> @@ -154,7 +154,7 @@ static INLINE void rgb9e5_to_float3(unsigned rgb, float retval[3])
>  
>     v.raw = rgb;
>     exponent = v.field.biasedexponent - RGB9E5_EXP_BIAS - RGB9E5_MANTISSA_BITS;
> -   scale = (float) pow(2, exponent);
> +   scale = exp2f(exponent);
>  
>     retval[0] = v.field.r * scale;
>     retval[1] = v.field.g * scale;
> diff --git a/src/gallium/auxiliary/util/u_math.c b/src/gallium/auxiliary/util/u_math.c
> index ae9e951..c58af91 100644
> --- a/src/gallium/auxiliary/util/u_math.c
> +++ b/src/gallium/auxiliary/util/u_math.c
> @@ -48,7 +48,7 @@ init_pow2_table(void)
>  {
>     int i;
>     for (i = 0; i < POW2_TABLE_SIZE; i++)
> -      pow2_table[i] = (float) pow(2.0, (i - POW2_TABLE_OFFSET) / POW2_TABLE_SCALE);
> +      pow2_table[i] = exp2f((i - POW2_TABLE_OFFSET) / POW2_TABLE_SCALE);
>  }
>  
>  
> 



More information about the mesa-dev mailing list