summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlyssa Rosenzweig <alyssa@collabora.com>2022-02-17 19:33:29 -0500
committerEric Engestrom <eric@engestrom.ch>2022-02-23 17:55:56 +0000
commit1c8401d88c5687d4d38d2dffdbecb13b00cf2f5c (patch)
treef6fbb7dbc8e478f6d0a0465ee88a2e5653cd10ca
parent45b0d0817fb97ad194094e788333d306f08efc51 (diff)
pan/bi: Avoid *FADD.v2f16 hazard in optimizer
This is a very obscure encoding restriction in the Bifrost ISA. Unknown if any real apps or tests hit this, but we still need to get it right sadly. Signed-off-by: Alyssa Rosenzweig <alyssa@collabora.com> Cc: mesa-stable Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15072> (cherry picked from commit 8e0eb592d5bbcf00f8bed55cc95013abf77fad12)
-rw-r--r--.pick_status.json2
-rw-r--r--src/panfrost/bifrost/bi_opt_mod_props.c28
2 files changed, 26 insertions, 4 deletions
diff --git a/.pick_status.json b/.pick_status.json
index 7ccaf5f15cb..0cd1b5aa637 100644
--- a/.pick_status.json
+++ b/.pick_status.json
@@ -1606,7 +1606,7 @@
"description": "pan/bi: Avoid *FADD.v2f16 hazard in optimizer",
"nominated": true,
"nomination_type": 0,
- "resolution": 0,
+ "resolution": 1,
"main_sha": null,
"because_sha": null
},
diff --git a/src/panfrost/bifrost/bi_opt_mod_props.c b/src/panfrost/bifrost/bi_opt_mod_props.c
index 44eae29bd62..ce06f9596ad 100644
--- a/src/panfrost/bifrost/bi_opt_mod_props.c
+++ b/src/panfrost/bifrost/bi_opt_mod_props.c
@@ -25,6 +25,18 @@
#include "compiler.h"
#include "bi_builder.h"
+/*
+ * Due to a Bifrost encoding restriction, some instructions cannot have an abs
+ * modifier on both sources. Check if adding a fabs modifier to a given source
+ * of a binary instruction would cause this restriction to be hit.
+ */
+static bool
+bi_would_impact_abs(unsigned arch, bi_instr *I, bi_index repl, unsigned s)
+{
+ return (arch <= 8) && I->src[1 - s].abs &&
+ bi_is_word_equiv(I->src[1 - s], repl);
+}
+
static bool
bi_takes_fabs(unsigned arch, bi_instr *I, bi_index repl, unsigned s)
{
@@ -32,9 +44,15 @@ bi_takes_fabs(unsigned arch, bi_instr *I, bi_index repl, unsigned s)
case BI_OPCODE_FCMP_V2F16:
case BI_OPCODE_FMAX_V2F16:
case BI_OPCODE_FMIN_V2F16:
- /* Bifrost encoding restriction: can't have both abs if equal sources */
- return !(arch <= 8 && I->src[1 - s].abs
- && bi_is_word_equiv(I->src[1 - s], repl));
+ return !bi_would_impact_abs(arch, I, repl, s);
+ case BI_OPCODE_FADD_V2F16:
+ /*
+ * For FADD.v2f16, the FMA pipe has the abs encoding hazard,
+ * while the FADD pipe cannot encode a clamp. Either case in
+ * isolation can be worked around in the scheduler, but both
+ * together is impossible to encode. Avoid the hazard.
+ */
+ return !(I->clamp && bi_would_impact_abs(arch, I, repl, s));
case BI_OPCODE_V2F32_TO_V2F16:
/* TODO: Needs both match or lower */
return false;
@@ -182,6 +200,10 @@ bi_takes_clamp(bi_instr *I)
case BI_OPCODE_FMA_RSCALE_V2F16:
case BI_OPCODE_FADD_RSCALE_F32:
return false;
+ case BI_OPCODE_FADD_V2F16:
+ /* Encoding restriction */
+ return !(I->src[0].abs && I->src[1].abs &&
+ bi_is_word_equiv(I->src[0], I->src[1]));
default:
return bi_opcode_props[I->op].clamp;
}