[Mesa-dev] [RFC 12/16] nir: Consider float precision when deciding between int/float: part2

Topi Pohjolainen topi.pohjolainen at intel.com
Fri May 15 02:39:39 PDT 2015


Signed-off-by: Topi Pohjolainen <topi.pohjolainen at intel.com>
---
 src/glsl/nir/glsl_to_nir.cpp | 61 ++++++++++++++++++--------------------------
 1 file changed, 25 insertions(+), 36 deletions(-)

diff --git a/src/glsl/nir/glsl_to_nir.cpp b/src/glsl/nir/glsl_to_nir.cpp
index 1267475..5b3c2ad 100644
--- a/src/glsl/nir/glsl_to_nir.cpp
+++ b/src/glsl/nir/glsl_to_nir.cpp
@@ -872,6 +872,11 @@ nir_visitor::emit(nir_op op, unsigned dest_size, nir_src src1,
    (type) == GLSL_TYPE_FLOAT ? nir_op_f ## suffix : \
                                nir_op_i ## suffix
 
+#define OP_FLT_INT_2(type, suffix_1, suffix_2) \
+   (type) == GLSL_TYPE_HALF  ? nir_op_ ## suffix_1 ## _h ## suffix_2 : \
+   (type) == GLSL_TYPE_FLOAT ? nir_op_ ## suffix_1 ## _f ## suffix_2 : \
+                               nir_op_ ## suffix_1 ## _i ## suffix_2
+
 void
 nir_visitor::visit(ir_expression *ir)
 {
@@ -1387,24 +1392,16 @@ nir_visitor::visit(ir_expression *ir)
       break;
    case ir_binop_all_equal:
       if (supports_ints) {
-         if (types[0] == GLSL_TYPE_FLOAT) {
-            switch (ir->operands[0]->type->vector_elements) {
-               case 1: emit(nir_op_feq, dest_size, srcs); break;
-               case 2: emit(nir_op_ball_fequal2, dest_size, srcs); break;
-               case 3: emit(nir_op_ball_fequal3, dest_size, srcs); break;
-               case 4: emit(nir_op_ball_fequal4, dest_size, srcs); break;
-               default:
-                  unreachable("not reached");
-            }
-         } else {
-            switch (ir->operands[0]->type->vector_elements) {
-               case 1: emit(nir_op_ieq, dest_size, srcs); break;
-               case 2: emit(nir_op_ball_iequal2, dest_size, srcs); break;
-               case 3: emit(nir_op_ball_iequal3, dest_size, srcs); break;
-               case 4: emit(nir_op_ball_iequal4, dest_size, srcs); break;
-               default:
-                  unreachable("not reached");
-            }
+         switch (ir->operands[0]->type->vector_elements) {
+            case 1: emit(OP_FLT_INT(types[0], eq), dest_size, srcs); break;
+            case 2: emit(OP_FLT_INT_2(types[0], ball, equal2),
+                         dest_size, srcs); break;
+            case 3: emit(OP_FLT_INT_2(types[0], ball, equal3),
+                         dest_size, srcs); break;
+            case 4: emit(OP_FLT_INT_2(types[0], ball, equal4),
+                         dest_size, srcs); break;
+            default:
+               unreachable("not reached");
          }
       } else {
          switch (ir->operands[0]->type->vector_elements) {
@@ -1419,24 +1416,16 @@ nir_visitor::visit(ir_expression *ir)
       break;
    case ir_binop_any_nequal:
       if (supports_ints) {
-         if (types[0] == GLSL_TYPE_FLOAT) {
-            switch (ir->operands[0]->type->vector_elements) {
-               case 1: emit(nir_op_fne, dest_size, srcs); break;
-               case 2: emit(nir_op_bany_fnequal2, dest_size, srcs); break;
-               case 3: emit(nir_op_bany_fnequal3, dest_size, srcs); break;
-               case 4: emit(nir_op_bany_fnequal4, dest_size, srcs); break;
-               default:
-                  unreachable("not reached");
-            }
-         } else {
-            switch (ir->operands[0]->type->vector_elements) {
-               case 1: emit(nir_op_ine, dest_size, srcs); break;
-               case 2: emit(nir_op_bany_inequal2, dest_size, srcs); break;
-               case 3: emit(nir_op_bany_inequal3, dest_size, srcs); break;
-               case 4: emit(nir_op_bany_inequal4, dest_size, srcs); break;
-               default:
-                  unreachable("not reached");
-            }
+         switch (ir->operands[0]->type->vector_elements) {
+            case 1: emit(OP_FLT_INT(types[0], ne), dest_size, srcs); break;
+            case 2: emit(OP_FLT_INT_2(types[0], bany, nequal2),
+                         dest_size, srcs); break;
+            case 3: emit(OP_FLT_INT_2(types[0], bany, nequal3),
+                         dest_size, srcs); break;
+            case 4: emit(OP_FLT_INT_2(types[0], bany, nequal4),
+                         dest_size, srcs); break;
+            default:
+               unreachable("not reached");
          }
       } else {
          switch (ir->operands[0]->type->vector_elements) {
-- 
1.9.3



More information about the mesa-dev mailing list