QEMU-Devel Archive mirror
 help / color / mirror / Atom feed
From: Brian Cain <bcain@quicinc.com>
To: <qemu-devel@nongnu.org>
Cc: <bcain@quicinc.com>, <armbru@redhat.com>,
	<richard.henderson@linaro.org>,  <philmd@linaro.org>,
	<peter.maydell@linaro.org>, <quic_mathbern@quicinc.com>,
	<stefanha@redhat.com>, <ale@rev.ng>, <anjo@rev.ng>,
	<quic_mliebel@quicinc.com>, <ltaylorsimpson@gmail.com>
Subject: [PULL 06/15] Hexagon (target/hexagon) Only pass env to generated helper when needed
Date: Sun, 5 May 2024 19:42:18 -0700	[thread overview]
Message-ID: <20240506024227.3345791-7-bcain@quicinc.com> (raw)
In-Reply-To: <20240506024227.3345791-1-bcain@quicinc.com>

From: Taylor Simpson <ltaylorsimpson@gmail.com>

Currently, we pass env to every generated helper.  When the semantics of
the instruction only depend on the arguments, this is unnecessary and
adds extra overhead to the helper call.

We add the TCG_CALL_NO_RWG_SE flag to any non-HVX helpers that don't get
the ptr to env.

The A2_nop and SA1_setin1 instructions end up with no arguments.  This
results in a "old-style function definition" error from the compiler, so
we write overrides for them.

With this change, the number of helpers with env argument is
    idef-parser enabled:    329 total, 23 with env
    idef-parser disabled:   1543 total, 550 with env

Signed-off-by: Taylor Simpson <ltaylorsimpson@gmail.com>
Reviewed-by: Anton Johansson <anjo@rev.ng>
Tested-by: Anton Johansson <anjo@rev.ng>
Message-Id: <20240214042726.19290-4-ltaylorsimpson@gmail.com>
Signed-off-by: Brian Cain <bcain@quicinc.com>
---
 target/hexagon/gen_helper_protos.py | 12 ++++++++++--
 target/hexagon/gen_tcg.h            |  5 ++++-
 target/hexagon/hex_common.py        | 23 ++++++++++++++++++-----
 3 files changed, 32 insertions(+), 8 deletions(-)

diff --git a/target/hexagon/gen_helper_protos.py b/target/hexagon/gen_helper_protos.py
index c82b0f54e4..f8578d5033 100755
--- a/target/hexagon/gen_helper_protos.py
+++ b/target/hexagon/gen_helper_protos.py
@@ -1,7 +1,7 @@
 #!/usr/bin/env python3
 
 ##
-##  Copyright(c) 2019-2023 Qualcomm Innovation Center, Inc. All Rights Reserved.
+##  Copyright(c) 2019-2024 Qualcomm Innovation Center, Inc. All Rights Reserved.
 ##
 ##  This program is free software; you can redistribute it and/or modify
 ##  it under the terms of the GNU General Public License as published by
@@ -40,7 +40,15 @@ def gen_helper_prototype(f, tag, tagregs, tagimms):
         declared.append(arg.proto_arg)
 
     arguments = ", ".join(declared)
-    f.write(f"DEF_HELPER_{len(declared) - 1}({tag}, {arguments})\n")
+
+    ## Add the TCG_CALL_NO_RWG_SE flag to helpers that don't take the env
+    ## argument and aren't HVX instructions.  Since HVX instructions take
+    ## pointers to their arguments, they will have side effects.
+    if hex_common.need_env(tag) or hex_common.is_hvx_insn(tag):
+        f.write(f"DEF_HELPER_{len(declared) - 1}({tag}, {arguments})\n")
+    else:
+        f.write(f"DEF_HELPER_FLAGS_{len(declared) - 1}({tag}, "
+                f"TCG_CALL_NO_RWG_SE, {arguments})\n")
 
 
 def main():
