Commit d84a208320 for qemu.org
commit d84a20832019bc5036d9a1680376607027819910
Author: Marco Liebel <marco.liebel@oss.qualcomm.com>
Date: Tue Nov 24 11:03:08 2026 -0800
target/hexagon: read the old predicate value through C4
Track C4 reads as reads of all four predicates. This prevents the
packet short circuit from exposing a predicate result to an old-value
control register read.
Signed-off-by: Marco Liebel <marco.liebel@oss.qualcomm.com>
Reviewed-by: Brian Cain <brian.cain@oss.qualcomm.com>
Reviewed-by: Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com>
Signed-off-by: Brian Cain <brian.cain@oss.qualcomm.com>
diff --git a/target/hexagon/translate.h b/target/hexagon/translate.h
index bc3b49ab06..c988c85f33 100644
--- a/target/hexagon/translate.h
+++ b/target/hexagon/translate.h
@@ -248,7 +248,11 @@ static inline void ctx_log_reg_write_pair(DisasContext *ctx, int rnum,
static inline void ctx_log_reg_read(DisasContext *ctx, int rnum)
{
- if (test_bit(rnum, ctx->regs_written)) {
+ if (rnum == HEX_REG_P3_0_ALIASED) {
+ for (int i = 0; i < NUM_PREGS; i++) {
+ ctx_log_pred_read(ctx, i);
+ }
+ } else if (test_bit(rnum, ctx->regs_written)) {
ctx->read_after_write = true;
}
}
diff --git a/tests/tcg/hexagon/meson.build b/tests/tcg/hexagon/meson.build
index 70f6475656..b3635be3fc 100644
--- a/tests/tcg/hexagon/meson.build
+++ b/tests/tcg/hexagon/meson.build
@@ -96,6 +96,7 @@ tests += {
'misc.c': {'cflags': [cflags, '-mv71', '-O2']},
'multiple-writes.c': {'cflags': [cflags, '-mhvx']},
'overflow.c': {'cflags': cflags, 'exe_name': 'hex-overflow'},
+ 'packet_user.c': {'cflags': [cflags, '-O2']},
'preg_alias.c': {'cflags': cflags},
'dual_stores.c': {'cflags': cflags},
'framekey.c': {'cflags': cflags},
diff --git a/tests/tcg/hexagon/packet_user.c b/tests/tcg/hexagon/packet_user.c
new file mode 100644
index 0000000000..27ac17de74
--- /dev/null
+++ b/tests/tcg/hexagon/packet_user.c
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include <stdio.h>
+#include <stdint.h>
+
+static int err;
+
+#include "hex_test.h"
+
+static void test_predicate_read(void)
+{
+ unsigned old, new;
+
+ asm volatile(
+ "r0 = #0x12\n"
+ "p3:0 = r0\n"
+ "{\n"
+ " p0 = cmp.eq(r0,r0)\n"
+ " %[old] = p3:0\n"
+ "}\n"
+ "%[new] = p3:0\n"
+ : [old] "=r"(old), [new] "=r"(new)
+ : : "r0", "p0", "p1", "p2", "p3"
+ );
+ /* Packet reads old C4, then commits P0. */
+ check32(old, 0x12);
+ check32(new, 0xff);
+}
+
+int main(void)
+{
+ test_predicate_read();
+ puts(err ? "FAIL" : "PASS");
+ return err != 0;
+}