[GIT PULL] RISC-V Patches for the 4.20 Merge Window, Part 1

Zong Li zongbox at gmail.com
Fri Oct 26 09:13:05 PDT 2018

Linus Torvalds <torvalds at linux-foundation.org> 於 2018年10月26日 週五 上午9:51寫道:
> On 10/25/18 6:12 PM, Linus Torvalds wrote:
> >
> > Almost always, the 64-bit divide turns out to be entirely pointless,
> > and the code can be written as a (much cheaper) 64-by-32 divide
> > instead using the functions in <asm/div.h> instead.
> The other common situation for the kernel is that something was
> written as "xyz / abc", when it turns out that abc is really just a
> power-of-two.
> So it's not necessarily always that the 64-bit divide can be
> re-written as a 64-by-32 divide, sometimes it can be rewritten as
> simply a shift. Which is even cheaper.
> That's the reason I try to actively discourage full 64-by-64 divides.
> We have had situations where people end up using a divide that can
> take hundres of cycles, where alarmingly often it can be rewritten as
> one that takes tens of cycles or even just _single_ cycles.
> People don't sometimes appreciate just how expensive 64-by-64 divides
> are when you don't have direct hardware support for them, and how
> often there are much simpler and faster ways to avoid them.

Our driver guys implement the DMA driver which has a full 64-bit
divide in its initialization function. I had checked the code, it
could use the 64-by-32 divides in fact of the situation. I was not
conscious of the mistake and naively thought that umoddi3 is useful
for the other drivers which need the 64-by-64 divide. I would submit a
patch to get rid of these routines.

More information about the linux-riscv mailing list