diff options
author | Jason Ekstrand <[email protected]> | 2019-04-01 21:42:37 -0500 |
---|---|---|
committer | Karol Herbst <[email protected]> | 2019-04-14 22:25:56 +0200 |
commit | 47709ca1465162160dacf2fdb8645b7afb58dcd9 (patch) | |
tree | 0a409c391bb98ef0987f069a168f070035d58fd7 /src/compiler | |
parent | c4b28d1730e9322821847a94bac2ee4ac60d8617 (diff) |
nir/validate: Require unused bits of nir_const_value to be zero
Reviewed-by: Karol Herbst <[email protected]>
Diffstat (limited to 'src/compiler')
-rw-r--r-- | src/compiler/nir/nir_instr_set.c | 26 | ||||
-rw-r--r-- | src/compiler/nir/nir_validate.c | 35 |
2 files changed, 41 insertions, 20 deletions
diff --git a/src/compiler/nir/nir_instr_set.c b/src/compiler/nir/nir_instr_set.c index 7dfd3ef1a3e..d53e044c901 100644 --- a/src/compiler/nir/nir_instr_set.c +++ b/src/compiler/nir/nir_instr_set.c @@ -628,29 +628,15 @@ nir_instrs_equal(const nir_instr *instr1, const nir_instr *instr2) 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; } 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 |