Mesa (master): i965/vec4: Emit MADs from (x + -(y * z)).

Matt Turner mattst88 at kemper.freedesktop.org
Wed Feb 11 01:50:19 UTC 2015


Module: Mesa
Branch: master
Commit: 3d581f99963dea7e93a2f8fd819410da02c1cb7f
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=3d581f99963dea7e93a2f8fd819410da02c1cb7f

Author: Matt Turner <mattst88 at gmail.com>
Date:   Fri Dec 19 21:35:56 2014 -0800

i965/vec4: Emit MADs from (x + -(y * z)).

Same as commit c4fab711 to the fs backend.

total instructions in shared programs: 5945998 -> 5945788 (-0.00%)
instructions in affected programs:     74665 -> 74455 (-0.28%)
helped:                                399
HURT:                                  180

It hurts some programs because we make no attempts in the vec4 backend
to avoid MADs if they have constant (or vector uniform) arguments.

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

---

 src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp |   12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp b/src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp
index 432c218..2a988d0 100644
--- a/src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp
+++ b/src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp
@@ -1161,10 +1161,21 @@ vec4_visitor::try_emit_mad(ir_expression *ir)
    ir_rvalue *nonmul = ir->operands[1];
    ir_expression *mul = ir->operands[0]->as_expression();
 
+   bool mul_negate = false;
+   if (mul && mul->operation == ir_unop_neg) {
+      mul = mul->operands[0]->as_expression();
+      mul_negate = true;
+   }
+
    if (!mul || mul->operation != ir_binop_mul) {
       nonmul = ir->operands[0];
       mul = ir->operands[1]->as_expression();
 
+      if (mul && mul->operation == ir_unop_neg) {
+         mul = mul->operands[0]->as_expression();
+         mul_negate = true;
+      }
+
       if (!mul || mul->operation != ir_binop_mul)
          return false;
    }
@@ -1174,6 +1185,7 @@ vec4_visitor::try_emit_mad(ir_expression *ir)
 
    mul->operands[0]->accept(this);
    src_reg src1 = fix_3src_operand(this->result);
+   src1.negate ^= mul_negate;
 
    mul->operands[1]->accept(this);
    src_reg src2 = fix_3src_operand(this->result);




More information about the mesa-commit mailing list