+
+uint64_t
+bi_get_immediate(bi_instruction *ins, unsigned index)
+{
+ unsigned v = ins->src[index];
+ assert(v & BIR_INDEX_CONSTANT);
+ unsigned shift = v & ~BIR_INDEX_CONSTANT;
+ uint64_t shifted = ins->constant.u64 >> shift;
+
+ /* Mask off the accessed part */
+ unsigned sz = nir_alu_type_get_type_size(ins->src_types[index]);
+
+ if (sz == 64)
+ return shifted;
+ else
+ return shifted & ((1ull << sz) - 1);
+}
+
+bool
+bi_writes_component(bi_instruction *ins, unsigned comp)
+{
+ return comp < bi_get_component_count(ins, -1);
+}
+
+unsigned
+bi_writemask(bi_instruction *ins)
+{
+ nir_alu_type T = ins->dest_type;
+ unsigned size = nir_alu_type_get_type_size(T);
+ unsigned bytes_per_comp = size / 8;
+ unsigned components = bi_get_component_count(ins, -1);
+ unsigned bytes = bytes_per_comp * components;
+ unsigned mask = (1 << bytes) - 1;
+ unsigned shift = ins->dest_offset * 4; /* 32-bit words */
+ return (mask << shift);
+}