[Mesa-dev] [RFC 13/16] nir: Consider float precision when deciding between uint/int/float
Topi Pohjolainen
topi.pohjolainen at intel.com
Fri May 15 02:39:40 PDT 2015
Signed-off-by: Topi Pohjolainen <topi.pohjolainen at intel.com>
---
src/glsl/nir/glsl_to_nir.cpp | 55 +++++++++++---------------------------------
1 file changed, 13 insertions(+), 42 deletions(-)
diff --git a/src/glsl/nir/glsl_to_nir.cpp b/src/glsl/nir/glsl_to_nir.cpp
index 5b3c2ad..5da4122 100644
--- a/src/glsl/nir/glsl_to_nir.cpp
+++ b/src/glsl/nir/glsl_to_nir.cpp
@@ -877,6 +877,12 @@ nir_visitor::emit(nir_op op, unsigned dest_size, nir_src src1,
(type) == GLSL_TYPE_FLOAT ? nir_op_ ## suffix_1 ## _f ## suffix_2 : \
nir_op_ ## suffix_1 ## _i ## suffix_2
+#define OP_FLT_INT_UINT(type, suffix) \
+ (type) == GLSL_TYPE_HALF ? nir_op_h ## suffix : \
+ (type) == GLSL_TYPE_FLOAT ? nir_op_f ## suffix : \
+ (type) == GLSL_TYPE_INT ? nir_op_i ## suffix : \
+ nir_op_u ## suffix
+
void
nir_visitor::visit(ir_expression *ir)
{
@@ -1230,12 +1236,7 @@ nir_visitor::visit(ir_expression *ir)
op = OP_FLT_INT(out_type, mul);
break;
case ir_binop_div:
- if (out_type == GLSL_TYPE_FLOAT)
- op = nir_op_fdiv;
- else if (out_type == GLSL_TYPE_INT)
- op = nir_op_idiv;
- else
- op = nir_op_udiv;
+ op = OP_FLT_INT_UINT(out_type, div);
break;
case ir_binop_mod:
if (out_type == GLSL_TYPE_FLOAT)
@@ -1244,20 +1245,10 @@ nir_visitor::visit(ir_expression *ir)
op = nir_op_umod;
break;
case ir_binop_min:
- if (out_type == GLSL_TYPE_FLOAT)
- op = nir_op_fmin;
- else if (out_type == GLSL_TYPE_INT)
- op = nir_op_imin;
- else
- op = nir_op_umin;
+ op = OP_FLT_INT_UINT(out_type, min);
break;
case ir_binop_max:
- if (out_type == GLSL_TYPE_FLOAT)
- op = nir_op_fmax;
- else if (out_type == GLSL_TYPE_INT)
- op = nir_op_imax;
- else
- op = nir_op_umax;
+ op = OP_FLT_INT_UINT(out_type, max);
break;
case ir_binop_bit_and:
op = nir_op_iand;
@@ -1330,48 +1321,28 @@ nir_visitor::visit(ir_expression *ir)
case ir_binop_borrow: emit(nir_op_usub_borrow, dest_size, srcs); break;
case ir_binop_less:
if (supports_ints) {
- if (types[0] == GLSL_TYPE_FLOAT)
- emit(nir_op_flt, dest_size, srcs);
- else if (types[0] == GLSL_TYPE_INT)
- emit(nir_op_ilt, dest_size, srcs);
- else
- emit(nir_op_ult, dest_size, srcs);
+ emit(OP_FLT_INT_UINT(types[0], lt), dest_size, srcs);
} else {
emit(nir_op_slt, dest_size, srcs);
}
break;
case ir_binop_greater:
if (supports_ints) {
- if (types[0] == GLSL_TYPE_FLOAT)
- emit(nir_op_flt, dest_size, srcs[1], srcs[0]);
- else if (types[0] == GLSL_TYPE_INT)
- emit(nir_op_ilt, dest_size, srcs[1], srcs[0]);
- else
- emit(nir_op_ult, dest_size, srcs[1], srcs[0]);
+ emit(OP_FLT_INT_UINT(types[0], lt), dest_size, srcs[1], srcs[0]);
} else {
emit(nir_op_slt, dest_size, srcs[1], srcs[0]);
}
break;
case ir_binop_lequal:
if (supports_ints) {
- if (types[0] == GLSL_TYPE_FLOAT)
- emit(nir_op_fge, dest_size, srcs[1], srcs[0]);
- else if (types[0] == GLSL_TYPE_INT)
- emit(nir_op_ige, dest_size, srcs[1], srcs[0]);
- else
- emit(nir_op_uge, dest_size, srcs[1], srcs[0]);
+ emit(OP_FLT_INT_UINT(types[0], ge), dest_size, srcs[1], srcs[0]);
} else {
emit(nir_op_slt, dest_size, srcs[1], srcs[0]);
}
break;
case ir_binop_gequal:
if (supports_ints) {
- if (types[0] == GLSL_TYPE_FLOAT)
- emit(nir_op_fge, dest_size, srcs);
- else if (types[0] == GLSL_TYPE_INT)
- emit(nir_op_ige, dest_size, srcs);
- else
- emit(nir_op_uge, dest_size, srcs);
+ emit(OP_FLT_INT_UINT(types[0], ge), dest_size, srcs[0], srcs[1]);
} else {
emit(nir_op_slt, dest_size, srcs);
}
--
1.9.3
More information about the mesa-dev
mailing list