From: Jeff Law <jlaw@ventanamicro.com>
To: Jiawei <jiawei@iscas.ac.cn>, gcc-patches@gcc.gnu.org
Cc: kito.cheng@sifive.com, palmer@dabbelt.com,
christoph.muellner@vrull.eu, wuwei2016@iscas.ac.cn,
shihua@iscas.ac.cn, shiyulong@iscas.ac.cn,
chenyixuan@iscas.ac.cn
Subject: Re: [PATCH] RISC-V: Add XiangShan Nanhu microarchitecture.
Date: Mon, 18 Mar 2024 20:54:09 -0600 [thread overview]
Message-ID: <35aff817-bcea-4e5f-9a23-9928e0f65043@ventanamicro.com> (raw)
In-Reply-To: <20240227085243.605255-1-jiawei@iscas.ac.cn>
On 2/27/24 1:52 AM, Jiawei wrote:
> From: Chen Jiawei <jiawei@iscas.ac.cn>
>
> Co-Authored by: Lin Jiawei <jiawei.lin@epfl.ch>
>
> This patch add XiangShan Nanhu cpu microarchitecture,
> Nanhu is a 6-issue, superscalar, out-of-order processor.
> More details see: https://xiangshan-doc.readthedocs.io/zh-cn/latest/arch
>
> gcc/ChangeLog:
>
> * config/riscv/riscv-cores.def (RISCV_TUNE): New def.
> (RISCV_CORE): Ditto.
> * config/riscv/riscv-opts.h (enum
> * riscv_microarchitecture_type): New option.
> * config/riscv/riscv.cc: New def.
> * config/riscv/riscv.md: New include.
> * config/riscv/xiangshan.md: New file.
>
> gcc/testsuite/ChangeLog:
>
> * gcc.target/riscv/mcpu-xiangshan-nanhu.c: New test.
As was discussed last Tuesday, this should be safe, even at this late
stage in the gcc-14 cycle.
>
> +/* Costs to use when optimizing for xiangshan nanhu. */
> +static const struct riscv_tune_param xiangshan_nanhu_tune_info = {
> + {COSTS_N_INSNS (3), COSTS_N_INSNS (3)}, /* fp_add */
> + {COSTS_N_INSNS (3), COSTS_N_INSNS (3)}, /* fp_mul */
> + {COSTS_N_INSNS (10), COSTS_N_INSNS (20)}, /* fp_div */
> + {COSTS_N_INSNS (3), COSTS_N_INSNS (3)}, /* int_mul */
> + {COSTS_N_INSNS (6), COSTS_N_INSNS (6)}, /* int_div */
> + 6, /* issue_rate */
> + 3, /* branch_cost */
> + 3, /* memory_cost */
> + 3, /* fmv_cost */
> + true, /* slow_unaligned_access */
> + false, /* use_divmod_expansion */
> + RISCV_FUSE_ZEXTW | RISCV_FUSE_ZEXTH, /* fusible_ops */
> + NULL, /* vector cost */
Is your integer division really that fast? The table above essentially
says that your cpu can do integer division in 6 cycles.
> +
> +(define_insn_reservation "xiangshan_mul" 3
> + (and (eq_attr "tune" "xiangshan")
> + (eq_attr "type" "imul"))
> + "xs_mdu_rs")
> +
> +(define_insn_reservation "xiangshan_div" 21
> + (and (eq_attr "tune" "xiangshan")
> + (eq_attr "type" "idiv"))
> + "xs_mdu_rs")
Whereas your pipeline description says it's 21c.
I strongly suspect you want to increase the cost of the int_div in the
tuning table. And with a the higher cost you probably want to turn on
use_divmod_expansion.
I'll also note that your scheduler description also indicates your
division is fully pipelined. Is that correct? if not, you'll want to
adjust that reservation.
> +
> +(define_insn_reservation "xiangshan_sfdiv" 11
> + (and (eq_attr "tune" "xiangshan")
> + (eq_attr "type" "fdiv")
> + (eq_attr "mode" "SF"))
> + "xs_fmisc_rs")
> +
> +(define_insn_reservation "xiangshan_sfsqrt" 17
> + (and (eq_attr "tune" "xiangshan")
> + (eq_attr "type" "fsqrt")
> + (eq_attr "mode" "SF"))
> + "xs_fmisc_rs")
> +
> +(define_insn_reservation "xiangshan_dfdiv" 21
> + (and (eq_attr "tune" "xiangshan")
> + (eq_attr "type" "fdiv")
> + (eq_attr "mode" "DF"))
> + "xs_fmisc_rs")
> +
> +(define_insn_reservation "xiangshan_dfsqrt" 37
> + (and (eq_attr "tune" "xiangshan")
> + (eq_attr "type" "fsqrt")
> + (eq_attr "mode" "DF"))
> + "xs_fmisc_rs")
Similarly these say your fpdiv and fpsqrt are fully pipelined. It's
certainly possible, but I suspect it's really just an oversight. Given
these values you may also want to adjust the cost of an fp division in
the cost table.
Finally with such high values for for the div/sqrt units, we find that
the DFA "blows up" causing genattrtab to run for a very long time. We'll
have to keep an eye on that.
And just to be clear, I think these can be done as a followup patch. I'm
going to push this patch as-is rather than make any adjustments -- you
almost certainly know the processor's capabilities better than myself or
anyone else on this list :-)
Jeff
next prev parent reply other threads:[~2024-03-19 2:54 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-27 8:52 Jiawei
2024-03-19 2:54 ` Jeff Law [this message]
2024-03-19 12:43 ` jiawei
2024-03-25 19:48 ` TARGET_RTX_COSTS and pipeline latency vs. variable-latency instructions (was Re: [PATCH] RISC-V: Add XiangShan Nanhu microarchitecture.) Xi Ruoyao
2024-03-25 19:59 ` Jeff Law
2024-03-25 20:13 ` Palmer Dabbelt
2024-03-25 20:27 ` Jeff Law
2024-03-25 20:31 ` Palmer Dabbelt
2024-03-25 20:49 ` Jeff Law
2024-03-25 20:57 ` Palmer Dabbelt
2024-03-25 21:41 ` Jeff Law
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=35aff817-bcea-4e5f-9a23-9928e0f65043@ventanamicro.com \
--to=jlaw@ventanamicro.com \
--cc=chenyixuan@iscas.ac.cn \
--cc=christoph.muellner@vrull.eu \
--cc=gcc-patches@gcc.gnu.org \
--cc=jiawei@iscas.ac.cn \
--cc=kito.cheng@sifive.com \
--cc=palmer@dabbelt.com \
--cc=shihua@iscas.ac.cn \
--cc=shiyulong@iscas.ac.cn \
--cc=wuwei2016@iscas.ac.cn \
/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).