nir/builder: Add ubitfield_extract_imm helper
authorAlyssa Rosenzweig <alyssa@rosenzweig.io>
Sun, 21 May 2023 03:01:45 +0000 (23:01 -0400)
committerAlyssa Rosenzweig <alyssa@rosenzweig.io>
Thu, 15 Jun 2023 17:08:41 +0000 (13:08 -0400)
We have a ubfe_imm helper that creates ubfe ops. Not all drivers support ubfe,
however, as it requires SM5 semantics. A few drivers support oly
ubitfield_extract. They should still get the convenience of an _imm helper, so
add a symmetric helper.

It might be nice to unify these helpers into a single helper that asserts its
inputs do not overflow (such that the two ops become equivalent) and emits
either ubfe or ubitfield_extract depending on the underlying driver. That is
left for future work as it's unclear exactly what naming/semantics we want.

Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
Reviewed-by: Erik Faye-Lund <erik.faye-lund@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/23351>

src/compiler/nir/nir_builder.h

index 71890b8..7d42e69 100644 (file)
@@ -938,6 +938,12 @@ nir_ubfe_imm(nir_builder *build, nir_ssa_def *x, uint32_t offset, uint32_t size)
 }
 
 static inline nir_ssa_def *
+nir_ubitfield_extract_imm(nir_builder *build, nir_ssa_def *x, uint32_t offset, uint32_t size)
+{
+   return nir_ubitfield_extract(build, x, nir_imm_int(build, offset), nir_imm_int(build, size));
+}
+
+static inline nir_ssa_def *
 nir_fclamp(nir_builder *b,
            nir_ssa_def *x, nir_ssa_def *min_val, nir_ssa_def *max_val)
 {