Implement an HMX accumulator clear instruction - mxclracc.

Reviewed-by: Pierrick Bouvier <[email protected]>
Signed-off-by: Brian Cain <[email protected]>
---
 target/hexagon/gen_tcg_hmx.h            | 13 +++++++++++++
 target/hexagon/helper.h                 |  2 ++
 target/hexagon/genptr.c                 |  1 +
 target/hexagon/op_helper.c              | 12 ++++++++++++
 target/hexagon/translate.c              | 16 +++++++++++++++-
 target/hexagon/gen_idef_parser_funcs.py |  6 ++++++
 target/hexagon/hex_common.py            |  2 ++
 target/hexagon/meson.build              | 23 +++++++++++++----------
 8 files changed, 64 insertions(+), 11 deletions(-)
 create mode 100644 target/hexagon/gen_tcg_hmx.h

diff --git a/target/hexagon/gen_tcg_hmx.h b/target/hexagon/gen_tcg_hmx.h
new file mode 100644
index 00000000000..e20b396b488
--- /dev/null
+++ b/target/hexagon/gen_tcg_hmx.h
@@ -0,0 +1,13 @@
+/*
+ * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#ifndef HEXAGON_GEN_TCG_HMX_H
+#define HEXAGON_GEN_TCG_HMX_H
+
+#define fGEN_TCG_M8_mxclracc(SHORTCODE) \
+    do { } while (0)
+
+#endif
diff --git a/target/hexagon/helper.h b/target/hexagon/helper.h
index 1ced8c56513..292ca8eb7c5 100644
--- a/target/hexagon/helper.h
+++ b/target/hexagon/helper.h
@@ -63,6 +63,8 @@ DEF_HELPER_FLAGS_4(hlx_gvec_absdiff_uh16, TCG_CALL_NO_RWG,
 /* GVec helper for a halfword arithmetic shift by 15. */
 DEF_HELPER_FLAGS_3(hlx_gvec_sari15_h16, TCG_CALL_NO_RWG, void, ptr, ptr, i32)
 
+DEF_HELPER_1(mxclracc, void, env)
+
 /* Floating point */
 DEF_HELPER_3(conv_sf2df, f64, env, f32, i32)
 DEF_HELPER_3(conv_df2sf, f32, env, f64, i32)
diff --git a/target/hexagon/genptr.c b/target/hexagon/genptr.c
index e4acb439dd0..addb5d23d90 100644
--- a/target/hexagon/genptr.c
+++ b/target/hexagon/genptr.c
@@ -33,6 +33,7 @@
 #undef QEMU_GENERATE
 #include "gen_tcg.h"
 #include "gen_tcg_hvx.h"
+#include "gen_tcg_hmx.h"
 #ifndef CONFIG_USER_ONLY
 #include "gen_tcg_sys.h"
 #endif
