Revert "i965/fs: Change fs_visitor::emit_lrp to use MAC for gen<6"
[mesa.git] / src / glsl / opt_algebraic.cpp
index 1b4d319366ccf68d1681ce782b2fe02ba3281d4b..9d5539252074901b56e5d4238b4b32d44af452ae 100644 (file)
@@ -45,10 +45,11 @@ namespace {
 
 class ir_algebraic_visitor : public ir_rvalue_visitor {
 public:
-   ir_algebraic_visitor()
+   ir_algebraic_visitor(bool native_integers)
    {
       this->progress = false;
       this->mem_ctx = NULL;
+      this->native_integers = native_integers;
    }
 
    virtual ~ir_algebraic_visitor()
@@ -70,6 +71,7 @@ public:
 
    void *mem_ctx;
 
+   bool native_integers;
    bool progress;
 };
 
@@ -445,6 +447,28 @@ ir_algebraic_visitor::handle_expression(ir_expression *ir)
       }
       break;
 
+   case ir_binop_less:
+   case ir_binop_lequal:
+   case ir_binop_greater:
+   case ir_binop_gequal:
+   case ir_binop_equal:
+   case ir_binop_nequal:
+      for (int add_pos = 0; add_pos < 2; add_pos++) {
+         ir_expression *add = op_expr[add_pos];
+
+         if (!add || add->operation != ir_binop_add)
+            continue;
+
+         ir_constant *zero = op_const[1 - add_pos];
+         if (!is_vec_zero(zero))
+            continue;
+
+         return new(mem_ctx) ir_expression(ir->operation,
+                                           add->operands[0],
+                                           neg(add->operands[1]));
+      }
+      break;
+
    case ir_binop_rshift:
    case ir_binop_lshift:
       /* 0 >> x == 0 */
@@ -528,6 +552,14 @@ ir_algebraic_visitor::handle_expression(ir_expression *ir)
       if (is_vec_two(op_const[0]))
          return expr(ir_unop_exp2, ir->operands[1]);
 
+      if (is_vec_two(op_const[1])) {
+         ir_variable *x = new(ir) ir_variable(ir->operands[1]->type, "x",
+                                              ir_var_temporary);
+         base_ir->insert_before(x);
+         base_ir->insert_before(assign(x, ir->operands[0]));
+         return mul(x, x);
+      }
+
       break;
 
    case ir_unop_rcp:
@@ -568,6 +600,12 @@ ir_algebraic_visitor::handle_expression(ir_expression *ir)
          return ir->operands[1];
       } else if (ir->operands[0]->equals(ir->operands[1])) {
          return ir->operands[0];
+      } else if (is_vec_zero(op_const[0])) {
+         return mul(ir->operands[1], ir->operands[2]);
+      } else if (is_vec_zero(op_const[1])) {
+         unsigned op2_components = ir->operands[2]->type->vector_elements;
+         ir_constant *one = new(mem_ctx) ir_constant(1.0f, op2_components);
+         return mul(ir->operands[0], add(one, neg(ir->operands[2])));
       }
       break;
 
@@ -609,9 +647,9 @@ ir_algebraic_visitor::handle_rvalue(ir_rvalue **rvalue)
 }
 
 bool
-do_algebraic(exec_list *instructions)
+do_algebraic(exec_list *instructions, bool native_integers)
 {
-   ir_algebraic_visitor v;
+   ir_algebraic_visitor v(native_integers);
 
    visit_list_elements(&v, instructions);