summaryrefslogtreecommitdiffstats
path: root/lib/div64.c
diff options
context:
space:
mode:
authorStephen Hemminger <shemminger@linux-foundation.org>2007-03-26 04:54:23 +0200
committerDavid S. Miller <davem@sunset.davemloft.net>2007-04-26 07:23:33 +0200
commit3927f2e8f9afa3424bb51ca81f7abac01ffd0005 (patch)
treeda9e335169572e6c743c084edce6a802f9e667ee /lib/div64.c
parent[NET]: Convert xtime.tv_sec to get_seconds() (diff)
downloadlinux-3927f2e8f9afa3424bb51ca81f7abac01ffd0005.tar.xz
linux-3927f2e8f9afa3424bb51ca81f7abac01ffd0005.zip
[NET]: div64_64 consolidate (rev3)
Here is the current version of the 64 bit divide common code. Signed-off-by: Stephen Hemminger <shemminger@linux-foundation.org> Signed-off-by: David S. Miller <davem@davemloft.net>
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)
EXPORT_SYMBOL(__div64_32);
+/* 64bit divisor, dividend and result. dynamic precision */
+uint64_t div64_64(uint64_t dividend, uint64_t divisor)
+{
+ uint32_t d = divisor;
+
+ if (divisor > 0xffffffffULL) {
+ unsigned int shift = fls(divisor >> 32);
+
+ d = divisor >> shift;
+ dividend >>= shift;
+ }
+
+ /* avoid 64 bit division if possible */
+ if (dividend >> 32)
+ do_div(dividend, d);
+ else
+ dividend = (uint32_t) dividend / d;
+
+ return dividend;
+}
+EXPORT_SYMBOL(div64_64);
+
#endif /* BITS_PER_LONG == 32 */