public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Palmer Dabbelt <palmer@dabbelt.com>
To: jeffreyalaw@gmail.com
Cc: gcc-patches@gcc.gnu.org
Subject: Re: RISC-V: Add divmod instruction support
Date: Sat, 18 Feb 2023 13:30:11 -0800 (PST)	[thread overview]
Message-ID: <mhng-e6ef3c83-7428-420c-a8dc-428b624c54a3@palmer-ri-x1c9a> (raw)
In-Reply-To: <d91601ec-526d-6dd5-94ec-2ddf33df715e@gmail.com>

On Sat, 18 Feb 2023 13:06:02 PST (-0800), jeffreyalaw@gmail.com wrote:
>
>
> On 2/18/23 11:26, Palmer Dabbelt wrote:
>> On Fri, 17 Feb 2023 06:02:40 PST (-0800), gcc-patches@gcc.gnu.org wrote:
>>> Hi all,
>>> If we have division and remainder calculations with the same operands:
>>>
>>>   a = b / c;
>>>   d = b % c;
>>>
>>> We can replace the calculation of remainder with multiplication +
>>> subtraction, using the result from the previous division:
>>>
>>>   a = b / c;
>>>   d = a * c;
>>>   d = b - d;
>>>
>>> Which will be faster.
>>
>> Do you have any benchmarks that show that performance increase?  The ISA
>> manual specifically says the suggested sequence is div+mod, and while
>> those suggestions don't always pan out for real hardware it's likely
>> that at least some implementations will end up with the ISA-suggested
>> fusions.
> It'll almost certainly be visible in mcf.  Been there, done that.  In
> fact, that's why I asked the team Matevos works on to poke at this case
> as I went through this issue on another processor.
>
> It can also be run through LLVM's MCA to estimate counts if you've got a
> pipeline description.  THe div+rem will come out at around ~40c while a
> div+mul+sub should weigh in around 25c for Veyron v1.

Do you have a link to the patches somewhere?  I couldn't find them 
online, just the custom instruction support.  Or even just some docs 
describing what the pipeline does, as just basing one performance model 
on another is kind of a double-edged sword.

That said, I think just knowing the processor doesn't do the div+mod 
fusion is sufficient to turn something like this on for the mtune for 
that processor.  That's different than turning it on globally, though -- 
unless it turns out nobody is actually doing the fusion suggested in the 
ISA manual, which wouldn't be super surprising.

Maybe some of the SiFive and T-Head folks can chime in on whether or not 
their processors perform the fusion in question -- and if so, do the 
instructions need to say back-to-back?  It doesn't look like we're 
really targeting the code sequences the ISA suggests as it stands, so 
maybe it's OK to just switch the default over too?

It also brings up the question of mulh+mul fusions, which I don't think 
we've really looked at (though maybe they're a lot less important for 
rv64).

  reply	other threads:[~2023-02-18 21:30 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-17 14:02 Matevos Mehrabyan
2023-02-18 18:26 ` Palmer Dabbelt
2023-02-18 18:42   ` Andrew Pinski
2023-02-18 19:26     ` Palmer Dabbelt
2023-02-18 19:31     ` Maciej W. Rozycki
2023-02-18 20:57       ` Prathamesh Kulkarni
2023-02-18 21:07       ` Jeff Law
2023-02-19  1:14         ` Maciej W. Rozycki
2023-02-20  8:11           ` Richard Biener
2023-02-20 13:32             ` Alexander Monakov
2023-02-28 12:54               ` Maciej W. Rozycki
2023-02-18 21:06   ` Jeff Law
2023-02-18 21:30     ` Palmer Dabbelt [this message]
2023-02-18 21:57       ` Jeff Law
2023-02-20  1:27       ` Andrew Waterman
2023-04-28 20:09 ` 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=mhng-e6ef3c83-7428-420c-a8dc-428b624c54a3@palmer-ri-x1c9a \
    --to=palmer@dabbelt.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jeffreyalaw@gmail.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).