From 0eb5f8e76548e05287d195199705b2d259d51609 Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Tue, 25 Apr 2023 14:39:23 -0400 Subject: [PATCH] nir: Add nir_alu_src_as_uint helper We have a few ALU instructions that take a constant source. Technically, they have a swizzle so you can't just nir_src_as_uint them, even though a bunch of backends do. To help backends do the right thing, add a helper that's just as easy to use that will chase the swizzle properly. Signed-off-by: Alyssa Rosenzweig Reviewed-by: Faith Ekstrand Part-of: --- src/compiler/nir/nir.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h index db75f75..9776aca 100644 --- a/src/compiler/nir/nir.h +++ b/src/compiler/nir/nir.h @@ -2725,6 +2725,13 @@ nir_ssa_scalar_resolved(nir_ssa_def *def, unsigned channel) return nir_ssa_scalar_chase_movs(nir_get_ssa_scalar(def, channel)); } +static inline uint64_t +nir_alu_src_as_uint(nir_alu_src src) +{ + assert(src.src.is_ssa && "precondition"); + nir_ssa_scalar scalar = nir_get_ssa_scalar(src.src.ssa, src.swizzle[0]); + return nir_ssa_scalar_as_uint(scalar); +} typedef struct { bool success; -- 2.7.4