target/hexagon: accept valid packets rejected by check
PATCH 1/2 target/hexagon: accept valid packets rejected by check
has_valid_slot_assignment() rejected any packet with two instructions assigned to the same slot. That is too strict. When a memory instruction is encoded before a slot-flexible instruction in a packet, the descending slot assignment places the memory op in slot 1 and the other in slot 0, then the "mem insns to slot 0" fixup moves the memory op to slot 0 as well, leaving both in slot 0. Such a packet is valid and executes correctly, but the uniqueness test flagged it as HEX_CAUSE_INVALID_PACKET, raising SIGILL in linux-user and a precise exception in system mode.
For example this packet, with the load encoded first, was wrongly rejected:
{ r6 = memw(r3+#-4)
r7 = #0x4ae6 }Replace the uniqueness test with a slot-exhaustion check: walk the instructions in encoding order handing out slots in strictly decreasing order and fail only if an instruction has no valid slot at or below the running slot. This accepts packets that legally share a slot while still rejecting genuinely unassignable packets, such as a memory instruction grouped with a duplex, or a load followed by an instruction that requires a high slot.
--- target/hexagon/decode.c | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-)
target/hexagon/decode.c +22 -8
@@ -549,21 +549,35 @@ static bool decode_parsebits_is_loopend(uint32_t encoding32)return bits ==0x2 ; } +/* +* Check that the packet's instructions can be grouped into slots: walk them +* in encoding order handing out slots in strictly decreasing order, and fail +* if an instruction has no valid slot at or below the running slot. Two +* instructions may legally share a slot, so this does not require unique +* slots, only that every instruction fits. +*/ 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)) { +int i; +int slot =3 ; + +for (i =0 ; i < pkt->num_insns; i++) { +SlotMask valid_slots; +if (decode_opcode_ends_loop (pkt->insn[i].opcode)) {/* We overload slot 0 for endloop. */ continue ; } - slot_mask =1 << insn->slot; -if (used_slots & slot_mask) { +if (slot <0 ) {return false; } - used_slots |= slot_mask; + valid_slots =get_valid_slots (pkt, i); +while (!(valid_slots & (1 << slot))) { +if (slot <=0 ) { +return false; + } + slot--; + } + slot--; }return true; }
Signature · 1 line
2.34.1
PATCH 2/2 tests/tcg/hexagon: add slot-assignment tests
valid-slots: packets that legally share a slot and were wrongly rejected before the fix (load and transfer, load encoded first; dczeroa packed last with three transfers).
invalid-slots: unassignable packets that must still be rejected:
store + duplex, load + indirect jump, three logical ops competing for slots 2 and 3, and five ops for four slots.
--- tests/tcg/hexagon/Makefile.target | 1 + tests/tcg/hexagon/invalid-slots.c | 72 +++++++++++++++++++++++++++++++ tests/tcg/hexagon/valid-slots.c | 62 ++++++++++++++++++++++++++ 3 files changed, 135 insertions(+) create mode 100644 tests/tcg/hexagon/valid-slots.c
tests/tcg/hexagon/Makefile.target +1 -0
@@ -51,6 +51,7 @@ HEX_TESTS += scatter_gather HEX_TESTS += hvx_misc HEX_TESTS += hvx_histogram HEX_TESTS += invalid-slots +HEX_TESTS += valid-slots HEX_TESTS += invalid-encoding HEX_TESTS += multiple-writes HEX_TESTS += unaligned_pc
tests/tcg/hexagon/invalid-slots.c +72 -0
84 lines not on this page · raw message
tests/tcg/hexagon/valid-slots.c new file +62 -0
62 lines not on this page · raw message
Signature · 1 line
2.34.1
Re: [PATCH 2/2] tests/tcg/hexagon: add slot-assignment tests
Quoted 9 lines · On Fri, 24 Jul 2026 10:18:45 -0700 Brian Cain <[email protected]>…
valid-slots: packets that legally share a slot and were wrongly rejected before the fix (load and transfer, load encoded first; dczeroa packed last with three transfers).
invalid-slots: unassignable packets that must still be rejected:
store + duplex, load + indirect jump, three logical ops competing for slots 2 and 3, and five ops for four slots.
Quoted 7 lines
Signed-off-by Brian Cain <[email protected]>--- tests/tcg/hexagon/Makefile.target | 1 + tests/tcg/hexagon/invalid-slots.c | 72 +++++++++++++++++++++++++++++++ tests/tcg/hexagon/valid-slots.c | 62 ++++++++++++++++++++++++++ 3 files changed, 135 insertions(+) create mode 100644 tests/tcg/hexagon/valid-slots.c
Re: [PATCH 2/2] tests/tcg/hexagon: add slot-assignment tests
In reply to Brian CainQuoted 9 lines · On Fri, 24 Jul 2026 10:18:45 -0700 Brian Cain <[email protected]>…
valid-slots: packets that legally share a slot and were wrongly rejected before the fix (load and transfer, load encoded first; dczeroa packed last with three transfers).
invalid-slots: unassignable packets that must still be rejected:
store + duplex, load + indirect jump, three logical ops competing for slots 2 and 3, and five ops for four slots.
Quoted 7 lines
Signed-off-by Brian Cain <[email protected]>--- tests/tcg/hexagon/Makefile.target | 1 + tests/tcg/hexagon/invalid-slots.c | 72 +++++++++++++++++++++++++++++++ tests/tcg/hexagon/valid-slots.c | 62 ++++++++++++++++++++++++++ 3 files changed, 135 insertions(+) create mode 100644 tests/tcg/hexagon/valid-slots.c
Re: [PATCH 2/2] tests/tcg/hexagon: add slot-assignment tests
In reply to Brian CainQuoted 9 lines · On Fri, 24 Jul 2026 10:18:45 -0700 Brian Cain <[email protected]>…
valid-slots: packets that legally share a slot and were wrongly rejected before the fix (load and transfer, load encoded first; dczeroa packed last with three transfers).
invalid-slots: unassignable packets that must still be rejected:
store + duplex, load + indirect jump, three logical ops competing for slots 2 and 3, and five ops for four slots.
Quoted 7 lines
Signed-off-by Brian Cain <[email protected]>--- tests/tcg/hexagon/Makefile.target | 1 + tests/tcg/hexagon/invalid-slots.c | 72 +++++++++++++++++++++++++++++++ tests/tcg/hexagon/valid-slots.c | 62 ++++++++++++++++++++++++++ 3 files changed, 135 insertions(+) create mode 100644 tests/tcg/hexagon/valid-slots.c
Quoted 25 lines · On Fri, 24 Jul 2026 10:18:44 -0700 Brian Cain <[email protected]>…
has_valid_slot_assignment()rejected any packet with two instructions assigned to the same slot. That is too strict. When a memory instruction is encoded before a slot-flexible instruction in a packet, the descending slot assignment places the memory op in slot 1 and the other in slot 0, then the "mem insns to slot 0" fixup moves the memory op to slot 0 as well, leaving both in slot 0. Such a packet is valid and executes correctly, but the uniqueness test flagged it asHEX_CAUSE_INVALID_PACKET, raising SIGILL in linux-user and a precise exception in system mode.For example this packet, with the load encoded first, was wrongly rejected:
{ r6 = memw(r3+#-4) r7 = #0x4ae6 }Replace the uniqueness test with a slot-exhaustion check: walk the instructions in encoding order handing out slots in strictly decreasing order and fail only if an instruction has no valid slot at or below the running slot. This accepts packets that legally share a slot while still rejecting genuinely unassignable packets, such as a memory instruction grouped with a duplex, or a load followed by an instruction that requires a high slot.
Quoted 4 lines
Signed-off-by Brian Cain <[email protected]>--- target/hexagon/decode.c | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-)
(BTW, apologies for the repeated replies in the second patch. I had a bug
in my setting here)