[Mesa-dev] [PATCH 42.5/48] nir/builder: Add a nir_imm_intN_t helper

Jason Ekstrand jason at jlekstrand.net
Tue Oct 31 23:54:31 UTC 2017


This lets you easily build integer immediates of arbitrary bit size.
---
 src/compiler/nir/nir_builder.h | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/src/compiler/nir/nir_builder.h b/src/compiler/nir/nir_builder.h
index 4bd5628..36e0ae3 100644
--- a/src/compiler/nir/nir_builder.h
+++ b/src/compiler/nir/nir_builder.h
@@ -264,6 +264,18 @@ nir_imm_int64(nir_builder *build, int64_t x)
 }
 
 static inline nir_ssa_def *
+nir_imm_intN_t(nir_builder *build, uint64_t x, unsigned bit_size)
+{
+   nir_const_value v;
+
+   memset(&v, 0, sizeof(v));
+   assert(bit_size <= 64);
+   v.i64[0] = x & (~0ull >> (64 - bit_size));
+
+   return nir_build_imm(build, 1, bit_size, v);
+}
+
+static inline nir_ssa_def *
 nir_imm_ivec4(nir_builder *build, int x, int y, int z, int w)
 {
    nir_const_value v;
-- 
2.5.0.400.gff86faf



More information about the mesa-dev mailing list