Hexagon (decode): look for pkts with multiple insns at the same slot

Each slot in a packet can be assigned to at most one instruction.
Although the assembler generally ought to enforce this rule, we better
be safe than sorry and also do some check to properly throw an "invalid
packet" exception on wrong slot assignments.

This should also make it easier to debug possible future errors caused
by missing updates to `find_iclass_slots()` rules in
target/hexagon/iclass.c.

Co-authored-by: Taylor Simpson <tsimpson@quicinc.com>
Signed-off-by: Taylor Simpson <tsimpson@quicinc.com>
Signed-off-by: Matheus Tavares Bernardino <quic_mathbern@quicinc.com>
Reviewed-by: Taylor Simpson <tsimpson@quicinc.com>
Tested-by: Taylor Simpson <tsimpson@quicinc.com>
Message-Id: <f8b829443523568823d062adf8bf6659bc6d4a3f.1683552984.git.quic_mathbern@quicinc.com>
This commit is contained in:
Matheus Tavares Bernardino 2023-05-08 10:37:23 -03:00 committed by Taylor Simpson
parent ed9b28fb00
commit 14edcf11e2
3 changed files with 63 additions and 3 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright(c) 2019-2022 Qualcomm Innovation Center, Inc. All Rights Reserved.
* Copyright(c) 2019-2023 Qualcomm Innovation Center, Inc. All Rights Reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -797,7 +797,26 @@ static bool decode_parsebits_is_loopend(uint32_t encoding32)
return bits == 0x2;
}
static void
static bool has_valid_slot_assignment(Packet *pkt)
{
int used_slots = 0;
for (int i = 0; i < pkt->num_insns; i++) {
int slot_mask;
Insn *insn = &pkt->insn[i];
if (decode_opcode_ends_loop(insn->opcode)) {
/* We overload slot 0 for endloop. */
continue;
}
slot_mask = 1 << insn->slot;
if (used_slots & slot_mask) {
return false;
}
used_slots |= slot_mask;
}
return true;
}
static bool
decode_set_slot_number(Packet *pkt)
{
int slot;
@ -886,6 +905,8 @@ decode_set_slot_number(Packet *pkt)
/* Then push it to slot0 */
pkt->insn[slot1_iidx].slot = 0;
}
return has_valid_slot_assignment(pkt);
}
/*
@ -961,8 +982,11 @@ int decode_packet(int max_words, const uint32_t *words, Packet *pkt,
decode_apply_extenders(pkt);
if (!disas_only) {
decode_remove_extenders(pkt);
if (!decode_set_slot_number(pkt)) {
/* Invalid packet */
return 0;
}
}
decode_set_slot_number(pkt);
decode_fill_newvalue_regno(pkt);
if (pkt->pkt_has_hvx) {