riscv-llvm
riscv-llvm copied to clipboard
Add support for RV32IM without division
Could we add something like -mattr=+m,-div
or -mattr=+mul
to generate multiplication instructions but not division (and remainder, etc.) instructions?
I'm not the only one who wants this. For instance: https://twitter.com/jangray/status/877188603440316416
In principle it's possible but probably will not happen because the number of compiler options that would need to be supported for a marginal area/speed saving. Also + - * / form a closed group so it is inelegant to leave one out.
Sent from my iPhone
On 26 Sep 2017, at 19:15, Luís Marques [email protected] wrote:
Could we add something like -mattr=+m,-div or -mattr=+mul to generate multiplication instructions but not division (and remainder, etc.) instructions?
I'm not the only one who wants this. For instance: https://twitter.com/jangray/status/877188603440316416
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.
This sort of thing has also come up on the mailing lists. I think it's inevitable we'll need to support this sort of flexibility, though it's not clear exactly how it should be expressed (specifically, are there lots of cases beyond the mul/div issues where you need this fine-grained approach?).
There's also the issue with the "U-mode" instructions like rdcycle, which sadly will trap on M-mode only implementations. I wish implementers of M-mode-only cores would just alias it to reading the M-mode cycle CSR to give us a single common ISA baseline, but it seems that's not the preferred approach. If targeting one of these cores, it would be nice if LLVM knew to complain when trying to use rdcycle.
Different "profiles" has been discussed as one potential approach, but nobody has really elaborated how this would work, and enumerated what these profiles might look like. Whatever the solution, we should try and coordinate with GCC to keep a uniform interface.
Also + - * / form a closed group so it is inelegant to leave one out.
What do you mean by 'closed group'? The for operations you mention form a field. If you leave out division, you get a ring which is also an important structure, and not at all 'inelegant'.
I meant inelegant from an engineering standpoint, not mathematically. Without division, the programmer would have to know that divisions were performed in a slow software loop, and apply appropriate workarounds, for example division by some constant c might be replaced by multiplying by (2^16)/c, with associated rounding issues to be considered. In my hand-waving way I represented a closed group as being a set of integers which applied to any of those operators would always lead to another integer (if you exclude the irritating divide by zero case). Anyway, I think the statute of limitations has run out on that remark since I said it over five years ago.