pan/bi: Handle core faddminmax16 packing
authorAlyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Sat, 28 Mar 2020 02:26:32 +0000 (22:26 -0400)
committerMarge Bot <eric+marge@anholt.net>
Tue, 31 Mar 2020 01:12:26 +0000 (01:12 +0000)
This works without the exception of absolute values, which have some...
odd properties to be handled in the next commit.

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

src/panfrost/bifrost/bi_pack.c

index f60efd9ad1955080ea41630f9ac793c9f8b89922..384c081a07dbe2776a5597dc70c0589e3db7c18c 100644 (file)
@@ -486,11 +486,8 @@ bi_pack_fma_fma(bi_instruction *ins, struct bi_registers *regs)
 }
 
 static unsigned
-bi_pack_fma_add(bi_instruction *ins, struct bi_registers *regs)
+bi_pack_fma_add_f32(bi_instruction *ins, struct bi_registers *regs)
 {
-        /* TODO: fadd16 packing is a bit different */
-        assert(ins->dest_type == nir_type_float32);
-
         struct bifrost_fma_add pack = {
                 .src0 = bi_get_src(ins, regs, 0, true),
                 .src1 = bi_get_src(ins, regs, 1, true),
@@ -507,6 +504,38 @@ bi_pack_fma_add(bi_instruction *ins, struct bi_registers *regs)
         RETURN_PACKED(pack);
 }
 
+static unsigned
+bi_pack_fma_addmin_f16(bi_instruction *ins, struct bi_registers *regs)
+{
+        unsigned op =
+                (ins->type == BI_ADD) ? BIFROST_FMA_OP_FADD16 :
+                (ins->op.minmax == BI_MINMAX_MIN) ? BIFROST_FMA_OP_FMIN16 :
+                BIFROST_FMA_OP_FMAX16;
+
+        struct bifrost_fma_add_minmax16 pack = {
+                .src0 = bi_get_src(ins, regs, 0, true),
+                .src1 = bi_get_src(ins, regs, 1, true),
+                .src0_neg = ins->src_neg[0],
+                .src1_neg = ins->src_neg[1],
+                .outmod = ins->outmod,
+                .mode = (ins->type == BI_ADD) ? ins->roundmode : ins->minmax,
+                .op = op
+        };
+
+        RETURN_PACKED(pack);
+}
+
+static unsigned
+bi_pack_fma_add(bi_instruction *ins, struct bi_registers *regs)
+{
+        if (ins->dest_type == nir_type_float32)
+                return bi_pack_fma_add_f32(ins, regs);
+        else if(ins->dest_type == nir_type_float16)
+                return bi_pack_fma_addmin_f16(ins, regs);
+        else
+                unreachable("Unknown FMA/ADD type");
+}
+
 static unsigned
 bi_pack_fma_1src(bi_instruction *ins, struct bi_registers *regs, unsigned op)
 {