diff --git a/src/panfrost/bifrost/bi_pack.c b/src/panfrost/bifrost/bi_pack.c index b3b6cbf5646..b497d28ceee 100644 --- a/src/panfrost/bifrost/bi_pack.c +++ b/src/panfrost/bifrost/bi_pack.c @@ -744,8 +744,7 @@ bi_lower_texc_dual(bi_context *ctx) if (I->op == BI_OPCODE_TEXC_DUAL) { /* In hardware, TEXC has 1 destination */ I->op = BI_OPCODE_TEXC; - I->dest[1] = bi_null(); - I->nr_dests = 1; + bi_drop_dests(I, 1); } } } diff --git a/src/panfrost/bifrost/bi_schedule.c b/src/panfrost/bifrost/bi_schedule.c index a06b416b6ac..f183fd266a8 100644 --- a/src/panfrost/bifrost/bi_schedule.c +++ b/src/panfrost/bifrost/bi_schedule.c @@ -328,13 +328,10 @@ bi_lower_cubeface(bi_context *ctx, pinstr->op = BI_OPCODE_CUBEFACE2; pinstr->dest[0] = pinstr->dest[1]; - pinstr->dest[1] = bi_null(); - pinstr->nr_dests = 1; + bi_drop_dests(pinstr, 1); pinstr->src[0] = cubeface1->dest[0]; - pinstr->src[1] = bi_null(); - pinstr->src[2] = bi_null(); - pinstr->nr_srcs = 1; + bi_drop_srcs(pinstr, 1); return cubeface1; } @@ -397,8 +394,7 @@ bi_lower_seg_add(bi_context *ctx, pinstr->op = BI_OPCODE_SEG_ADD; pinstr->src[0] = pinstr->src[1]; - pinstr->src[1] = bi_null(); - pinstr->nr_srcs = 1; + bi_drop_srcs(pinstr, 1); assert(pinstr->dest[0].type == BI_INDEX_REGISTER); pinstr->dest[0].value += 1; diff --git a/src/panfrost/bifrost/compiler.h b/src/panfrost/bifrost/compiler.h index ceb7e9d935e..6fbdfa5db17 100644 --- a/src/panfrost/bifrost/compiler.h +++ b/src/panfrost/bifrost/compiler.h @@ -547,6 +547,33 @@ bi_is_staging_src(const bi_instr *I, unsigned s) return (s == 0 || s == 4) && bi_opcode_props[I->op].sr_read; } +/* + * Safe helpers to remove destinations/sources at the end of the + * destination/source array when changing opcodes. Unlike adding + * sources/destinations, this does not require reallocation. + */ +static inline void +bi_drop_dests(bi_instr *I, unsigned new_count) +{ + assert(new_count < I->nr_dests); + + for (unsigned i = new_count; i < I->nr_dests; ++i) + I->dest[i] = bi_null(); + + I->nr_dests = new_count; +} + +static inline void +bi_drop_srcs(bi_instr *I, unsigned new_count) +{ + assert(new_count < I->nr_srcs); + + for (unsigned i = new_count; i < I->nr_srcs; ++i) + I->src[i] = bi_null(); + + I->nr_srcs = new_count; +} + /* Represents the assignment of slots for a given bi_tuple */ typedef struct { diff --git a/src/panfrost/bifrost/valhall/va_optimize.c b/src/panfrost/bifrost/valhall/va_optimize.c index 06711872584..a50c4244952 100644 --- a/src/panfrost/bifrost/valhall/va_optimize.c +++ b/src/panfrost/bifrost/valhall/va_optimize.c @@ -105,8 +105,7 @@ va_fuse_add_imm(bi_instr *I) } I->src[0] = I->src[1 - s]; - I->src[1] = bi_null(); - I->nr_srcs = 1; + bi_drop_srcs(I, 1); } void