From: Andrew Burgess <aburgess@redhat.com>
To: Bernd Edlinger <bernd.edlinger@hotmail.de>,
"gdb-patches@sourceware.org" <gdb-patches@sourceware.org>
Subject: Re: [PATCH 2/2] sim: riscv: Simplify the signed div by -1 code
Date: Tue, 11 Jun 2024 17:25:40 +0100 [thread overview]
Message-ID: <87frtja1kr.fsf@redhat.com> (raw)
In-Reply-To: <AS8P193MB12858E260739E6109ED66D4EE4092@AS8P193MB1285.EURP193.PROD.OUTLOOK.COM>
Bernd Edlinger <bernd.edlinger@hotmail.de> writes:
> This uses the idea from the previous patch to
> simplify the code for non-overflowing signed
> divisions by -1. This is no bug-fix but it
> simplifies the code and avoids some unnecessary
> branches.
> ---
> sim/riscv/sim-main.c | 10 ++++------
> 1 file changed, 4 insertions(+), 6 deletions(-)
>
> diff --git a/sim/riscv/sim-main.c b/sim/riscv/sim-main.c
> index 515ff835223..e4b15b533ba 100644
> --- a/sim/riscv/sim-main.c
> +++ b/sim/riscv/sim-main.c
> @@ -700,18 +700,16 @@ execute_m (SIM_CPU *cpu, unsigned_word iw, const struct riscv_opcode *op)
> const char *rd_name = riscv_gpr_names_abi[rd];
> const char *rs1_name = riscv_gpr_names_abi[rs1];
> const char *rs2_name = riscv_gpr_names_abi[rs2];
> - unsigned_word tmp, dividend_max;
> + unsigned_word tmp;
> sim_cia pc = riscv_cpu->pc + 4;
>
> - dividend_max = -((unsigned_word) 1 << (WITH_TARGET_WORD_BITSIZE - 1));
I really don't understand what this was trying to calculate. It's not
the max value of an unsigned_word. Nor is it the bit representation of
the maximum signed_word value... but you're removing it, so I guess I
can not worry about that :)
> -
> switch (op->match)
> {
> case MATCH_DIV:
> TRACE_INSN (cpu, "div %s, %s, %s; // %s = %s / %s",
> rd_name, rs1_name, rs2_name, rd_name, rs1_name, rs2_name);
> - if (riscv_cpu->regs[rs1] == dividend_max && riscv_cpu->regs[rs2] == -1)
> - tmp = dividend_max;
> + if (riscv_cpu->regs[rs2] == -1)
> + tmp = -riscv_cpu->regs[rs1];
As with the previous commit, can't we drop this whole if check and block?
I think we should add some tests for this too. The test I proposed in
the previous commit can be modified to give us div.s and rem.s tests.
Thanks,
Andrew
> else if (riscv_cpu->regs[rs2])
> tmp = (signed_word) riscv_cpu->regs[rs1] /
> (signed_word) riscv_cpu->regs[rs2];
> @@ -793,7 +791,7 @@ execute_m (SIM_CPU *cpu, unsigned_word iw, const struct riscv_opcode *op)
> case MATCH_REM:
> TRACE_INSN (cpu, "rem %s, %s, %s; // %s = %s %% %s",
> rd_name, rs1_name, rs2_name, rd_name, rs1_name, rs2_name);
> - if (riscv_cpu->regs[rs1] == dividend_max && riscv_cpu->regs[rs2] == -1)
> + if (riscv_cpu->regs[rs2] == -1)
> tmp = 0;
> else if (riscv_cpu->regs[rs2])
> tmp = (signed_word) riscv_cpu->regs[rs1]
> --
> 2.39.2
next prev parent reply other threads:[~2024-06-11 16:25 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-15 14:46 Bernd Edlinger
2024-06-11 16:25 ` Andrew Burgess [this message]
2024-06-17 5:10 ` Bernd Edlinger
2024-06-17 8:58 ` Andrew Burgess
2024-06-17 10:43 ` Bernd Edlinger
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=87frtja1kr.fsf@redhat.com \
--to=aburgess@redhat.com \
--cc=bernd.edlinger@hotmail.de \
--cc=gdb-patches@sourceware.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).