extsrc/mesa/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp
/**
 * Emit a gen6 IF statement with the comparison folded into the IF
 * instruction.
 */
Emit a gen6 IF statement with the comparison folded into the IF
instruction.
Emit a gen6 IF statement with the comparison folded into the IF instruction .
void
fs_visitor::emit_if_gen6(ir_if *ir)
{
   ir_expression *expr = ir->condition->as_expression();
   if (expr) {
      fs_reg op[2];
      fs_inst *inst;
      fs_reg temp;
      assert(expr->get_num_operands() <= 2);
      for (unsigned int i = 0; i < expr->get_num_operands(); i++) {
	 assert(expr->operands[i]->type->is_scalar());
	 expr->operands[i]->accept(this);
	 op[i] = this->result;
      }
      switch (expr->operation) {
      case ir_unop_logic_not:
	 inst = emit(BRW_OPCODE_IF, temp, op[0], fs_reg(0));
	 inst->conditional_mod = BRW_CONDITIONAL_Z;
	 return;
      case ir_binop_logic_xor:
	 inst = emit(BRW_OPCODE_IF, reg_null_d, op[0], op[1]);
	 inst->conditional_mod = BRW_CONDITIONAL_NZ;
	 return;
      case ir_binop_logic_or:
	 temp = fs_reg(this, glsl_type::bool_type);
	 emit(BRW_OPCODE_OR, temp, op[0], op[1]);
	 inst = emit(BRW_OPCODE_IF, reg_null_d, temp, fs_reg(0));
	 inst->conditional_mod = BRW_CONDITIONAL_NZ;
	 return;
      case ir_binop_logic_and:
	 temp = fs_reg(this, glsl_type::bool_type);
	 emit(BRW_OPCODE_AND, temp, op[0], op[1]);
	 inst = emit(BRW_OPCODE_IF, reg_null_d, temp, fs_reg(0));
	 inst->conditional_mod = BRW_CONDITIONAL_NZ;
	 return;
      case ir_unop_f2b:
	 inst = emit(BRW_OPCODE_IF, reg_null_f, op[0], fs_reg(0));
	 inst->conditional_mod = BRW_CONDITIONAL_NZ;
	 return;
      case ir_unop_i2b:
	 inst = emit(BRW_OPCODE_IF, reg_null_d, op[0], fs_reg(0));
	 inst->conditional_mod = BRW_CONDITIONAL_NZ;
	 return;
      case ir_binop_greater:
      case ir_binop_gequal:
      case ir_binop_less:
      case ir_binop_lequal:
      case ir_binop_equal:
      case ir_binop_all_equal:
      case ir_binop_nequal:
      case ir_binop_any_nequal:
	 inst = emit(BRW_OPCODE_IF, reg_null_d, op[0], op[1]);
	 inst->conditional_mod =
	    brw_conditional_for_comparison(expr->operation);
	 return;
      default:
	 assert(!"not reached");
	 inst = emit(BRW_OPCODE_IF, reg_null_d, op[0], fs_reg(0));
	 inst->conditional_mod = BRW_CONDITIONAL_NZ;
	 fail("bad condition\n");
	 return;
      }
      return;
   }
   ir->condition->accept(this);
   fs_inst *inst = emit(BRW_OPCODE_IF, reg_null_d, this->result, fs_reg(0));
   inst->conditional_mod = BRW_CONDITIONAL_NZ;
}
void fs_visitor :: emit_if_gen6 ( ir_if * ir ) { ir_expression * expr = ir -> condition -> as_expression ( ) ; if ( expr ) { fs_reg op [ 2 ] ; fs_inst * inst ; fs_reg temp ; assert ( expr -> get_num_operands ( ) <= 2 ) ; for ( unsigned int i = 0 ; i < expr -> get_num_operands ( ) ; i ++ ) { assert ( expr -> operands [ i ] -> type -> is_scalar ( ) ) ; expr -> operands [ i ] -> accept ( this ) ; op [ i ] = this -> result ; } switch ( expr -> operation ) { case ir_unop_logic_not : inst = emit ( BRW_OPCODE_IF , temp , op [ 0 ] , fs_reg ( 0 ) ) ; inst -> conditional_mod = BRW_CONDITIONAL_Z ; return ; case ir_binop_logic_xor : inst = emit ( BRW_OPCODE_IF , reg_null_d , op [ 0 ] , op [ 1 ] ) ; inst -> conditional_mod = BRW_CONDITIONAL_NZ ; return ; case ir_binop_logic_or : temp = fs_reg ( this , glsl_type :: bool_type ) ; emit ( BRW_OPCODE_OR , temp , op [ 0 ] , op [ 1 ] ) ; inst = emit ( BRW_OPCODE_IF , reg_null_d , temp , fs_reg ( 0 ) ) ; inst -> conditional_mod = BRW_CONDITIONAL_NZ ; return ; case ir_binop_logic_and : temp = fs_reg ( this , glsl_type :: bool_type ) ; emit ( BRW_OPCODE_AND , temp , op [ 0 ] , op [ 1 ] ) ; inst = emit ( BRW_OPCODE_IF , reg_null_d , temp , fs_reg ( 0 ) ) ; inst -> conditional_mod = BRW_CONDITIONAL_NZ ; return ; case ir_unop_f2b : inst = emit ( BRW_OPCODE_IF , reg_null_f , op [ 0 ] , fs_reg ( 0 ) ) ; inst -> conditional_mod = BRW_CONDITIONAL_NZ ; return ; case ir_unop_i2b : inst = emit ( BRW_OPCODE_IF , reg_null_d , op [ 0 ] , fs_reg ( 0 ) ) ; inst -> conditional_mod = BRW_CONDITIONAL_NZ ; return ; case ir_binop_greater : case ir_binop_gequal : case ir_binop_less : case ir_binop_lequal : case ir_binop_equal : case ir_binop_all_equal : case ir_binop_nequal : case ir_binop_any_nequal : inst = emit ( BRW_OPCODE_IF , reg_null_d , op [ 0 ] , op [ 1 ] ) ; inst -> conditional_mod = brw_conditional_for_comparison ( expr -> operation ) ; return ; default : assert ( ! " " ) ; inst = emit ( BRW_OPCODE_IF , reg_null_d , op [ 0 ] , fs_reg ( 0 ) ) ; inst -> conditional_mod = BRW_CONDITIONAL_NZ ; fail ( " \n " ) ; return ; } return ; } ir -> condition -> accept ( this ) ; fs_inst * inst = emit ( BRW_OPCODE_IF , reg_null_d , this -> result , fs_reg ( 0 ) ) ; inst -> conditional_mod = BRW_CONDITIONAL_NZ ; }
Emit a gen6 IF statement with the comparison folded into the IF
 instruction.
Emit a gen6 IF statement with the comparison folded into the IF instruction .