pan/bi: Implement comparison opcodes via BI_CMP
authorAlyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Tue, 10 Mar 2020 12:21:35 +0000 (08:21 -0400)
committerMarge Bot <eric+marge@anholt.net>
Tue, 10 Mar 2020 19:26:00 +0000 (19:26 +0000)
Pretty straightforward for the moment. Ideally these would be fused into
csel/branches but that will come a bit later.

Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Tested-by: Marge Bot <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4139>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4139>

src/panfrost/bifrost/bifrost_compile.c

index f2529e52a09919e01997265e99ee3b0389eefc50..5e8222990940d86faf48816521892ccce3421c34 100644 (file)
@@ -237,6 +237,16 @@ bi_class_for_nir_alu(nir_op op)
         case nir_op_isub:
                 return BI_ISUB;
 
+        case nir_op_flt:
+        case nir_op_fge:
+        case nir_op_feq:
+        case nir_op_fne:
+        case nir_op_ilt:
+        case nir_op_ige:
+        case nir_op_ieq:
+        case nir_op_ine:
+                return BI_CMP;
+
         case nir_op_bcsel:
                 return BI_CSEL;
 
@@ -290,6 +300,27 @@ bi_class_for_nir_alu(nir_op op)
         }
 }
 
+static enum bi_cond
+bi_cond_for_nir(nir_op op)
+{
+        switch (op) {
+        case nir_op_flt:
+        case nir_op_ilt:
+                return BI_COND_LT;
+        case nir_op_fge:
+        case nir_op_ige:
+                return BI_COND_GE;
+        case nir_op_feq:
+        case nir_op_ieq:
+                return BI_COND_EQ;
+        case nir_op_fne:
+        case nir_op_ine:
+                return BI_COND_NE;
+        default:
+                unreachable("Invalid compare");
+        }
+}
+
 static void
 emit_alu(bi_context *ctx, nir_alu_instr *instr)
 {
@@ -388,6 +419,16 @@ emit_alu(bi_context *ctx, nir_alu_instr *instr)
         case nir_op_fcos:
                 alu.op.special = BI_SPECIAL_FCOS;
                 break;
+        case nir_op_flt:
+        case nir_op_ilt:
+        case nir_op_fge:
+        case nir_op_ige:
+        case nir_op_feq:
+        case nir_op_ieq:
+        case nir_op_fne:
+        case nir_op_ine:
+                alu.op.compare = bi_cond_for_nir(instr->op);
+                break;
         default:
                 break;
         }