pan/bi: Validate format 12 tuple count in disasm

We were throwing away this information. Let's just use a lookup table
and add an assertion. Would have caught a bug in this series resulting
in INSTR_INVALID_ENC faults.

Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8723>
This commit is contained in:
Alyssa Rosenzweig 2021-01-18 08:58:09 -05:00 committed by Marge Bot
parent 61af9cb76b
commit 15d03ed783

View file

@ -567,45 +567,33 @@ static bool dump_clause(FILE *fp, uint32_t *words, unsigned *size, unsigned offs
case 0x7: { case 0x7: {
/* Format 12 */ /* Format 12 */
unsigned pos = tag & 0xf; unsigned pos = tag & 0xf;
// note that `pos' encodes both the total number of
// instructions and the position in the constant stream, struct {
// presumably because decoded constants and instructions unsigned const_idx;
// share a buffer in the decoder, but we only care about unsigned nr_tuples;
// the position in the constant stream; the total number of } pos_table[0x10] = {
// instructions is redundant. { 0, 1 },
unsigned const_idx = 0; { 0, 2 },
switch (pos) { { 0, 4 },
case 0: { 1, 3 },
case 1: { 1, 5 },
case 2: { 2, 4 },
case 6: { 0, 7 },
const_idx = 0; { 1, 6 },
break; { 3, 5 },
case 3: { 1, 8 },
case 4: { 2, 7 },
case 7: { 3, 6 },
case 9: { 3, 8 },
const_idx = 1; { 4, 7 },
break; { 5, 6 },
case 5: { ~0, ~0 }
case 0xa: };
const_idx = 2;
break; ASSERTED bool valid_count = pos_table[pos].nr_tuples == num_instrs;
case 8: assert(valid_count && "INSTR_INVALID_ENC");
case 0xb:
case 0xc: unsigned const_idx = pos_table[pos].const_idx;
const_idx = 3;
break;
case 0xd:
const_idx = 4;
break;
case 0xe:
const_idx = 5;
break;
default:
fprintf(fp, "# unknown pos 0x%x\n", pos);
break;
}
if (num_consts < const_idx + 2) if (num_consts < const_idx + 2)
num_consts = const_idx + 2; num_consts = const_idx + 2;