[Mesa-dev] [PATCH 5/5] glsl: Recognize open-coded pow(x, y).

Kenneth Graunke kenneth at whitecape.org
Wed Sep 24 23:09:13 PDT 2014


On Monday, September 08, 2014 12:21:44 PM Matt Turner wrote:
> pow(x, y) is equivalent to exp(log(x) * y).
> 
> instructions in affected programs:     578 -> 458 (-20.76%)

Impressive stats!

> ---
>  src/glsl/opt_algebraic.cpp | 14 ++++++++++++++
>  1 file changed, 14 insertions(+)
> 
> diff --git a/src/glsl/opt_algebraic.cpp b/src/glsl/opt_algebraic.cpp
> index 447618f..0cdb8ec 100644
> --- a/src/glsl/opt_algebraic.cpp
> +++ b/src/glsl/opt_algebraic.cpp
> @@ -357,6 +357,20 @@ ir_algebraic_visitor::handle_expression(ir_expression *ir)
>        if (op_expr[0]->operation == ir_unop_log2) {
>           return op_expr[0]->operands[0];
>        }
> +
> +      if (!options->EmitNoPow && op_expr[0]->operation == ir_binop_mul) {
> +         for (int log2_pos = 0; log2_pos < 2; log2_pos++) {
> +            ir_expression *log2_expr =
> +               op_expr[0]->operands[log2_pos]->as_expression();
> +
> +            if (log2_expr && log2_expr->operation == ir_unop_log2) {
> +               return new(mem_ctx) ir_expression(ir_binop_pow,
> +                                                 ir->type,
> +                                                 log2_expr->operands[0],
> +                                                 op_expr[0]->operands[1 - log2_pos]);

We have ir_builder in this file now, so maybe just:

return pow(log2_expr->operands[0], op_expr[0]->operands[1 - log2_pos]);

Either way,
Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>

> +            }
> +         }
> +      }
>        break;
>  
>     case ir_unop_log2:
> 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.freedesktop.org/archives/mesa-dev/attachments/20140924/b60849dc/attachment.sig>


More information about the mesa-dev mailing list