From 37f478688132fcf22baa8d97688d890815419525 Mon Sep 17 00:00:00 2001 From: Job Noorman Date: Thu, 12 Jun 2025 12:14:46 +0200 Subject: [PATCH] ir3: add helpers to handle 64b values 64b values occupy 2 registers but we receive them as a single component value from NIR. Since there are many places that assume a 1:1 relationship between components and instructions, this can be error prone as we have to remember to double the number of components whenever a 64b value is involved. This commit tries to improve on this situation by representing 64b values as a collect of 2 registers, restoring the 1:1 mapping between NIR components and ir3 instructions. This commit only adds some helpers to create 64b values and access their individual components but doesn't actually use them yet. This will happen in a follow-up commit. Signed-off-by: Job Noorman Part-of: --- src/freedreno/ir3/ir3.h | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/freedreno/ir3/ir3.h b/src/freedreno/ir3/ir3.h index 969c9431b12..44dd8f30e94 100644 --- a/src/freedreno/ir3/ir3.h +++ b/src/freedreno/ir3/ir3.h @@ -2698,6 +2698,36 @@ struct ir3_instruction *ir3_create_collect(struct ir3_builder *build, void ir3_split_dest(struct ir3_builder *build, struct ir3_instruction **dst, struct ir3_instruction *src, unsigned base, unsigned n); +static inline struct ir3_instruction * +ir3_64b(struct ir3_builder *build, struct ir3_instruction *lo, + struct ir3_instruction *hi) +{ + assert((lo->dsts[0]->flags & IR3_REG_SHARED) == + (hi->dsts[0]->flags & IR3_REG_SHARED)); + return ir3_collect(build, lo, hi); +} + +static inline struct ir3_instruction * +ir3_64b_immed(struct ir3_builder *build, uint64_t val) +{ + return ir3_64b(build, create_immed(build, (uint32_t)val), + create_immed(build, val >> 32)); +} + +static inline struct ir3_instruction * +ir3_64b_get_lo(struct ir3_instruction *instr) +{ + assert(instr->opc == OPC_META_COLLECT && instr->srcs_count == 2); + return instr->srcs[0]->def->instr; +} + +static inline struct ir3_instruction * +ir3_64b_get_hi(struct ir3_instruction *instr) +{ + assert(instr->opc == OPC_META_COLLECT && instr->srcs_count == 2); + return instr->srcs[1]->def->instr; +} + struct ir3_instruction *ir3_store_const(struct ir3_shader_variant *so, struct ir3_builder *build, struct ir3_instruction *src,