[PATCH] target/hexagon: Explicitly pass GP to helpers

Anton Johansson via qemu development posted 1 patch 4 days, 13 hours ago
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(-)
[PATCH] target/hexagon: Explicitly pass GP to helpers
Posted by Anton Johansson via qemu development 4 days, 13 hours ago
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.

Signed-off-by: Anton Johansson <anjo@rev.ng>
---
 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(-)

diff --git a/target/hexagon/macros.h b/target/hexagon/macros.h
index 2748e26d6c..9187b02e6c 100644
--- a/target/hexagon/macros.h
+++ b/target/hexagon/macros.h
@@ -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)
diff --git a/target/hexagon/attribs_def.h.inc b/target/hexagon/attribs_def.h.inc
index 71c6f04912..bef7ff45d9 100644
--- a/target/hexagon/attribs_def.h.inc
+++ b/target/hexagon/attribs_def.h.inc
@@ -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")
diff --git a/target/hexagon/hex_common.py b/target/hexagon/hex_common.py
index f85f063f52..24dcdb5ce1 100755
--- a/target/hexagon/hex_common.py
+++ b/target/hexagon/hex_common.py
@@ -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",
-- 
2.52.0
Re: [PATCH] target/hexagon: Explicitly pass GP to helpers
Posted by Brian Cain 4 days, 12 hours ago
On 11/18/2026 8:44 AM, Anton Johansson wrote:
> 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.
>
> Signed-off-by: Anton Johansson <anjo@rev.ng>
> ---
>   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(-)

Reviewed-by: Brian Cain <brian.cain@oss.qualcomm.com>