OSDN Git Service

glsl: Optimize various cases of fma (aka MAD).
authorEric Anholt <eric@anholt.net>
Sat, 18 Jan 2014 19:06:16 +0000 (11:06 -0800)
committerEric Anholt <eric@anholt.net>
Fri, 7 Feb 2014 20:46:48 +0000 (12:46 -0800)
Reviewed-by: Matt Turner <mattst88@gmail.com>
src/glsl/opt_algebraic.cpp

index 392051f..7863fe8 100644 (file)
@@ -547,6 +547,19 @@ ir_algebraic_visitor::handle_expression(ir_expression *ir)
 
       break;
 
+   case ir_triop_fma:
+      /* Operands are op0 * op1 + op2. */
+      if (is_vec_zero(op_const[0]) || is_vec_zero(op_const[1])) {
+         return ir->operands[2];
+      } else if (is_vec_zero(op_const[2])) {
+         return mul(ir->operands[0], ir->operands[1]);
+      } else if (is_vec_one(op_const[0])) {
+         return add(ir->operands[1], ir->operands[2]);
+      } else if (is_vec_one(op_const[1])) {
+         return add(ir->operands[0], ir->operands[2]);
+      }
+      break;
+
    case ir_triop_lrp:
       /* Operands are (x, y, a). */
       if (is_vec_zero(op_const[2])) {