public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Dimitar Dimitrov <dimitar@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r14-4725] pru: Implement TARGET_INSN_COST
Date: Wed, 18 Oct 2023 17:17:17 +0000 (GMT)	[thread overview]
Message-ID: <20231018171717.AB0B13858D33@sourceware.org> (raw)

https://gcc.gnu.org/g:fe9767eedcea3e867a48102f96d913fc70670e67

commit r14-4725-gfe9767eedcea3e867a48102f96d913fc70670e67
Author: Dimitar Dimitrov <dimitar@dinux.eu>
Date:   Mon Oct 16 20:40:18 2023 +0300

    pru: Implement TARGET_INSN_COST
    
    This patch slightly improves the embench-iot benchmark score for
    PRU code size.  There is also small improvement in a few real-world
    firmware programs.
    
      Embench-iot size
      ------------------------------------------
      Benchmark          before   after    delta
      ---------           ----    ----     -----
      aha-mont64          4.15    4.15         0
      crc32               6.04    6.04         0
      cubic              21.64   21.62     -0.02
      edn                 6.37    6.37         0
      huffbench          18.63   18.55     -0.08
      matmult-int         5.44    5.44         0
      md5sum             25.56   25.43     -0.13
      minver             12.82   12.76     -0.06
      nbody              15.09   14.97     -0.12
      nettle-aes          4.75    4.75         0
      nettle-sha256       4.67    4.67         0
      nsichneu            3.77    3.77         0
      picojpeg            4.11    4.11         0
      primecount          7.90    7.90         0
      qrduino             7.18    7.16     -0.02
      sglib-combined     13.63   13.59     -0.04
      slre                5.19    5.19         0
      st                 14.23   14.12     -0.11
      statemate           2.34    2.34         0
      tarfind            36.85   36.64     -0.21
      ud                 10.51   10.46     -0.05
      wikisort            7.44    7.41     -0.03
      ---------          -----   -----
      Geometric mean      8.42    8.40     -0.02
      Geometric SD        2.00    2.00         0
      Geometric range    12.68   12.62     -0.06
    
    gcc/ChangeLog:
    
            * config/pru/pru.cc (pru_insn_cost): New function.
            (TARGET_INSN_COST): Define for PRU.
    
    Signed-off-by: Dimitar Dimitrov <dimitar@dinux.eu>

Diff:
---
 gcc/config/pru/pru.cc | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)

diff --git a/gcc/config/pru/pru.cc b/gcc/config/pru/pru.cc
index 6e8112be64a7..fd1924e38dc7 100644
--- a/gcc/config/pru/pru.cc
+++ b/gcc/config/pru/pru.cc
@@ -783,6 +783,39 @@ pru_rtx_costs (rtx x, machine_mode mode,
       }
     }
 }
+
+/* Insn costs on PRU are straightforward because:
+     - Insns emit 0, 1 or more instructions.
+     - All instructions are 32-bit length.
+     - All instructions execute in 1 cycle (sans memory access delays).
+   The "length" attribute maps nicely to the insn cost.  */
+
+static int
+pru_insn_cost (rtx_insn *insn, bool speed)
+{
+  /* Use generic cost calculation for unrecognized insns.  */
+  if (recog_memoized (insn) < 0)
+    return pattern_cost (insn, speed);
+
+  unsigned int len = get_attr_length (insn);
+
+  gcc_assert ((len % 4) == 0);
+
+  int cost = COSTS_N_INSNS (len / 4);
+  /* Some insns have zero length (e.g. blockage, pruloop_end).
+     In such cases give the minimum cost, because a return of
+     0 would incorrectly indicate that the insn cost is unknown.  */
+  if (cost == 0)
+    cost = 1;
+
+  /* Writes are usually posted, so they take 1 cycle.  Reads
+     from DMEM usually take 3 cycles.
+     See TI document SPRACE8A, Device-Specific PRU Read Latency Values.  */
+  if (speed && get_attr_type (insn) == TYPE_LD)
+    cost += COSTS_N_INSNS (2);
+
+  return cost;
+}
 \f
 static GTY(()) rtx eqdf_libfunc;
 static GTY(()) rtx nedf_libfunc;
@@ -3175,6 +3208,9 @@ pru_unwind_word_mode (void)
 #undef TARGET_RTX_COSTS
 #define TARGET_RTX_COSTS pru_rtx_costs
 
+#undef TARGET_INSN_COST
+#define TARGET_INSN_COST pru_insn_cost
+
 #undef TARGET_PRINT_OPERAND
 #define TARGET_PRINT_OPERAND pru_print_operand

                 reply	other threads:[~2023-10-18 17:17 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20231018171717.AB0B13858D33@sourceware.org \
    --to=dimitar@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /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).