if (load1->def.bit_size != load2->def.bit_size)
return false;
- for (unsigned i = 0; i < load1->def.num_components; ++i) {
- switch (load1->def.bit_size) {
- case 1:
+ if (load1->def.bit_size == 1) {
+ for (unsigned i = 0; i < load1->def.num_components; ++i) {
if (load1->value[i].b != load2->value[i].b)
return false;
- break;
- case 8:
- if (load1->value[i].u8 != load2->value[i].u8)
- return false;
- break;
- case 16:
- if (load1->value[i].u16 != load2->value[i].u16)
- return false;
- break;
- case 32:
- if (load1->value[i].u32 != load2->value[i].u32)
- return false;
- break;
- case 64:
- if (load1->value[i].u64 != load2->value[i].u64)
- return false;
- break;
}
+ } else {
+ unsigned size = load1->def.num_components * sizeof(*load1->value);
+ if (memcmp(load1->value, load2->value, size) != 0)
+ return false;
}
return true;
}
}
}
+static void
+validate_const_value(nir_const_value *val, unsigned bit_size,
+ validate_state *state)
+{
+ /* In order for block copies to work properly for things like instruction
+ * comparisons and [de]serialization, we require the unused bits of the
+ * nir_const_value to be zero.
+ */
+ nir_const_value cmp_val;
+ memset(&cmp_val, 0, sizeof(cmp_val));
+ switch (bit_size) {
+ case 1:
+ cmp_val.b = val->b;
+ break;
+ case 8:
+ cmp_val.u8 = val->u8;
+ break;
+ case 16:
+ cmp_val.u16 = val->u16;
+ break;
+ case 32:
+ cmp_val.u32 = val->u32;
+ break;
+ case 64:
+ cmp_val.u64 = val->u64;
+ break;
+ default:
+ validate_assert(state, !"Invalid load_const bit size");
+ }
+ validate_assert(state, memcmp(val, &cmp_val, sizeof(cmp_val)) == 0);
+}
+
static void
validate_load_const_instr(nir_load_const_instr *instr, validate_state *state)
{
validate_ssa_def(&instr->def, state);
+
+ for (unsigned i = 0; i < instr->def.num_components; i++)
+ validate_const_value(&instr->value[i], instr->def.bit_size, state);
}
static void