From d93995fd2bc0a1dd7ee324f41dd15d412784c69e Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Fri, 27 Nov 2020 15:43:14 -0500 Subject: [PATCH] pan/bi: Make BIR_INDEX_ZERO less special It can be implemented as a constant that just shifts beyond the 64-bits available for the instruction, and then we can avoid special handling in a bunch of places. Signed-off-by: Alyssa Rosenzweig Part-of: --- src/panfrost/bifrost/bi_pack.c | 30 +++++++----------------------- src/panfrost/bifrost/bi_print.c | 4 +--- src/panfrost/bifrost/bir.c | 5 +++++ src/panfrost/bifrost/compiler.h | 11 ++++++----- 4 files changed, 19 insertions(+), 31 deletions(-) diff --git a/src/panfrost/bifrost/bi_pack.c b/src/panfrost/bifrost/bi_pack.c index 27823f8766a..bf71b44936f 100644 --- a/src/panfrost/bifrost/bi_pack.c +++ b/src/panfrost/bifrost/bi_pack.c @@ -131,16 +131,16 @@ bi_assign_fau_idx_single(bi_registers *regs, } bi_foreach_src(ins, s) { - if (s == 0 && (ins->type == BI_LOAD_VAR_ADDRESS || ins->type == BI_LOAD_ATTR)) continue; - if (s == 1 && (ins->type == BI_BRANCH)) continue; - if (ins->src[s] & BIR_INDEX_CONSTANT) { - /* Let direct addresses through */ - if (ins->type == BI_LOAD_VAR) - continue; - bool hi = false; uint32_t cons = bi_get_immediate(ins, s); + + /* FMA can encode zero for free */ + if (cons == 0 && fast_zero) { + ins->src[s] = BIR_INDEX_PASS | BIFROST_SRC_STAGE; + continue; + } + unsigned idx = bi_lookup_constant(clause, cons, &hi); unsigned lo = clause->constants[idx] & 0xF; unsigned f = bi_constant_field(idx) | lo; @@ -151,22 +151,6 @@ bi_assign_fau_idx_single(bi_registers *regs, regs->fau_idx = f; ins->src[s] = BIR_INDEX_PASS | (hi ? BIFROST_SRC_FAU_HI : BIFROST_SRC_FAU_LO); assigned = true; - } else if (ins->src[s] & BIR_INDEX_ZERO && (ins->type == BI_LOAD_UNIFORM || ins->type == BI_LOAD_VAR)) { - /* XXX: HACK UNTIL WE HAVE HI MATCHING DUE TO OVERFLOW XXX */ - ins->src[s] = BIR_INDEX_PASS | BIFROST_SRC_FAU_HI; - } else if (ins->src[s] & BIR_INDEX_ZERO && !fast_zero) { - /* FMAs have a fast zero slot, ADD needs to use the - * uniform/const slot's special 0 mode handled here */ - unsigned f = 0; - - if (assigned && regs->fau_idx != f) - unreachable("Mismatched uniform/const field: 0"); - - regs->fau_idx = f; - ins->src[s] = BIR_INDEX_PASS | BIFROST_SRC_FAU_LO; - assigned = true; - } else if (ins->src[s] & BIR_INDEX_ZERO && fast_zero) { - ins->src[s] = BIR_INDEX_PASS | BIFROST_SRC_STAGE; } else if (ins->src[s] & BIR_INDEX_FAU) { unsigned index = ins->src[s] & BIR_FAU_TYPE_MASK; bool hi = !!(ins->src[s] & BIR_FAU_HI); diff --git a/src/panfrost/bifrost/bi_print.c b/src/panfrost/bifrost/bi_print.c index 3484238d398..1785bf092da 100644 --- a/src/panfrost/bifrost/bi_print.c +++ b/src/panfrost/bifrost/bi_print.c @@ -174,8 +174,6 @@ bi_print_index(FILE *fp, bi_instruction *ins, unsigned index, unsigned s) (index & BIR_FAU_HI) ? 1 : 0); else if (index & BIR_INDEX_CONSTANT) fprintf(fp, "#0x%" PRIx64, bi_get_immediate(ins, s)); - else if (index & BIR_INDEX_ZERO) - fprintf(fp, "#0"); else if (index & BIR_INDEX_FAU) fprintf(fp, "%s.%c", bir_fau_name(index & BIR_FAU_TYPE_MASK), (index & BIR_FAU_HI) ? 'y' : 'x'); @@ -416,7 +414,7 @@ bi_print_instruction(bi_instruction *ins, FILE *fp) if (ins->src[s] && !(ins->src[s] & - (BIR_INDEX_CONSTANT | BIR_INDEX_ZERO | BIR_INDEX_FAU))) { + (BIR_INDEX_CONSTANT | BIR_INDEX_FAU))) { pan_print_alu_type(ins->src_types[s], fp); bi_print_swizzle(ins, s, fp); } diff --git a/src/panfrost/bifrost/bir.c b/src/panfrost/bifrost/bir.c index de7c1d7d985..1cef5dc1d59 100644 --- a/src/panfrost/bifrost/bir.c +++ b/src/panfrost/bifrost/bir.c @@ -151,6 +151,11 @@ bi_get_immediate(bi_instruction *ins, unsigned index) unsigned v = ins->src[index]; assert(v & BIR_INDEX_CONSTANT); unsigned shift = v & ~BIR_INDEX_CONSTANT; + + /* Don't invoke undefined behaviour on shift */ + if (shift == 64) + return 0; + uint64_t shifted = ins->constant.u64 >> shift; /* Mask off the accessed part */ diff --git a/src/panfrost/bifrost/compiler.h b/src/panfrost/bifrost/compiler.h index e5304bdadfc..425d71fc5e4 100644 --- a/src/panfrost/bifrost/compiler.h +++ b/src/panfrost/bifrost/compiler.h @@ -534,9 +534,11 @@ bi_remove_instruction(bi_instruction *ins) #define BIR_INDEX_REGISTER (1 << 31) #define BIR_INDEX_CONSTANT (1 << 30) -#define BIR_INDEX_ZERO (1 << 29) -#define BIR_INDEX_PASS (1 << 28) -#define BIR_INDEX_FAU (1 << 27) +#define BIR_INDEX_PASS (1 << 29) +#define BIR_INDEX_FAU (1 << 28) + +/* Shift everything away */ +#define BIR_INDEX_ZERO (BIR_INDEX_CONSTANT | 64) enum bir_fau { BIR_FAU_ZERO = 0, @@ -555,8 +557,7 @@ enum bir_fau { /* Keep me synced please so we can check src & BIR_SPECIAL */ -#define BIR_SPECIAL (BIR_INDEX_REGISTER | \ - BIR_INDEX_CONSTANT | BIR_INDEX_ZERO | \ +#define BIR_SPECIAL (BIR_INDEX_REGISTER | BIR_INDEX_CONSTANT | \ BIR_INDEX_PASS | BIR_INDEX_FAU) static inline unsigned