Changing I->nr_srcs or I->nr_dests directly is generally unsafe, but the special
case of removing sources/destinations at the end is safe. Add and use helpers to
wrap this operation simplifying the remaining code audit before we can
dynamically allocate sources/destinations.
At this point in the series, nothing modifies I->nr_dests after allocation
except these helpers, so destinations should be safe to make dynamic. There's a
bit more work needed for sources.
Signed-off-by: Alyssa Rosenzweig <alyssa@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17794>
if (I->op == BI_OPCODE_TEXC_DUAL) {
/* In hardware, TEXC has 1 destination */
I->op = BI_OPCODE_TEXC;
- I->dest[1] = bi_null();
- I->nr_dests = 1;
+ bi_drop_dests(I, 1);
}
}
}
pinstr->op = BI_OPCODE_CUBEFACE2;
pinstr->dest[0] = pinstr->dest[1];
- pinstr->dest[1] = bi_null();
- pinstr->nr_dests = 1;
+ bi_drop_dests(pinstr, 1);
pinstr->src[0] = cubeface1->dest[0];
- pinstr->src[1] = bi_null();
- pinstr->src[2] = bi_null();
- pinstr->nr_srcs = 1;
+ bi_drop_srcs(pinstr, 1);
return cubeface1;
}
pinstr->op = BI_OPCODE_SEG_ADD;
pinstr->src[0] = pinstr->src[1];
- pinstr->src[1] = bi_null();
- pinstr->nr_srcs = 1;
+ bi_drop_srcs(pinstr, 1);
assert(pinstr->dest[0].type == BI_INDEX_REGISTER);
pinstr->dest[0].value += 1;
return (s == 0 || s == 4) && bi_opcode_props[I->op].sr_read;
}
+/*
+ * Safe helpers to remove destinations/sources at the end of the
+ * destination/source array when changing opcodes. Unlike adding
+ * sources/destinations, this does not require reallocation.
+ */
+static inline void
+bi_drop_dests(bi_instr *I, unsigned new_count)
+{
+ assert(new_count < I->nr_dests);
+
+ for (unsigned i = new_count; i < I->nr_dests; ++i)
+ I->dest[i] = bi_null();
+
+ I->nr_dests = new_count;
+}
+
+static inline void
+bi_drop_srcs(bi_instr *I, unsigned new_count)
+{
+ assert(new_count < I->nr_srcs);
+
+ for (unsigned i = new_count; i < I->nr_srcs; ++i)
+ I->src[i] = bi_null();
+
+ I->nr_srcs = new_count;
+}
+
/* Represents the assignment of slots for a given bi_tuple */
typedef struct {
}
I->src[0] = I->src[1 - s];
- I->src[1] = bi_null();
- I->nr_srcs = 1;
+ bi_drop_srcs(I, 1);
}
void