<div dir="ltr">On 22 August 2013 16:08, Matt Turner <span dir="ltr"><<a href="mailto:mattst88@gmail.com" target="_blank">mattst88@gmail.com</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
---<br>
src/mesa/drivers/dri/i965/brw_fs_channel_expressions.cpp | 1 +<br>
src/mesa/drivers/dri/i965/brw_fs_visitor.cpp | 6 ++++++<br>
src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp | 6 ++++++<br>
3 files changed, 13 insertions(+)<br>
<br>
diff --git a/src/mesa/drivers/dri/i965/brw_fs_channel_expressions.cpp b/src/mesa/drivers/dri/i965/brw_fs_channel_expressions.cpp<br>
index 6ee6d01..34dbc90 100644<br>
--- a/src/mesa/drivers/dri/i965/brw_fs_channel_expressions.cpp<br>
+++ b/src/mesa/drivers/dri/i965/brw_fs_channel_expressions.cpp<br>
@@ -362,6 +362,7 @@ ir_channel_expressions_visitor::visit_leave(ir_assignment *ir)<br>
<br>
case ir_triop_fma:<br>
case ir_triop_lrp:<br>
+ case ir_triop_cond_sel:<br>
case ir_triop_bitfield_extract:<br>
for (i = 0; i < vector_elements; i++) {<br>
ir_rvalue *op0 = get_element(op_var[0], i);<br>
diff --git a/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp b/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp<br>
index 4b54bee..27887d6 100644<br>
--- a/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp<br>
+++ b/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp<br>
@@ -735,6 +735,12 @@ fs_visitor::visit(ir_expression *ir)<br>
case ir_triop_lrp:<br>
emit_lrp(this->result, op[0], op[1], op[2]);<br>
break;<br>
+<br>
+ case ir_triop_cond_sel:<br>
+ emit(CMP(reg_null_d, op[0], fs_reg(0), BRW_CONDITIONAL_NZ));<br>
+ inst = emit(BRW_OPCODE_SEL, this->result, op[1], op[2]);<br>
+ inst->predicate = BRW_PREDICATE_NORMAL;<br>
+ break;<br>
}<br>
}<br></blockquote><div><br></div><div>For the uses of ir_triop_cond_sel we have currently (the lowering passes in patch 14), I believe this will generate efficient code. But if we adapt the mix() functions to use it, then there are probably going to be a lot of uses like this:<br>
<br>x = mix(y, z, a < b);<br><br>Which will compile down to this silly assembly (please excuse the pseudocode--I can't remember the assembly syntax exactly):<br><br></div><div>CMP.lt tmp a b<br></div><div>CMP.nz null tmp 0<br>
</div><div>SEL.f0 x y z<br><br></div>What if we modify the loop that calls ir->operands[operand]->accept(this) on each operand (near the top of the visitor) so that it skips operand 0 when the expression is ir_triop_cond_sel. Then, in the switch statement, we can do something like this:<br>
<div><br></div>emit_bool_to_cond_code(ir->operands[0]);<br><div>inst = emit(BRW_OPCODE_SEL, this->result, op[1], op[2]);<br></div><div>inst->predicate = BRW_PREDICATE_NORMAL;<br><br></div><div>That should produce the assembly we want, which is:<br>
<br></div><div>CMP.lt null a b<br></div><div>SEL.fo x y z<br></div><br> <blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
diff --git a/src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp b/src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp<br>
index fbdf73d..0615309 100644<br>
--- a/src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp<br>
+++ b/src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp<br>
@@ -1731,6 +1731,12 @@ vec4_visitor::visit(ir_expression *ir)<br>
emit(LRP(result_dst, op[2], op[1], op[0]));<br>
break;<br>
<br>
+ case ir_triop_cond_sel:<br>
+ emit(CMP(dst_null_d(), op[0], src_reg(0), BRW_CONDITIONAL_NZ));<br>
+ inst = emit(BRW_OPCODE_SEL, result_dst, op[1], op[2]);<br>
+ inst->predicate = BRW_PREDICATE_NORMAL;<br>
+ break;<br>
+<br></blockquote><div><br></div><div>A nearly identical optimization ought to be possible here.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
case ir_triop_bfi:<br>
op[0] = fix_3src_operand(op[0]);<br>
op[1] = fix_3src_operand(op[1]);<br>
<span class=""><font color="#888888">--<br>
1.8.3.2<br>
<br>
_______________________________________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a><br>
<a href="http://lists.freedesktop.org/mailman/listinfo/mesa-dev" target="_blank">http://lists.freedesktop.org/mailman/listinfo/mesa-dev</a><br>
</font></span></blockquote></div><br></div></div>