diff --git a/target/hexagon/op_helper.c b/target/hexagon/op_helper.c
index 62e38c68754..0a16778e5e2 100644
--- a/target/hexagon/op_helper.c
+++ b/target/hexagon/op_helper.c
@@ -2149,6 +2149,18 @@ void HELPER(pending_interrupt)(CPUHexagonState *env)
 #define BOGUS_HELPER(tag) \
     printf("ERROR: bogus helper: " #tag "\n")
 
+void HELPER(mxclracc)(CPUHexagonState *env)
+{
+    HmxState *hmx = env->hmx_state;
+    int i;
+
+    g_assert(hmx);
+
+    for (i = 0; i < HMX_NUM_ACC_SETS; i++) {
+        memset(&hmx->acc[i].fxp_primary, 0, sizeof(hmx->acc[i].fxp_primary));
+    }
+}
+
 #include "helper_funcs_generated.c.inc"
 
 #define DO_ABSDIFF(NAME, TYPE, UTYPE) \
diff --git a/target/hexagon/translate.c b/target/hexagon/translate.c
index 015f0958fd0..8ab28d40d34 100644
--- a/target/hexagon/translate.c
+++ b/target/hexagon/translate.c
@@ -922,7 +922,8 @@ static void gen_start_packet(DisasContext *ctx)
 
     if (ctx->pkt.pkt_has_hmx) {
         for (i = 0; i < ctx->pkt.num_insns; i++) {
-            if (GET_ATTRIB(ctx->pkt.insn[i].opcode, A_HMX)) {
+            if (GET_ATTRIB(ctx->pkt.insn[i].opcode, A_HMX) &&
+                ctx->pkt.insn[i].opcode != M8_mxclracc) {
                 qemu_log_mask(LOG_UNIMP, "'%s' is not implemented\n",
                               opcode_names[ctx->pkt.insn[i].opcode]);
             }
@@ -1299,7 +1300,17 @@ static void gen_commit_hlx(DisasContext *ctx)
         int rnum = ctx->lreg_log[i];
         gen_helper_hlx_commit_reg(tcg_env, tcg_constant_i32(rnum));
     }
+}
 
+static void gen_commit_hmx(DisasContext *ctx)
+{
+    int i;
+
+    for (i = 0; i < ctx->pkt.num_insns; i++) {
+        if (ctx->pkt.insn[i].opcode == M8_mxclracc) {
+            gen_helper_mxclracc(tcg_env);
+        }
+    }
 }
 
 static void update_exec_counters(DisasContext *ctx)
@@ -1444,6 +1455,9 @@ static void gen_commit_packet(DisasContext *ctx)
     if (ctx->pkt.pkt_has_hlx) {
         gen_commit_hlx(ctx);
     }
+    if (ctx->pkt.pkt_has_hmx) {
+        gen_commit_hmx(ctx);
+    }
     update_exec_counters(ctx);
 
     if (ctx->pkt.vhist_insn != NULL) {
diff --git a/target/hexagon/gen_idef_parser_funcs.py 
b/target/hexagon/gen_idef_parser_funcs.py
index 3f5879ce195..494353e1ef5 100644
--- a/target/hexagon/gen_idef_parser_funcs.py
+++ b/target/hexagon/gen_idef_parser_funcs.py
@@ -48,9 +48,11 @@ def main():
         "Emit instruction implementations that can be fed to idef-parser"
     )
     parser.add_argument("semantics", help="semantics file")
+    parser.add_argument("overrides_hmx", help="HMX overrides file")
     parser.add_argument("out", help="output file")
     args = parser.parse_args()
     hex_common.read_semantics_file(args.semantics)
+    hex_common.read_overrides_file(args.overrides_hmx)
     hex_common.calculate_attribs()
     hex_common.init_registers()
     tagregs = hex_common.get_tagregs()
@@ -117,6 +119,10 @@ def main():
                 continue
             if tag.startswith("V6_"):
                 continue
+            ## Skip the HMX instructions implemented by an override
+            if ("A_HMX" in hex_common.attribdict[tag] and
+                hex_common.skip_qemu_helper(tag)):
+                continue
             if ( tag.startswith("F") and
                  tag not in {
                      "F2_sfimm_p",
diff --git a/target/hexagon/hex_common.py b/target/hexagon/hex_common.py
index adf739f8f53..f85f063f52d 100755
--- a/target/hexagon/hex_common.py
+++ b/target/hexagon/hex_common.py
@@ -2232,6 +2232,7 @@ def parse_common_args(desc):
     parser.add_argument("overrides", help="overrides file")
     parser.add_argument("overrides_vec", help="vector overrides file")
     parser.add_argument("overrides_sys", help="system overrides file")
+    parser.add_argument("overrides_hmx", help="matrix overrides file")
     parser.add_argument("out", help="output file")
     parser.add_argument("--idef-parser",
                         help="file of instructions translated by idef-parser")
@@ -2240,6 +2241,7 @@ def parse_common_args(desc):
     read_overrides_file(args.overrides)
     read_overrides_file(args.overrides_vec)
     read_overrides_file(args.overrides_sys)
+    read_overrides_file(args.overrides_hmx)
     if args.idef_parser:
         read_idef_parser_enabled_file(args.idef_parser)
     calculate_attribs()
diff --git a/target/hexagon/meson.build b/target/hexagon/meson.build
index 98c511bcf89..db65edcba54 100644
--- a/target/hexagon/meson.build
+++ b/target/hexagon/meson.build
@@ -21,6 +21,7 @@ hex_common_py = 'hex_common.py'
 gen_tcg_h = meson.current_source_dir() / 'gen_tcg.h'
 gen_tcg_hvx_h = meson.current_source_dir() / 'gen_tcg_hvx.h'
 gen_tcg_sys_h = meson.current_source_dir() / 'gen_tcg_sys.h'
+gen_tcg_hmx_h = meson.current_source_dir() / 'gen_tcg_hmx.h'
 idef_parser_dir = meson.current_source_dir() / 'idef-parser'
 imported_dir = meson.current_source_dir() / 'imported'
 
@@ -72,9 +73,11 @@ tcg_func_table_generated = custom_target(
     'tcg_func_table_generated.c.inc',
     output: 'tcg_func_table_generated.c.inc',
     depends: [semantics_generated],
-    depend_files: [hex_common_py, gen_tcg_h, gen_tcg_hvx_h, gen_tcg_sys_h],
+    depend_files: [hex_common_py, gen_tcg_h, gen_tcg_hvx_h, gen_tcg_sys_h,
+                   gen_tcg_hmx_h],
     command: [python, files('gen_tcg_func_table.py'), semantics_generated,
-              gen_tcg_h, gen_tcg_hvx_h, gen_tcg_sys_h, '@OUTPUT@'],
+              gen_tcg_h, gen_tcg_hvx_h, gen_tcg_sys_h, gen_tcg_hmx_h,
+              '@OUTPUT@'],
 )
 hexagon_ss.add(tcg_func_table_generated)
 
@@ -334,8 +337,8 @@ if idef_parser_enabled and ('hexagon-linux-user' in 
target_dirs or
         'idef_parser_input.h.inc',
         output: 'idef_parser_input.h.inc',
         depends: [semantics_generated],
-        depend_files: [hex_common_py],
-        command: [python, files('gen_idef_parser_funcs.py'), 
semantics_generated, '@OUTPUT@'],
+        depend_files: [hex_common_py, gen_tcg_hmx_h],
+        command: [python, files('gen_idef_parser_funcs.py'), 
semantics_generated, gen_tcg_hmx_h, '@OUTPUT@'],
     )
 
     compiler = meson.get_compiler('c').cmd_array()
@@ -405,12 +408,12 @@ if idef_parser_enabled and ('hexagon-linux-user' in 
target_dirs or
     # Setup input and dependencies for the next step, this depends on whether 
or
     # not idef-parser is enabled
     helper_dep = [semantics_generated, idef_generated_tcg_c, 
idef_generated_tcg]
-    helper_in = [semantics_generated, gen_tcg_h, gen_tcg_hvx_h, gen_tcg_sys_h, 
'--idef-parser', idef_generated_list]
+    helper_in = [semantics_generated, gen_tcg_h, gen_tcg_hvx_h, gen_tcg_sys_h, 
gen_tcg_hmx_h, '--idef-parser', idef_generated_list]
 else
     # Setup input and dependencies for the next step, this depends on whether 
or
     # not idef-parser is enabled
     helper_dep = [semantics_generated]
-    helper_in = [semantics_generated, gen_tcg_h, gen_tcg_hvx_h, gen_tcg_sys_h]
+    helper_in = [semantics_generated, gen_tcg_h, gen_tcg_hvx_h, gen_tcg_sys_h, 
gen_tcg_hmx_h]
 endif
 
 #
@@ -424,7 +427,7 @@ helper_protos_generated = custom_target(
     'helper_protos_generated.h.inc',
     output: 'helper_protos_generated.h.inc',
     depends: helper_dep,
-    depend_files: [hex_common_py, gen_tcg_h, gen_tcg_hvx_h, gen_tcg_sys_h],
+    depend_files: [hex_common_py, gen_tcg_h, gen_tcg_hvx_h, gen_tcg_sys_h, 
gen_tcg_hmx_h],
     command: [python, files('gen_helper_protos.py'), helper_in, '@OUTPUT@'],
 )
 hexagon_ss.add(helper_protos_generated)
@@ -433,7 +436,7 @@ helper_funcs_generated = custom_target(
     'helper_funcs_generated.c.inc',
     output: 'helper_funcs_generated.c.inc',
     depends: helper_dep,
-    depend_files: [hex_common_py, gen_tcg_h, gen_tcg_hvx_h, gen_tcg_sys_h],
+    depend_files: [hex_common_py, gen_tcg_h, gen_tcg_hvx_h, gen_tcg_sys_h, 
gen_tcg_hmx_h],
     command: [python, files('gen_helper_funcs.py'), helper_in, '@OUTPUT@'],
 )
 hexagon_ss.add(helper_funcs_generated)
@@ -442,7 +445,7 @@ tcg_funcs_generated = custom_target(
     'tcg_funcs_generated.c.inc',
     output: 'tcg_funcs_generated.c.inc',
     depends: helper_dep,
-    depend_files: [hex_common_py, gen_tcg_h, gen_tcg_hvx_h, gen_tcg_sys_h],
+    depend_files: [hex_common_py, gen_tcg_h, gen_tcg_hvx_h, gen_tcg_sys_h, 
gen_tcg_hmx_h],
     command: [python, files('gen_tcg_funcs.py'), helper_in, '@OUTPUT@'],
 )
 hexagon_ss.add(tcg_funcs_generated)
@@ -451,7 +454,7 @@ analyze_funcs_generated = custom_target(
     'analyze_funcs_generated.c.inc',
     output: 'analyze_funcs_generated.c.inc',
     depends: helper_dep,
-    depend_files: [hex_common_py, gen_tcg_h, gen_tcg_hvx_h, gen_tcg_sys_h],
+    depend_files: [hex_common_py, gen_tcg_h, gen_tcg_hvx_h, gen_tcg_sys_h, 
gen_tcg_hmx_h],
     command: [python, files('gen_analyze_funcs.py'), helper_in, '@OUTPUT@'],
 )
 hexagon_ss.add(analyze_funcs_generated)
-- 
2.34.1

Reply via email to