diff options
author | Nicolas Pitre <nicolas.pitre@linaro.org> | 2015-10-30 19:36:39 (GMT) |
---|---|---|
committer | Nicolas Pitre <nicolas.pitre@linaro.org> | 2015-11-16 19:42:08 (GMT) |
commit | 461a5e51060c93f5844113f4be9dba513cc92830 (patch) | |
tree | f02ce68a22937ce0b8d2c609e77bccc02c86455a /include/asm-generic/mcs_spinlock.h | |
parent | 911918aa7ef6f868c135505b0015e42072c54682 (diff) | |
download | linux-461a5e51060c93f5844113f4be9dba513cc92830.tar.xz |
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>
Diffstat (limited to 'include/asm-generic/mcs_spinlock.h')
0 files changed, 0 insertions, 0 deletions