nir/builder: Add a nir_iand_imm helper
authorJason Ekstrand <jason@jlekstrand.net>
Thu, 11 Jun 2020 22:32:11 +0000 (17:32 -0500)
committerMarge Bot <eric+marge@anholt.net>
Wed, 19 Aug 2020 19:43:31 +0000 (19:43 +0000)
Reviewed-by: Caio Marcelo de Oliveira Filho <caio.oliveira@intel.com>
Reviewed-by: Jesse Natalie <jenatali@microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6210>

src/compiler/nir/nir_builder.h

index 1c1ed9d437358cb93c53577c24f09f8f7787a78f..4a91d26915ba979fd7aa705ac828df4442684fb2 100644 (file)
@@ -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)
 {