bifrost: Add support for nir_op_imul
Unfortunately this doesn't map nicely to the existing instruction
classes, so we'll make a new one for now.
Signed-off-by: Chris Forbes <chrisforbes@google.com>
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6091>
diff --git a/src/panfrost/bifrost/bi_pack.c b/src/panfrost/bifrost/bi_pack.c
index 99a155f..b7ae113 100644
--- a/src/panfrost/bifrost/bi_pack.c
+++ b/src/panfrost/bifrost/bi_pack.c
@@ -1142,6 +1142,14 @@
}
static unsigned
+bi_pack_fma_imul(bi_instruction *ins, bi_registers *regs)
+{
+ assert(ins->op.imul == BI_IMUL_IMUL);
+ unsigned op = BIFROST_FMA_IMUL_32;
+ return bi_pack_fma_2src(ins, regs, op);
+}
+
+static unsigned
bi_pack_fma(bi_clause *clause, bi_bundle bundle, bi_registers *regs)
{
if (!bundle.fma)
@@ -1174,6 +1182,8 @@
return bi_pack_fma_round(bundle.fma, regs);
case BI_REDUCE_FMA:
return bi_pack_fma_reduce(bundle.fma, regs);
+ case BI_IMUL:
+ return bi_pack_fma_imul(bundle.fma, regs);
default:
unreachable("Cannot encode class as FMA");
}
diff --git a/src/panfrost/bifrost/bi_print.c b/src/panfrost/bifrost/bi_print.c
index e8fb326..6dcfdbd 100644
--- a/src/panfrost/bifrost/bi_print.c
+++ b/src/panfrost/bifrost/bi_print.c
@@ -155,6 +155,7 @@
case BI_TABLE: return "table";
case BI_TEX: return "tex";
case BI_ROUND: return "round";
+ case BI_IMUL: return "imul";
default: return "unknown_class";
}
}
diff --git a/src/panfrost/bifrost/bi_tables.c b/src/panfrost/bifrost/bi_tables.c
index 8136593..942de5e 100644
--- a/src/panfrost/bifrost/bi_tables.c
+++ b/src/panfrost/bifrost/bi_tables.c
@@ -56,4 +56,5 @@
[BI_SELECT] = BI_SCHED_ALL | BI_SWIZZLABLE,
[BI_TEX] = BI_SCHED_HI_LATENCY | BI_SCHED_ADD | BI_VECTOR | BI_DATA_REG_DEST,
[BI_ROUND] = BI_ROUNDMODE | BI_SCHED_ALL,
+ [BI_IMUL] = BI_SCHED_FMA,
};
diff --git a/src/panfrost/bifrost/bifrost.h b/src/panfrost/bifrost/bifrost.h
index 0864b3a..a41076b 100644
--- a/src/panfrost/bifrost/bifrost.h
+++ b/src/panfrost/bifrost/bifrost.h
@@ -117,6 +117,7 @@
#define BIFROST_FMA_IADD_32 (0x4ff98 >> 3)
#define BIFROST_FMA_ISUB_32 (0x4ffd8 >> 3)
+#define BIFROST_FMA_IMUL_32 ((BIFROST_FMA_EXT | 0x7818) >> 3)
struct bifrost_fma_2src {
unsigned src0 : 3;
diff --git a/src/panfrost/bifrost/bifrost_compile.c b/src/panfrost/bifrost/bifrost_compile.c
index 566c0e5..2419a4f 100644
--- a/src/panfrost/bifrost/bifrost_compile.c
+++ b/src/panfrost/bifrost/bifrost_compile.c
@@ -512,6 +512,9 @@
case nir_op_isub:
return BI_IMATH;
+ case nir_op_imul:
+ return BI_IMUL;
+
case nir_op_iand:
case nir_op_ior:
case nir_op_ixor:
@@ -821,6 +824,9 @@
alu.src_types[2] = alu.src_types[1];
alu.src[1] = BIR_INDEX_ZERO;
break;
+ case nir_op_imul:
+ alu.op.imul = BI_IMUL_IMUL;
+ break;
case nir_op_fmax:
case nir_op_imax:
case nir_op_umax:
diff --git a/src/panfrost/bifrost/compiler.h b/src/panfrost/bifrost/compiler.h
index 2038a32..4c77ac5 100644
--- a/src/panfrost/bifrost/compiler.h
+++ b/src/panfrost/bifrost/compiler.h
@@ -76,6 +76,7 @@
BI_TABLE,
BI_TEX,
BI_ROUND,
+ BI_IMUL,
BI_NUM_CLASSES
};
@@ -171,6 +172,10 @@
BI_IMATH_SUB,
};
+enum bi_imul_op {
+ BI_IMUL_IMUL,
+};
+
enum bi_table_op {
/* fp32 log2() with low precision, suitable for GL or half_log2() in
* CL. In the first argument, takes x. Letting u be such that x =
@@ -281,6 +286,7 @@
enum bi_frexp_op frexp;
enum bi_tex_op texture;
enum bi_imath_op imath;
+ enum bi_imul_op imul;
/* For FMA/ADD, should we add a biased exponent? */
bool mscale;