aboutsummaryrefslogtreecommitdiffstats
path: root/lib/div64.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/div64.c')
-rw-r--r--lib/div64.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/lib/div64.c b/lib/div64.c
index 365719f84832..c3d7655cdfb5 100644
--- a/lib/div64.c
+++ b/lib/div64.c
@@ -58,4 +58,26 @@ uint32_t __div64_32(uint64_t *n, uint32_t base)
58 58
59EXPORT_SYMBOL(__div64_32); 59EXPORT_SYMBOL(__div64_32);
60 60
61/* 64bit divisor, dividend and result. dynamic precision */
62uint64_t div64_64(uint64_t dividend, uint64_t divisor)
63{
64 uint32_t d = divisor;
65
66 if (divisor > 0xffffffffULL) {
67 unsigned int shift = fls(divisor >> 32);
68
69 d = divisor >> shift;
70 dividend >>= shift;
71 }
72
73 /* avoid 64 bit division if possible */
74 if (dividend >> 32)
75 do_div(dividend, d);
76 else
77 dividend = (uint32_t) dividend / d;
78
79 return dividend;
80}
81EXPORT_SYMBOL(div64_64);
82
61#endif /* BITS_PER_LONG == 32 */ 83#endif /* BITS_PER_LONG == 32 */