summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorNicolas Pitre <nicolas.pitre@linaro.org>2015-11-02 22:55:05 +0300
committerNicolas Pitre <nicolas.pitre@linaro.org>2015-11-16 22:14:03 +0300
commit911918aa7ef6f868c135505b0015e42072c54682 (patch)
treeb12a768b34d0461978276533b73436c4494fe71f /include
parent1c07db46511f0d2335d3b32008f644164071d13e (diff)
downloadlinux-911918aa7ef6f868c135505b0015e42072c54682.tar.xz
div64.h: optimize do_div() for power-of-two constant divisors
Let's perform the obvious mask and shift operation in this case. On 32-bit targets, gcc is able to do the same thing with a constant divisor that happens to be a power of two i.e. it turns the division into an inline shift, but it doesn't hurt to be explicit. Signed-off-by: Nicolas Pitre <nico@linaro.org>
Diffstat (limited to 'include')
-rw-r--r--include/asm-generic/div64.h8
1 files changed, 7 insertions, 1 deletions
diff --git a/include/asm-generic/div64.h b/include/asm-generic/div64.h
index 8f4e3193342e..5d974683193a 100644
--- a/include/asm-generic/div64.h
+++ b/include/asm-generic/div64.h
@@ -32,6 +32,8 @@
#elif BITS_PER_LONG == 32
+#include <linux/log2.h>
+
extern uint32_t __div64_32(uint64_t *dividend, uint32_t divisor);
/* The unnecessary pointer compare is there
@@ -41,7 +43,11 @@ extern uint32_t __div64_32(uint64_t *dividend, uint32_t divisor);
uint32_t __base = (base); \
uint32_t __rem; \
(void)(((typeof((n)) *)0) == ((uint64_t *)0)); \
- if (likely(((n) >> 32) == 0)) { \
+ if (__builtin_constant_p(__base) && \
+ is_power_of_2(__base)) { \
+ __rem = (n) & (__base - 1); \
+ (n) >>= ilog2(__base); \
+ } else if (likely(((n) >> 32) == 0)) { \
__rem = (uint32_t)(n) % __base; \
(n) = (uint32_t)(n) / __base; \
} else \