summaryrefslogtreecommitdiff
path: root/src/compiler
diff options
context:
space:
mode:
authorMike Blumenkrantz <michael.blumenkrantz@gmail.com>2021-05-04 10:24:03 -0400
committerMarge Bot <eric+marge@anholt.net>2021-05-26 04:06:27 +0000
commitf9ecbb1e1d5b8077ba9aa00aaaf3fb4908dae4c8 (patch)
tree34cc4aec12cf9ec16d0b83a72f9f86d6ead46491 /src/compiler
parent360f1032d2a19e9ca1e015baa2bea839a0f1b0fc (diff)
nir/builder: add nir_mask
it's handy to have functions for generating masks Reviewed-by: Jason Ekstrand <jason@jlekstrand.net> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10620>
Diffstat (limited to 'src/compiler')
-rw-r--r--src/compiler/nir/nir_builder.h8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/compiler/nir/nir_builder.h b/src/compiler/nir/nir_builder.h
index 7a81bfb2ada..64832594816 100644
--- a/src/compiler/nir/nir_builder.h
+++ b/src/compiler/nir/nir_builder.h
@@ -1612,6 +1612,14 @@ nir_build_calc_io_offset(nir_builder *b,
return nir_iadd_imm_nuw(b, nir_iadd_nuw(b, base_op, offset_op), const_op);
}
+/* calculate a `(1 << value) - 1` in ssa without overflows */
+static inline nir_ssa_def *
+nir_mask(nir_builder *b, nir_ssa_def *bits, unsigned dst_bit_size)
+{
+ return nir_ushr(b, nir_imm_intN_t(b, -1, dst_bit_size),
+ nir_isub_imm(b, dst_bit_size, nir_u2u32(b, bits)));
+}
+
static inline nir_ssa_def *
nir_f2b(nir_builder *build, nir_ssa_def *f)
{