[Mesa-dev] [RFC 11/16] nir: Consider float precision when deciding between int/float
Topi Pohjolainen
topi.pohjolainen at intel.com
Fri May 15 02:39:38 PDT 2015
Signed-off-by: Topi Pohjolainen <topi.pohjolainen at intel.com>
---
src/glsl/nir/glsl_to_nir.cpp | 39 +++++++++++++--------------------------
1 file changed, 13 insertions(+), 26 deletions(-)
diff --git a/src/glsl/nir/glsl_to_nir.cpp b/src/glsl/nir/glsl_to_nir.cpp
index 7a20e1a..1267475 100644
--- a/src/glsl/nir/glsl_to_nir.cpp
+++ b/src/glsl/nir/glsl_to_nir.cpp
@@ -867,6 +867,11 @@ nir_visitor::emit(nir_op op, unsigned dest_size, nir_src src1,
return emit(op, dest_size, srcs);
}
+#define OP_FLT_INT(type, suffix) \
+ (type) == GLSL_TYPE_HALF ? nir_op_h ## suffix : \
+ (type) == GLSL_TYPE_FLOAT ? nir_op_f ## suffix : \
+ nir_op_i ## suffix
+
void
nir_visitor::visit(ir_expression *ir)
{
@@ -1020,20 +1025,17 @@ nir_visitor::visit(ir_expression *ir)
emit(supports_ints ? nir_op_inot : nir_op_fnot, dest_size, srcs);
break;
case ir_unop_neg:
- instr = emit(types[0] == GLSL_TYPE_FLOAT ? nir_op_fneg : nir_op_ineg,
- dest_size, srcs);
+ instr = emit(OP_FLT_INT(types[0], neg), dest_size, srcs);
break;
case ir_unop_abs:
- instr = emit(types[0] == GLSL_TYPE_FLOAT ? nir_op_fabs : nir_op_iabs,
- dest_size, srcs);
+ instr = emit(OP_FLT_INT(types[0], abs), dest_size, srcs);
break;
case ir_unop_saturate:
assert(types[0] == GLSL_TYPE_FLOAT);
instr = emit(nir_op_fsat, dest_size, srcs);
break;
case ir_unop_sign:
- emit(types[0] == GLSL_TYPE_FLOAT ? nir_op_fsign : nir_op_isign,
- dest_size, srcs);
+ instr = emit(OP_FLT_INT(types[0], sign), dest_size, srcs);
break;
case ir_unop_rcp: emit(nir_op_frcp, dest_size, srcs); break;
case ir_unop_rsq: emit(nir_op_frsq, dest_size, srcs); break;
@@ -1214,22 +1216,13 @@ nir_visitor::visit(ir_expression *ir)
case ir_binop_rshift:
switch (ir->operation) {
case ir_binop_add:
- if (out_type == GLSL_TYPE_FLOAT)
- op = nir_op_fadd;
- else
- op = nir_op_iadd;
+ op = OP_FLT_INT(out_type, add);
break;
case ir_binop_sub:
- if (out_type == GLSL_TYPE_FLOAT)
- op = nir_op_fsub;
- else
- op = nir_op_isub;
+ op = OP_FLT_INT(out_type, sub);
break;
case ir_binop_mul:
- if (out_type == GLSL_TYPE_FLOAT)
- op = nir_op_fmul;
- else
- op = nir_op_imul;
+ op = OP_FLT_INT(out_type, mul);
break;
case ir_binop_div:
if (out_type == GLSL_TYPE_FLOAT)
@@ -1380,20 +1373,14 @@ nir_visitor::visit(ir_expression *ir)
break;
case ir_binop_equal:
if (supports_ints) {
- if (types[0] == GLSL_TYPE_FLOAT)
- emit(nir_op_feq, dest_size, srcs);
- else
- emit(nir_op_ieq, dest_size, srcs);
+ instr = emit(OP_FLT_INT(types[0], eq), dest_size, srcs);
} else {
emit(nir_op_seq, dest_size, srcs);
}
break;
case ir_binop_nequal:
if (supports_ints) {
- if (types[0] == GLSL_TYPE_FLOAT)
- emit(nir_op_fne, dest_size, srcs);
- else
- emit(nir_op_ine, dest_size, srcs);
+ instr = emit(OP_FLT_INT(types[0], ne), dest_size, srcs);
} else {
emit(nir_op_sne, dest_size, srcs);
}
--
1.9.3
More information about the mesa-dev
mailing list