Mesa (main): nir: Add a nir_test_mask helper

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Thu Jun 30 18:29:38 UTC 2022


Module: Mesa
Branch: main
Commit: 1018d0f9c04c154738a3ebe67c35a055a4908c45
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=1018d0f9c04c154738a3ebe67c35a055a4908c45

Author: Konstantin Seurer <konstantin.seurer at gmail.com>
Date:   Fri Jun 24 21:12:41 2022 +0200

nir: Add a nir_test_mask helper

nir_ine_imm(b, nir_iand_imm(b, x, mask), 0) and
nir_i2b(b, nir_iand_imm(b, x, mask)) are common
patterns which become quite messy when they are
part of a larger expression. Clang-format does
not improve things either and we can end up with
some rather interesting looking code.
(RADV ray tracing pipeline and query lowering)

Signed-off-by: Konstantin Seurer <konstantin.seurer at gmail.com>
Reviewed-by: Ian Romanick <ian.d.romanick at intel.com>
Reviewed-by: Jason Ekstrand <jason.ekstrand at collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17242>

---

 src/compiler/nir/nir_builder.h | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/src/compiler/nir/nir_builder.h b/src/compiler/nir/nir_builder.h
index bfe27164539..b1051726663 100644
--- a/src/compiler/nir/nir_builder.h
+++ b/src/compiler/nir/nir_builder.h
@@ -740,6 +740,13 @@ nir_iand_imm(nir_builder *build, nir_ssa_def *x, uint64_t y)
    }
 }
 
+static inline nir_ssa_def *
+nir_test_mask(nir_builder *build, nir_ssa_def *x, uint64_t mask)
+{
+   assert(mask <= BITFIELD64_MASK(x->bit_size));
+   return nir_ine_imm(build, nir_iand_imm(build, x, mask), 0);
+}
+
 static inline nir_ssa_def *
 nir_ior_imm(nir_builder *build, nir_ssa_def *x, uint64_t y)
 {



More information about the mesa-commit mailing list