Skip to contentSkip to conversation

Hexagon (target/hexagon) Fix predicated assignment to .tmp and .cur

PATCH Superseded Taylor Simpson 1 participant 1 message Oct 10, 2022

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 Hexagon (target/hexagon) Fix predicated assignment to .tmp and .cur

*** Changes in v2 ***
Update test case to use both true and false predicates Add fix for .cur

Here are example instructions with a predicated .tmp/.cur assignment

    if (p1) v12.tmp = vmem(r7 + #0)
    if (p0) v12.cur = vmem(r9 + #0)

The .tmp/.cur indicates that references to v12 in the same packet take the result of the load. However, when the predicate is false, the value at the start of the packet should be used. After the packet commits, the .tmp value is dropped, but the .cur value is maintained.

To fix this bug, we preload the original value from the HVX register into the temporary used for the result.

Test cases added to tests/tcg/hexagon/hvx_misc.c

---
 target/hexagon/translate.h      | 12 +++++-
 tests/tcg/hexagon/hvx_misc.c    | 72 +++++++++++++++++++++++++++++++++
 target/hexagon/gen_tcg_funcs.py | 16 ++++++++
 3 files changed, 99 insertions(+), 1 deletion(-)
target/hexagon/translate.h +11 -1
index a245172827..2d563cea14 100644
@@ -1,5 +1,5 @@
 /*
- *  Copyright(c) 2019-2021 Qualcomm Innovation Center, Inc. All Rights Reserved.
+ *  Copyright(c) 2019-2022 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
@@ -83,6 +83,16 @@ static inline bool is_preloaded(DisasContext *ctx, int num)
     return test_bit(num, ctx->regs_written);
 }
 
+static inline bool is_tmp_vreg_preloaded(DisasContext *ctx, int num)
+{
+    return test_bit(num, ctx->vregs_updated_tmp);
+}
+
+static inline bool is_future_vreg_preloaded(DisasContext *ctx, int num)
+{
+    return test_bit(num, ctx->vregs_select);
+}
+
 intptr_t ctx_future_vreg_off(DisasContext *ctx, int regnum,
                              int num, bool alloc_ok);
 intptr_t ctx_tmp_vreg_off(DisasContext *ctx, int regnum,
tests/tcg/hexagon/hvx_misc.c +72 -0

84 lines not on this page · raw message

target/hexagon/gen_tcg_funcs.py +16 -0
index 6dea02b0b9..de0e06ab71 100755
@@ -173,6 +173,22 @@ def genptr_decl(f, tag, regtype, regid, regno):
                 f.write("        ctx_future_vreg_off(ctx, %s%sN," % \
                     (regtype, regid))
                 f.write(" 1, true);\n");
+            if regid != "y" and 'A_CONDEXEC' in hex_common.attribdict[tag]:
+                if hex_common.is_tmp_result(tag):
+                    preload_test_fn = "is_tmp_vreg_preloaded"
+                else:
+                    preload_test_fn = "is_future_vreg_preloaded"
+                f.write("    if (!%s(ctx, %s)) {\n" % (preload_test_fn, regN))
+                f.write("        intptr_t src_off =")
+                f.write(" offsetof(CPUHexagonState, VRegs[%s%sN]);\n"% \
+                                     (regtype, regid))
+                f.write("        tcg_gen_gvec_mov(MO_64, %s%sV_off,\n" % \
+                                     (regtype, regid))
+                f.write("                         src_off,\n")
+                f.write("                         sizeof(MMVector),\n")
+                f.write("                         sizeof(MMVector));\n")
+                f.write("    }\n")
+
             if (not hex_common.skip_qemu_helper(tag)):
                 f.write("    TCGv_ptr %s%sV = tcg_temp_new_ptr();\n" % \
                     (regtype, regid))
Signature · 1 line
2.17.1