Skip to contentSkip to conversation

target/hexagon: Explicitly pass GP to helpers

PATCH In review Anton Johansson via qemu development 2 participants 2 messages Nov 18

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 target/hexagon: Explicitly pass GP to helpers

helpers using fREAD_GP() are broken and do not account for the presence of extenders which change the addressing mode from GP-relative to absolute. Explicitly pass GP to helpers and check for expanders at the call-site.

---
 target/hexagon/macros.h          |  8 +-------
 target/hexagon/attribs_def.h.inc |  1 +
 target/hexagon/hex_common.py     | 11 +++++++++++
 3 files changed, 13 insertions(+), 7 deletions(-)
target/hexagon/macros.h +1 -7
index 2748e26d6c..9187b02e6c 100644
@@ -347,13 +347,7 @@ static inline TCGv gen_read_ireg(TCGv result, TCGv val, int shift)
 #define fREAD_SA0 (env->gpr[HEX_REG_SA0])
 #define fREAD_SA1 (env->gpr[HEX_REG_SA1])
 #define fREAD_FP() (env->gpr[HEX_REG_FP])
-#ifdef FIXME
-/* Figure out how to get insn->extension_valid to helper */
-#define fREAD_GP() \
-    (insn->extension_valid ? 0 : env->gpr[HEX_REG_GP])
-#else
-#define fREAD_GP() (env->gpr[HEX_REG_GP])
-#endif
+#define fREAD_GP() (GP)
 #define fREAD_PC() (PC)
 
 #define fREAD_P0() (P0)
target/hexagon/attribs_def.h.inc +1 -0
index 71c6f04912..bef7ff45d9 100644
@@ -133,6 +133,7 @@ DEF_ATTRIB(IMPLICIT_WRITES_LR, "Writes the link register", "", "UREG.LR")
 DEF_ATTRIB(IMPLICIT_READS_PC, "Reads the program counter", "UREG.PC", "")
 DEF_ATTRIB(IMPLICIT_WRITES_SP, "Writes the stack pointer", "", "UREG.SP")
 DEF_ATTRIB(IMPLICIT_READS_SP, "Reads the stack pointer", "UREG.SP", "")
+DEF_ATTRIB(IMPLICIT_READS_GP, "Reads the global pointer", "UREG.GP", "")
 DEF_ATTRIB(IMPLICIT_WRITES_FP, "Writes the frame pointer", "", "UREG.FP")
 DEF_ATTRIB(IMPLICIT_WRITES_LC0, "Writes loop count for loop 0", "", "UREG.LC0")
 DEF_ATTRIB(IMPLICIT_WRITES_LC1, "Writes loop count for loop 1", "", "UREG.LC1")
target/hexagon/hex_common.py +11 -0
index f85f063f52..24dcdb5ce1 100755
@@ -142,6 +142,7 @@ def calculate_attribs():
     add_qemu_macro_attrib('fLSBNEW1NOT', 'A_IMPLICIT_READS_P1')
     add_qemu_macro_attrib('fREAD_P3', 'A_IMPLICIT_READS_P3')
     add_qemu_macro_attrib('fREAD_SP', 'A_IMPLICIT_READS_SP')
+    add_qemu_macro_attrib('fREAD_GP', 'A_IMPLICIT_READS_GP')
 
     # Recurse down macros, find attributes from sub-macros
     macroValues = list(macros.values())
@@ -246,6 +247,10 @@ def need_sp(tag):
     return "A_IMPLICIT_READS_SP" in attribdict[tag]
 
 
+def need_gp(tag):
+    return "A_IMPLICIT_READS_GP" in attribdict[tag]
+
+
 def is_hvx_insn(tag):
     return "A_CVI" in attribdict[tag]
 
@@ -2210,6 +2215,12 @@ def helper_args(tag, regs, imms):
             "hex_gpr[HEX_REG_SP]",
             "uint32_t SP"
         ))
+    if need_gp(tag):
+        args.append(HelperArg(
+            "i32",
+            "insn->extension_valid ? tcg_constant_tl(0) : hex_gpr[HEX_REG_GP]",
+            "uint32_t GP"
+        ))
     if need_slot(tag):
         args.append(HelperArg(
             "i32",
Signature · 1 line
2.52.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Anton Johansson

helpers using fREAD_GP() are broken and do not account for the presence of extenders which change the addressing mode from GP-relative to absolute. Explicitly pass GP to helpers and check for expanders at the call-site.

---
  target/hexagon/macros.h          |  8 +-------
  target/hexagon/attribs_def.h.inc |  1 +
  target/hexagon/hex_common.py     | 11 +++++++++++
  3 files changed, 13 insertions(+), 7 deletions(-)