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.

Jeff

Reply via email to