From a0a0bcfa263434507134c382f33d54334c4a67a3 Mon Sep 17 00:00:00 2001 From: Jason Ekstrand Date: Thu, 11 Jun 2020 17:32:11 -0500 Subject: [PATCH] nir/builder: Add a nir_iand_imm helper Reviewed-by: Caio Marcelo de Oliveira Filho Reviewed-by: Jesse Natalie Part-of: --- src/compiler/nir/nir_builder.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/compiler/nir/nir_builder.h b/src/compiler/nir/nir_builder.h index 1c1ed9d4373..4a91d26915b 100644 --- a/src/compiler/nir/nir_builder.h +++ b/src/compiler/nir/nir_builder.h @@ -763,6 +763,20 @@ nir_fmul_imm(nir_builder *build, nir_ssa_def *x, double y) return nir_fmul(build, x, nir_imm_floatN_t(build, y, x->bit_size)); } +static inline nir_ssa_def * +nir_iand_imm(nir_builder *build, nir_ssa_def *x, uint64_t y) +{ + y &= BITFIELD64_MASK(x->bit_size); + + if (y == 0) { + return nir_imm_intN_t(build, 0, x->bit_size); + } else if (y == BITFIELD64_MASK(x->bit_size)) { + return x; + } else { + return nir_iand(build, x, nir_imm_intN_t(build, y, x->bit_size)); + } +} + static inline nir_ssa_def * nir_pack_bits(nir_builder *b, nir_ssa_def *src, unsigned dest_bit_size) { -- 2.30.2