Skip to contentSkip to conversation

Hexagon (target/hexagon) Additional instructions handled by idef-parser

PATCH Superseded Taylor Simpson 2 participants 2 messages Apr 7, 2023 – Apr 11, 2023

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Hexagon (target/hexagon) Additional instructions handled by idef-parser

Currently, idef-parser skips all floating point instructions. However, there are some floating point instructions that can be handled.

The following instructions are now parsed

    F2_sfimm_p
    F2_sfimm_n
    F2_dfimm_p
    F2_dfimm_n
    F2_dfmpyll
    F2_dfmpylh

To make these instructions work, we fix some bugs in parser-helpers.c
gen_rvalue_extend
gen_cast_op

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

---
 target/hexagon/idef-parser/parser-helpers.c | 16 +++---
 tests/tcg/hexagon/fpstuff.c                 | 54 +++++++++++++++++++++
 target/hexagon/gen_idef_parser_funcs.py     | 10 +++-
 3 files changed, 72 insertions(+), 8 deletions(-)
target/hexagon/idef-parser/parser-helpers.c +9 -7
index 18cde6a1be..0b160e6f58 100644
@@ -386,13 +386,10 @@ HexValue gen_rvalue_extend(Context *c, YYLTYPE *locp, HexValue *rvalue)
 
     if (rvalue->type == IMMEDIATE) {
         HexValue res = gen_imm_qemu_tmp(c, locp, 64, rvalue->signedness);
-        bool is_unsigned = (rvalue->signedness == UNSIGNED);
-        const char *sign_suffix = is_unsigned ? "u" : "";
         gen_c_int_type(c, locp, 64, rvalue->signedness);
-        OUT(c, locp, " ", &res, " = ");
-        OUT(c, locp, "(", sign_suffix, "int64_t) ");
-        OUT(c, locp, "(", sign_suffix, "int32_t) ");
-        OUT(c, locp, rvalue, ";\n");
+        OUT(c, locp, " ", &res, " = (");
+        gen_c_int_type(c, locp, 64, rvalue->signedness);
+        OUT(c, locp, ")", rvalue, ";\n");
         return res;
     } else {
         HexValue res = gen_tmp(c, locp, 64, rvalue->signedness);
@@ -963,7 +960,12 @@ HexValue gen_cast_op(Context *c,
     if (src->bit_width == target_width) {
         return *src;
     } else if (src->type == IMMEDIATE) {
-        HexValue res = *src;
+        HexValue res;
+        if (src->bit_width < target_width) {
+            res = gen_rvalue_extend(c, locp, src);
+        } else {
+            res = *src;
+        }
         res.bit_width = target_width;
         res.signedness = signedness;
         return res;
tests/tcg/hexagon/fpstuff.c +54 -0

72 lines not on this page · raw message

target/hexagon/gen_idef_parser_funcs.py +9 -1
index 917753d6d8..9bed7ee55e 100644
@@ -89,7 +89,15 @@ def main():
                 continue
             if ( tag.startswith('V6_') ) :
                 continue
-            if ( tag.startswith('F') ) :
+            if ( tag.startswith('F') and
+                 tag not in {
+                     'F2_sfimm_p',
+                     'F2_sfimm_n',
+                     'F2_dfimm_p',
+                     'F2_dfimm_n',
+                     'F2_dfmpyll',
+                     'F2_dfmpylh'
+                 }):
                 continue
             if ( tag.endswith('_locked') ) :
                 continue
Signature · 1 line
2.25.1
Reviewed-by Anton Johansson Tested-by Anton Johansson on v1 1/1
#1 lore raw
Quoted 15 lines · Taylor Simpson

Currently, idef-parser skips all floating point instructions. However, there are some floating point instructions that can be handled.

The following instructions are now parsed

     F2_sfimm_p
     F2_sfimm_n
     F2_dfimm_p
     F2_dfimm_n
     F2_dfmpyll
     F2_dfmpylh

To make these instructions work, we fix some bugs in parser-helpers.c
gen_rvalue_extend
gen_cast_op

Quoted 8 lines

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

---
  target/hexagon/idef-parser/parser-helpers.c | 16 +++---
  tests/tcg/hexagon/fpstuff.c                 | 54 +++++++++++++++++++++
  target/hexagon/gen_idef_parser_funcs.py     | 10 +++-
  3 files changed, 72 insertions(+), 8 deletions(-)

This patch looks good, nice catch on the bugs!