[PATCH 1/6] target/hexagon: handle .new values

Brian Cain posted 6 patches 7 months, 2 weeks ago
There is a newer version of this series
[PATCH 1/6] target/hexagon: handle .new values
Posted by Brian Cain 7 months, 2 weeks ago
From: Brian Cain <bcain@quicinc.com>

Signed-off-by: Brian Cain <brian.cain@oss.qualcomm.com>
---
 target/hexagon/hex_common.py | 27 ++++++++++++++++++++++-----
 1 file changed, 22 insertions(+), 5 deletions(-)

diff --git a/target/hexagon/hex_common.py b/target/hexagon/hex_common.py
index 758e5fd12d..242dee3731 100755
--- a/target/hexagon/hex_common.py
+++ b/target/hexagon/hex_common.py
@@ -349,6 +349,12 @@ def helper_arg(self):
             self.reg_tcg(),
             f"{self.helper_arg_type()} {self.helper_arg_name()}"
         )
+    def from_subtype(self, subtype):
+        if subtype == "":
+            return self
+        raise Exception(
+            f"unknown subtype '{subtype}' on generic Register class")
+
 
 #
 # Every register is either Single or Pair or Hvx
@@ -1070,11 +1076,22 @@ def init_registers():
     for reg in new_regs:
         new_registers[f"{reg.regtype}{reg.regid}"] = reg
 
-def get_register(tag, regtype, regid):
-    if f"{regtype}{regid}V" in semdict[tag]:
-        return registers[f"{regtype}{regid}"]
-    else:
-        return new_registers[f"{regtype}{regid}"]
+def is_new_reg(tag, regid):
+    if regid[0] in "NO":
+        return True
+    return regid[0] == "P" and \
+           f"{regid}N" in semdict[tag] and \
+           f"{regid}V" not in semdict[tag]
+
+def get_register(tag, regtype, regid, subtype=""):
+    regid = f"{regtype}{regid}"
+    is_new = is_new_reg(tag, regid)
+    try:
+        reg = new_registers[regid] if is_new else registers[regid]
+    except KeyError:
+        raise Exception(f"Unknown {'new ' if is_new else ''}register {regid}" +\
+                        f"from '{tag}' with syntax '{semdict[tag]}'") from None
+    return reg.from_subtype(subtype)
 
 def helper_ret_type(tag, regs):
     ## If there is a scalar result, it is the return type
-- 
2.34.1

Re: [PATCH 1/6] target/hexagon: handle .new values
Posted by Matheus Tavares Bernardino 7 months, 2 weeks ago
On Thu,  3 Apr 2025 19:51:58 -0700 Brian Cain <brian.cain@oss.qualcomm.com> wrote:
>
> From: Brian Cain <bcain@quicinc.com>

Perhaps it would be best to reset the autorship here to
brian.cain@oss.qualcomm.com?

> Signed-off-by: Brian Cain <brian.cain@oss.qualcomm.com>
> ---
>  target/hexagon/hex_common.py | 27 ++++++++++++++++++++++-----
>  1 file changed, 22 insertions(+), 5 deletions(-)
> 
> diff --git a/target/hexagon/hex_common.py b/target/hexagon/hex_common.py
> index 758e5fd12d..242dee3731 100755
> --- a/target/hexagon/hex_common.py
> +++ b/target/hexagon/hex_common.py
> @@ -349,6 +349,12 @@ def helper_arg(self):
>              self.reg_tcg(),
>              f"{self.helper_arg_type()} {self.helper_arg_name()}"
>          )
> +    def from_subtype(self, subtype):
> +        if subtype == "":
> +            return self
> +        raise Exception(
> +            f"unknown subtype '{subtype}' on generic Register class")
> +

We use this method for other reg types downstream (HVX). Since, in this patch
series, we are not really using from_subtype (get_register is always called
with subtype == ""), I think we could either exclude it from this series or
evaluate how to also upstream its use for HVX.
Re: [PATCH 1/6] target/hexagon: handle .new values
Posted by Brian Cain 7 months, 2 weeks ago
On 4/4/2025 8:25 AM, Matheus Tavares Bernardino wrote:
> On Thu,  3 Apr 2025 19:51:58 -0700 Brian Cain <brian.cain@oss.qualcomm.com> wrote:
>> From: Brian Cain <bcain@quicinc.com>
> Perhaps it would be best to reset the autorship here to
> brian.cain@oss.qualcomm.com?


Good catch -- will do.


>> Signed-off-by: Brian Cain <brian.cain@oss.qualcomm.com>
>> ---
>>   target/hexagon/hex_common.py | 27 ++++++++++++++++++++++-----
>>   1 file changed, 22 insertions(+), 5 deletions(-)
>>
>> diff --git a/target/hexagon/hex_common.py b/target/hexagon/hex_common.py
>> index 758e5fd12d..242dee3731 100755
>> --- a/target/hexagon/hex_common.py
>> +++ b/target/hexagon/hex_common.py
>> @@ -349,6 +349,12 @@ def helper_arg(self):
>>               self.reg_tcg(),
>>               f"{self.helper_arg_type()} {self.helper_arg_name()}"
>>           )
>> +    def from_subtype(self, subtype):
>> +        if subtype == "":
>> +            return self
>> +        raise Exception(
>> +            f"unknown subtype '{subtype}' on generic Register class")
>> +
> We use this method for other reg types downstream (HVX). Since, in this patch
> series, we are not really using from_subtype (get_register is always called
> with subtype == ""), I think we could either exclude it from this series or
> evaluate how to also upstream its use for HVX.