i965: Add a function for handling the move of boolean values to flag regs.
authorEric Anholt <eric@anholt.net>
Thu, 14 Oct 2010 18:11:29 +0000 (11:11 -0700)
committerEric Anholt <eric@anholt.net>
Thu, 14 Oct 2010 19:02:54 +0000 (12:02 -0700)
This will be a place to peephole comparisions directly to the flag
regs, and for now avoids using MOV with conditional mod on gen6, which
is now illegal.

src/mesa/drivers/dri/i965/brw_fs.cpp
src/mesa/drivers/dri/i965/brw_fs.h

index 41081c3b6343e2f7a059dbd2688aa49c2e5ffda6..c92bb54960085a99d1cd58b9026c5428c3b2373f 100644 (file)
@@ -969,10 +969,7 @@ fs_visitor::visit(ir_assignment *ir)
    assert(r.file != BAD_FILE);
 
    if (ir->condition) {
-      /* Get the condition bool into the predicate. */
-      ir->condition->accept(this);
-      inst = emit(fs_inst(BRW_OPCODE_CMP, reg_null, this->result, fs_reg(0)));
-      inst->conditional_mod = BRW_CONDITIONAL_NZ;
+      emit_bool_to_cond_code(ir->condition);
    }
 
    if (ir->lhs->type->is_scalar() ||
@@ -1342,6 +1339,22 @@ fs_visitor::visit(ir_constant *ir)
    }
 }
 
+void
+fs_visitor::emit_bool_to_cond_code(ir_rvalue *ir)
+{
+
+   ir->accept(this);
+
+   if (intel->gen >= 6) {
+      fs_inst *inst = emit(fs_inst(BRW_OPCODE_AND, reg_null,
+                                  this->result, fs_reg(1)));
+      inst->conditional_mod = BRW_CONDITIONAL_NZ;
+   } else {
+      fs_inst *inst = emit(fs_inst(BRW_OPCODE_MOV, reg_null, this->result));
+      inst->conditional_mod = BRW_CONDITIONAL_NZ;
+   }
+}
+
 void
 fs_visitor::visit(ir_if *ir)
 {
@@ -1352,10 +1365,7 @@ fs_visitor::visit(ir_if *ir)
     */
    this->base_ir = ir->condition;
 
-   /* Generate the condition into the condition code. */
-   ir->condition->accept(this);
-   inst = emit(fs_inst(BRW_OPCODE_MOV, fs_reg(brw_null_reg()), this->result));
-   inst->conditional_mod = BRW_CONDITIONAL_NZ;
+   emit_bool_to_cond_code(ir->condition);
 
    inst = emit(fs_inst(BRW_OPCODE_IF));
    inst->predicated = true;
index d0e84da1aad1d3d80398936d18848969faa9938b..e0dfa6aed15b7890bcfa76b0c88d960db1fa68b5 100644 (file)
@@ -388,6 +388,7 @@ public:
    fs_inst *emit_texture_gen5(ir_texture *ir, fs_reg dst, fs_reg coordinate);
    fs_inst *emit_math(fs_opcodes op, fs_reg dst, fs_reg src0);
    fs_inst *emit_math(fs_opcodes op, fs_reg dst, fs_reg src0, fs_reg src1);
+   void emit_bool_to_cond_code(ir_rvalue *condition);
 
    void emit_fb_writes();
    void emit_assignment_writes(fs_reg &l, fs_reg &r,