]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commit - include/asm-generic/div64.h
do_div(): generic optimization for constant divisor on 32-bit machines
authorNicolas Pitre <nicolas.pitre@linaro.org>
Fri, 30 Oct 2015 19:36:39 +0000 (15:36 -0400)
committerNicolas Pitre <nicolas.pitre@linaro.org>
Mon, 16 Nov 2015 19:42:08 +0000 (14:42 -0500)
commit461a5e51060c93f5844113f4be9dba513cc92830
treef02ce68a22937ce0b8d2c609e77bccc02c86455a
parent911918aa7ef6f868c135505b0015e42072c54682
do_div(): generic optimization for constant divisor on 32-bit machines

64-by-32-bit divisions are prominent in the kernel, even on 32-bit
machines.  Luckily, many of them use a constant divisor that allows
for a much faster multiplication by the divisor's reciprocal.

The compiler already performs this optimization when compiling a 32-by-32
division with a constant divisor. Unfortunately, on 32-bit machines, gcc
does not optimize 64-by-32 divisions in that case, except for constant
divisors that happen to be a power of 2.

Let's avoid the slow path whenever the divisor is constant by manually
computing the reciprocal ourselves and performing the multiplication
inline.  In most cases, this improves performance of 64-by-32 divisions
by about two orders of magnitude compared to the __div64_32() fallback,
especially on architectures lacking a native div instruction.

The algorithm used here comes from the existing ARM code.

The __div64_const32_is_OK macro can be predefined by architectures to
disable this optimization in some cases. For example, some ancient gcc
version on ARM would crash with an ICE when fed this code.

Signed-off-by: Nicolas Pitre <nico@linaro.org>
Acked-by: Alexey Brodkin <abrodkin@synopsys.com>
include/asm-generic/div64.h