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 <alyssa.rosenzweig@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8215>
This commit is contained in:
Alyssa Rosenzweig 2020-11-27 15:43:14 -05:00
parent 0f0bb87e9d
commit d93995fd2b
4 changed files with 19 additions and 31 deletions

View File

@ -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);

View File

@ -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);
}

View File

@ -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 */

View File

@ -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