[Mesa-dev] [PATCH 5/5] i965: Emit MUL with a negated src for neg(mul(...)).

Ian Romanick idr at freedesktop.org
Wed Apr 8 16:38:31 PDT 2015


From: Matt Turner <mattst88 at gmail.com>

Shader-db results:

GM45:
total instructions in shared programs: 4060151 -> 4059575 (-0.01%)
instructions in affected programs:     81478 -> 80902 (-0.71%)
helped:                                441
HURT:                                  4

GM45 NIR:
total instructions in shared programs: 4079065 -> 4078671 (-0.01%)
instructions in affected programs:     67196 -> 66802 (-0.59%)
helped:                                398
HURT:                                  4

Iron Lake:
total instructions in shared programs: 5477330 -> 5476586 (-0.01%)
instructions in affected programs:     92444 -> 91700 (-0.80%)
helped:                                472
HURT:                                  4

Iron Lake NIR:
total instructions in shared programs: 5675880 -> 5675486 (-0.01%)
instructions in affected programs:     67196 -> 66802 (-0.59%)
helped:                                398
HURT:                                  4

Sandy Bridge:
total instructions in shared programs: 7307710 -> 7305083 (-0.04%)
instructions in affected programs:     282903 -> 280276 (-0.93%)
helped:                                1506

Sandy Bridge NIR:
total instructions in shared programs: 7329198 -> 7328404 (-0.01%)
instructions in affected programs:     133777 -> 132983 (-0.59%)
helped:                                682

Ivy Bridge:
total instructions in shared programs: 6763747 -> 6763036 (-0.01%)
instructions in affected programs:     79009 -> 78298 (-0.90%)
helped:                                573

Ivy Bridge NIR:
total instructions in shared programs: 6765185 -> 6764738 (-0.01%)
instructions in affected programs:     61743 -> 61296 (-0.72%)
helped:                                445

Haswell:
total instructions in shared programs: 6223429 -> 6222718 (-0.01%)
instructions in affected programs:     77427 -> 76716 (-0.92%)
helped:                                573

Haswell NIR:
total instructions in shared programs: 6180970 -> 6180523 (-0.01%)
instructions in affected programs:     61743 -> 61296 (-0.72%)
helped:                                445

Broadwell:
total instructions in shared programs: 7284540 -> 7284103 (-0.01%)
instructions in affected programs:     31526 -> 31089 (-1.39%)
helped:                                251

Broadwell NIR:
total instructions in shared programs: 7500487 -> 7500487 (0.00%)
instructions in affected programs:     0 -> 0

Reviewed-by: Ben Widawsky <ben at bwidawsk.net>
Reviewed-by: Ian Romanick <ian.d.romanick at intel.com>
---
 src/mesa/drivers/dri/i965/brw_fs_visitor.cpp   | 15 +++++++++++++++
 src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp | 20 ++++++++++++++++++++
 2 files changed, 35 insertions(+)

diff --git a/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp b/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp
index 3622e65..574c266 100644
--- a/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp
+++ b/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp
@@ -700,6 +700,21 @@ fs_visitor::visit(ir_expression *ir)
 
    /* Deal with the real oddball stuff first */
    switch (ir->operation) {
+   case ir_unop_neg: {
+      if (!ir->type->is_float())
+         break;
+
+      ir_expression *mul = ir->operands[0]->as_expression();
+      if (mul && mul->operation == ir_binop_mul) {
+         mul->accept(this);
+         fs_inst *mul_inst = (fs_inst *) this->instructions.get_tail();
+         assert(mul_inst->opcode == BRW_OPCODE_MUL);
+
+         mul_inst->src[1].negate = true;
+         return;
+      }
+      break;
+   }
    case ir_binop_add:
       if (brw->gen <= 5 && try_emit_line(ir))
          return;
diff --git a/src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp b/src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp
index ffbe04d..b9d6087 100644
--- a/src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp
+++ b/src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp
@@ -1303,6 +1303,26 @@ vec4_visitor::visit(ir_expression *ir)
    src_reg op[ARRAY_SIZE(ir->operands)];
    vec4_instruction *inst;
 
+   switch (ir->operation) {
+   case ir_unop_neg: {
+      if (!ir->type->is_float())
+         break;
+
+      ir_expression *mul = ir->operands[0]->as_expression();
+      if (mul && mul->operation == ir_binop_mul) {
+         mul->accept(this);
+         vec4_instruction *mul_inst = (vec4_instruction *) this->instructions.get_tail();
+         assert(mul_inst->opcode == BRW_OPCODE_MUL);
+
+         mul_inst->src[1].negate = true;
+         return;
+      }
+      break;
+   }
+   default:
+      break;
+   }
+
    if (ir->operation == ir_binop_add) {
       if (try_emit_mad(ir))
 	 return;
-- 
2.1.0



More information about the mesa-dev mailing list