From: Jason Ekstrand Date: Thu, 11 Jun 2020 22:32:11 +0000 (-0500) Subject: nir/builder: Add a nir_iand_imm helper X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=a0a0bcfa263434507134c382f33d54334c4a67a3;p=mesa.git nir/builder: Add a nir_iand_imm helper Reviewed-by: Caio Marcelo de Oliveira Filho Reviewed-by: Jesse Natalie Part-of: --- 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) {