diff --git a/target/hexagon/gen_tcg.h b/target/hexagon/gen_tcg.h
index 1c4391b415..3fc1f4e281 100644
--- a/target/hexagon/gen_tcg.h
+++ b/target/hexagon/gen_tcg.h
@@ -1,5 +1,5 @@
 /*
- *  Copyright(c) 2019-2023 Qualcomm Innovation Center, Inc. All Rights Reserved.
+ *  Copyright(c) 2019-2024 Qualcomm Innovation Center, Inc. All Rights Reserved.
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -1369,3 +1369,6 @@
         gen_helper_raise_exception(tcg_env, excp); \
     } while (0)
 #endif
+
+#define fGEN_TCG_A2_nop(SHORTCODE) do { } while (0)
+#define fGEN_TCG_SA1_setin1(SHORTCODE) tcg_gen_movi_tl(RdV, -1)
diff --git a/target/hexagon/hex_common.py b/target/hexagon/hex_common.py
index 03c9ce1d8a..c09b48bb36 100755
--- a/target/hexagon/hex_common.py
+++ b/target/hexagon/hex_common.py
@@ -206,6 +206,18 @@ def need_sp(tag):
     return "A_IMPLICIT_READS_SP" in attribdict[tag]
 
 
+def is_hvx_insn(tag):
+    return "A_CVI" in attribdict[tag]
+
+
+def need_env(tag):
+    return ("A_STORE" in attribdict[tag] or
+            "A_LOAD" in attribdict[tag] or
+            "A_CVI_GATHER" in attribdict[tag] or
+            "A_CVI_SCATTER" in attribdict[tag] or
+            "A_IMPLICIT_WRITES_USR" in attribdict[tag])
+
+
 def need_slot(tag):
     if (
         "A_CVI_SCATTER" not in attribdict[tag]
@@ -1085,11 +1097,12 @@ def helper_args(tag, regs, imms):
     args = []
 
     ## First argument is the CPU state
-    args.append(HelperArg(
-        "env",
-        "tcg_env",
-        "CPUHexagonState *env"
-    ))
+    if need_env(tag):
+        args.append(HelperArg(
+            "env",
+            "tcg_env",
+            "CPUHexagonState *env"
+        ))
 
     ## For predicated instructions, we pass in the destination register
     if is_predicated(tag):
-- 
2.25.1


  parent reply	other threads:[~2024-05-06  2:43 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-06  2:42 [PULL 00/15] Hexagon: simplify gen for packets w/o read-after-write Brian Cain
2024-05-06  2:42 ` [PULL 01/15] Hexagon (target/hexagon) Analyze reads before writes Brian Cain
2024-05-06  2:42 ` [PULL 02/15] Hexagon (target/hexagon) Enable more short-circuit packets (scalar core) Brian Cain
2024-05-06  2:42 ` [PULL 03/15] Hexagon (target/hexagon) Enable more short-circuit packets (HVX) Brian Cain
2024-05-06  2:42 ` [PULL 04/15] Hexagon (target/hexagon) Pass P0 explicitly to helpers that need it Brian Cain
2024-05-06  2:42 ` [PULL 05/15] Hexagon (target/hexagon) Pass SP " Brian Cain
2024-05-06  2:42 ` Brian Cain [this message]
2024-05-06  2:42 ` [PULL 07/15] Hexagon (target/hexagon) Add is_old/is_new to Register class Brian Cain
2024-05-06  2:42 ` [PULL 08/15] Hexagon (target/hexagon) Mark new_read_idx in trans functions Brian Cain
2024-05-06  2:42 ` [PULL 09/15] Hexagon (target/hexagon) Mark dest_idx " Brian Cain
2024-05-06  2:42 ` [PULL 10/15] Hexagon (target/hexagon) Mark has_pred_dest " Brian Cain
2024-05-06  2:42 ` [PULL 11/15] Hexagon (tests/tcg/hexagon) Test HVX .new read from high half of pair Brian Cain
2024-05-06  2:42 ` [PULL 12/15] Hexagon (target/hexagon) Remove uses of op_regs_generated.h.inc Brian Cain
2024-05-06  2:42 ` [PULL 13/15] Hexagon (target/hexagon) Remove gen_op_regs.py Brian Cain
2024-05-06  2:42 ` [PULL 14/15] Hexagon (target/hexagon) Remove gen_shortcode.py Brian Cain
2024-05-06  2:42 ` [PULL 15/15] Hexagon (target/hexagon) Remove hex_common.read_attribs_file Brian Cain
2024-05-06 17:17 ` [PULL 00/15] Hexagon: simplify gen for packets w/o read-after-write Richard Henderson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240506024227.3345791-7-bcain@quicinc.com \
    --to=bcain@quicinc.com \
    --cc=ale@rev.ng \
    --cc=anjo@rev.ng \
    --cc=armbru@redhat.com \
    --cc=ltaylorsimpson@gmail.com \
    --cc=peter.maydell@linaro.org \
    --cc=philmd@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=quic_mathbern@quicinc.com \
    --cc=quic_mliebel@quicinc.com \
    --cc=richard.henderson@linaro.org \
    --cc=stefanha@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).