| Message ID | 20261105114633.597-3-anjo@rev.ng |
|---|---|
| State | New |
| Headers | show |
| Series | target/hexagon: Misc HLX fixes | expand |
On Thu, Nov 5, 2026 at 5:41 AM Anton Johansson <anjo@rev.ng> wrote: > > Otherwise, the following packet > > { > L7:6 = combine(L0, L1) > memw(R7) = L7.new > } > > results in memw(R7) being zero-intialized, compared to L6.new which > would correctly write the lower bytes of the pair. The packet in the test is combine(L0, L2), and the store is mem(R7) = L7.new. Also s/intialized/initialized/. [...] > + if (regno == lreg || > + (GET_ATTRIB(insn->opcode, A_HLX_PAIRED_ALU) && regno + 1 == lreg)) { > return i; > } This finds the producer now, but decode_fill_newvalue_regno() then overwrites the consumer's register with the producer's dest register: `packet->insn[i].regno[use_regidx] = packet->insn[def_idx].regno[dst_idx];` For a pair, that is the base register, so L7.new becomes L6.new and the store writes the low half of the pair instead of the high half. Also, not all instructions that write a pair have A_HLX_PAIRED_ALU, e.g. LX_assign_rw (Ldd16.w=Rt32.w). A high .new store from those still writes zeros. [...] > + hlx_put_v(0, l_lo); > + hlx_put_v(2, l_hi); [...] > + for (int j = 0; j < HLX_HALF_ELEMS; j++) { > + expected[j] = VAL_A; > + } > + check_h("LX_assign_w (hi only)", buf_a, expected, HLX_HALF_ELEMS); > +} L0 holds the low halves of VAL_W (0x5678), and combine(L0, L2) puts L0 into L7. So L7.new must store 0x5678, but the test expects VAL_A (0x1234), which is the L6 value. The test passes because L6.new is used instead of L7.new. IMHO: Maybe we should have a mechanism that creates an error if a .new value is used, but that .new value isn't even in the packet. Like it is happening here. L6.new is computed, but it isn't even used in the packet. Maybe poisoning it somehow. But that's just me thinking out loud, doesn't need to go into this patch series.
On 11/5/2026 11:58 AM, Marco Liebel wrote: > On Thu, Nov 5, 2026 at 5:41 AM Anton Johansson <anjo@rev.ng> wrote: >> Otherwise, the following packet >> >> { >> L7:6 = combine(L0, L1) >> memw(R7) = L7.new >> } >> >> results in memw(R7) being zero-intialized, compared to L6.new which >> would correctly write the lower bytes of the pair. > The packet in the test is combine(L0, L2), and the store is > mem(R7) = L7.new. > > Also s/intialized/initialized/. > > [...] > >> + if (regno == lreg || >> + (GET_ATTRIB(insn->opcode, A_HLX_PAIRED_ALU) && regno + 1 == lreg)) { >> return i; >> } > This finds the producer now, but decode_fill_newvalue_regno() then > overwrites the consumer's register with the producer's dest register: > > `packet->insn[i].regno[use_regidx] = packet->insn[def_idx].regno[dst_idx];` > > For a pair, that is the base register, so L7.new becomes L6.new and > the store writes the low half of the pair instead of the high half. > > Also, not all instructions that write a pair have A_HLX_PAIRED_ALU, > e.g. LX_assign_rw (Ldd16.w=Rt32.w). A high .new store from those > still writes zeros. > > [...] > >> + hlx_put_v(0, l_lo); >> + hlx_put_v(2, l_hi); > [...] > >> + for (int j = 0; j < HLX_HALF_ELEMS; j++) { >> + expected[j] = VAL_A; >> + } >> + check_h("LX_assign_w (hi only)", buf_a, expected, HLX_HALF_ELEMS); >> +} > L0 holds the low halves of VAL_W (0x5678), and combine(L0, L2) puts > L0 into L7. So L7.new must store 0x5678, but the test expects VAL_A > (0x1234), which is the L6 value. > > The test passes because L6.new is used instead of L7.new. > > IMHO: Maybe we should have a mechanism that creates an error > if a .new value is used, but that .new value isn't even in the packet. Like it This sounds like it's either well-defined behavior that raises an invalid packet exception or implicitly/explicitly undefined behavior for which we can log a guest error. If this condition represents a problem with the decoder it can just be an assertion, but it sounds like that's not the case. For HVX many ill-formed packets are considered to be undefined and do not raise exceptions. HLX may be similar, we'll have to check. > is happening here. L6.new is computed, but it isn't even used in the packet. > Maybe poisoning it somehow. But that's just me thinking out loud, doesn't > need to go into this patch series.
On 11/5/2026 5:12 PM, Brian Cain wrote: > > On 11/5/2026 11:58 AM, Marco Liebel wrote: >> On Thu, Nov 5, 2026 at 5:41 AM Anton Johansson <anjo@rev.ng> wrote: >>> Otherwise, the following packet >>> >>> { >>> L7:6 = combine(L0, L1) >>> memw(R7) = L7.new >>> } >>> >>> results in memw(R7) being zero-intialized, compared to L6.new which >>> would correctly write the lower bytes of the pair. >> The packet in the test is combine(L0, L2), and the store is >> mem(R7) = L7.new. >> >> Also s/intialized/initialized/. >> >> [...] >> >>> + if (regno == lreg || >>> + (GET_ATTRIB(insn->opcode, A_HLX_PAIRED_ALU) && regno + >>> 1 == lreg)) { >>> return i; >>> } >> This finds the producer now, but decode_fill_newvalue_regno() then >> overwrites the consumer's register with the producer's dest register: >> >> `packet->insn[i].regno[use_regidx] = >> packet->insn[def_idx].regno[dst_idx];` >> >> For a pair, that is the base register, so L7.new becomes L6.new and >> the store writes the low half of the pair instead of the high half. >> >> Also, not all instructions that write a pair have A_HLX_PAIRED_ALU, >> e.g. LX_assign_rw (Ldd16.w=Rt32.w). A high .new store from those >> still writes zeros. >> >> [...] >> >>> + hlx_put_v(0, l_lo); >>> + hlx_put_v(2, l_hi); >> [...] >> >>> + for (int j = 0; j < HLX_HALF_ELEMS; j++) { >>> + expected[j] = VAL_A; >>> + } >>> + check_h("LX_assign_w (hi only)", buf_a, expected, HLX_HALF_ELEMS); >>> +} >> L0 holds the low halves of VAL_W (0x5678), and combine(L0, L2) puts >> L0 into L7. So L7.new must store 0x5678, but the test expects VAL_A >> (0x1234), which is the L6 value. >> >> The test passes because L6.new is used instead of L7.new. >> >> IMHO: Maybe we should have a mechanism that creates an error >> if a .new value is used, but that .new value isn't even in the >> packet. Like it > > This sounds like it's either well-defined behavior that raises an > invalid packet exception or implicitly/explicitly undefined behavior > for which we can log a guest error. If this condition represents a > problem with the decoder it can just be an assertion, but it sounds > like that's not the case. > It was a little unclear to me whether ".new value is used ... isn't even in the packet" represented an encoding problem or a design error/decoding problem in QEMU. Marco and I talked in person and it's clear to me now that it's the latter. "maybe poisoning it somehow" - yes, if there's an easy way for us to make such an assertion we should definitely do that. That sounds like it may be worth a look (by someone, at some time - agreed not necessarily in scope for this patch review). > For HVX many ill-formed packets are considered to be undefined and do > not raise exceptions. HLX may be similar, we'll have to check. > >> is happening here. L6.new is computed, but it isn't even used in the >> packet. >> Maybe poisoning it somehow. But that's just me thinking out loud, >> doesn't >> need to go into this patch series.
diff --git a/target/hexagon/decode.c b/target/hexagon/decode.c index d48630da87..8921ff765d 100644 --- a/target/hexagon/decode.c +++ b/target/hexagon/decode.c @@ -110,9 +110,25 @@ static int hlx_find_new_value_producer(Packet *packet, int consumer, { for (int i = 0; i < packet->num_insns; i++) { Insn *insn = &packet->insn[i]; + uint8_t regno; - if (i != consumer && GET_ATTRIB(insn->opcode, A_HLX) && - insn->dest_idx != -1 && insn->regno[insn->dest_idx] == lreg) { + /* + * Skip ourselves, instructions without return values, and + * any non-HLX instructions. + */ + if (i == consumer || !GET_ATTRIB(insn->opcode, A_HLX) || + insn->dest_idx == -1) { + continue; + } + + regno = insn->regno[insn->dest_idx]; + + /* + * Compare against the base register number, and against the top + * register for instructions returning pairs. + */ + if (regno == lreg || + (GET_ATTRIB(insn->opcode, A_HLX_PAIRED_ALU) && regno + 1 == lreg)) { return i; } } diff --git a/tests/tcg/hexagon/hlx_assign_conv.c b/tests/tcg/hexagon/hlx_assign_conv.c index 8192882b8e..aef82dd63b 100644 --- a/tests/tcg/hexagon/hlx_assign_conv.c +++ b/tests/tcg/hexagon/hlx_assign_conv.c @@ -120,6 +120,40 @@ static void test_assign_rw(void) check_wp("LX_assign_rw", pw_out_lo, pw_out_hi, expected_w, HLX_HALF_ELEMS); } +static void test_combine_assign_hi(void) +{ + /* + * Tests that a combine operation acts as a producer of a .new value for + * the high vector in a pair. + */ + HLX_Vector l_lo; + HLX_Vector l_hi; + + fill_w(pw_a_lo, pw_a_hi, VAL_W); + + l_lo = Q6_L_tmp_mem_A(pw_a_lo); + l_hi = Q6_L_tmp_mem_A(pw_a_hi); + + hlx_put_v(0, l_lo); + hlx_put_v(2, l_hi); + /* + * { + * L7:6 = combine(L0, L1) + * memw(R7) = L7.new + * } + */ + asm volatile(HLX_PTRS HLX_LD0 HLX_LD2 + ".word 0xef24602d\n" + ".word 0xa487c007\n" + : : [stage] "r"(hlx_stage) : HLX_CLOBBERS); + Q6_mem_Ku16_new_AL(buf_a, hlx_get_v(7)); + + for (int j = 0; j < HLX_HALF_ELEMS; j++) { + expected[j] = VAL_A; + } + check_h("LX_assign_w (hi only)", buf_a, expected, HLX_HALF_ELEMS); +} + static void test_combine_w(void) { @@ -336,6 +370,7 @@ int main(void) test_assign_s(); test_assign_u(); test_assign_rw(); + test_combine_assign_hi(); /* Combine and mux */ test_combine_w();
Otherwise, the following packet { L7:6 = combine(L0, L1) memw(R7) = L7.new } results in memw(R7) being zero-intialized, compared to L6.new which would correctly write the lower bytes of the pair. Fixes: ef81d1b047337e81 ("target/hexagon: decode HLX packets and add load and store") Signed-off-by: Anton Johansson <anjo@rev.ng> --- target/hexagon/decode.c | 20 +++++++++++++++-- tests/tcg/hexagon/hlx_assign_conv.c | 35 +++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 2 deletions(-)