[Mesa-dev] [PATCH 06/16] glsl: Add sin, cos and sign to get_range

Ian Romanick idr at freedesktop.org
Wed Nov 19 10:43:44 PST 2014


On 11/16/2014 05:51 PM, Thomas Helland wrote:
> They are bound between -1 and 1, so report that.
> ---
>  src/glsl/opt_minmax.cpp | 13 +++++++++++++
>  1 file changed, 13 insertions(+)
> 
> diff --git a/src/glsl/opt_minmax.cpp b/src/glsl/opt_minmax.cpp
> index 111d183..341006e 100644
> --- a/src/glsl/opt_minmax.cpp
> +++ b/src/glsl/opt_minmax.cpp
> @@ -271,6 +271,10 @@ get_range(ir_rvalue *rval)
>     minmax_range r0;
>     minmax_range r1;
>  
> +   void *mem_ctx = ralloc_parent(rval);

I would constify this (as 'void *const mem_ctx') to avoid accidental,
unintentional assignments from being added later.  We use mem_ctx a lot
as a name, and this has happened before with nested scopes.  I know
others on the project may not agree with me here...

> +   ir_constant *low = NULL;
> +   ir_constant *high = NULL;
> +
>     if(expr) {
>        switch(expr->operation) {
>        case ir_binop_min:
> @@ -279,6 +283,15 @@ get_range(ir_rvalue *rval)
>           r1 = get_range(expr->operands[1]);
>           return combine_range(r0, r1, expr->operation == ir_binop_min);
>  
> +      case ir_unop_sin:
> +      case ir_unop_sin_reduced:
> +      case ir_unop_cos:
> +      case ir_unop_cos_reduced:
> +      case ir_unop_sign:
> +         high = new(mem_ctx) ir_constant(1.0f);
> +         low = new(mem_ctx) ir_constant(-1.0f);
> +         return minmax_range(low, high);
> +

Why not just

    return minmax_range(new(mem_ctx) ir_constant(1.0f),
                        new(mem_ctx) ir_constant(-1.0f));

>        default:
>           break;
>        }
> 



More information about the mesa-dev mailing list