summaryrefslogtreecommitdiffstats
path: root/src/compiler/nir/nir_validate.c
diff options
context:
space:
mode:
authorJason Ekstrand <[email protected]>2019-04-01 21:42:37 -0500
committerKarol Herbst <[email protected]>2019-04-14 22:25:56 +0200
commit47709ca1465162160dacf2fdb8645b7afb58dcd9 (patch)
tree0a409c391bb98ef0987f069a168f070035d58fd7 /src/compiler/nir/nir_validate.c
parentc4b28d1730e9322821847a94bac2ee4ac60d8617 (diff)
nir/validate: Require unused bits of nir_const_value to be zero
Reviewed-by: Karol Herbst <[email protected]>
Diffstat (limited to 'src/compiler/nir/nir_validate.c')
-rw-r--r--src/compiler/nir/nir_validate.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/compiler/nir/nir_validate.c b/src/compiler/nir/nir_validate.c
index 9a950218208..7746c391abc 100644
--- a/src/compiler/nir/nir_validate.c
+++ b/src/compiler/nir/nir_validate.c
@@ -620,9 +620,44 @@ validate_call_instr(nir_call_instr *instr, validate_state *state)
}
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