Re: [PATCH] arm: lib: implement aeabi_uldivmod via div64_u64_rem

From: Arnd Bergmann
Date: Sat Jul 16 2022 - 05:47:24 EST


On Sat, Jul 16, 2022 at 2:16 AM Nick Desaulniers
<ndesaulniers@xxxxxxxxxx> wrote:
>
> Compilers frequently need to defer 64b division to a libcall with this
> symbol name. It essentially is div64_u64_rem, just with a different
> signature. Kernel developers know to call div64_u64_rem, but compilers
> don't.
>
> Link: https://lore.kernel.org/lkml/20220524004156.0000790e@xxxxxxxxxxx/
> Suggested-by: Gary Guo <gary@xxxxxxxxxxx>
> Signed-off-by: Nick Desaulniers <ndesaulniers@xxxxxxxxxx>

This has historically been strongly NAK'd, and I don't think that position
has changed in the meantime. A variable-argument 64-bit division is
really expensive, especially on 32-bit machines that lack a native
32-bit division instruction, and we don't want developers to accidentally
insert one in their driver code.

Explicitly calling one of the division helpers in linux/math64.h is the
established way for driver writers to declare that a particular division
cannot be turned into a cheaper operation and is never run in a
performance critical code path. The compiler of course cannot know
about either of those.

Arnd