aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/div64.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/lib/div64.c b/lib/div64.c
index a163b6caef73..4382ad77777e 100644
--- a/lib/div64.c
+++ b/lib/div64.c
@@ -79,6 +79,46 @@ EXPORT_SYMBOL(div_s64_rem);
79#endif 79#endif
80 80
81/** 81/**
82 * div64_u64_rem - unsigned 64bit divide with 64bit divisor and remainder
83 * @dividend: 64bit dividend
84 * @divisor: 64bit divisor
85 * @remainder: 64bit remainder
86 *
87 * This implementation is a comparable to algorithm used by div64_u64.
88 * But this operation, which includes math for calculating the remainder,
89 * is kept distinct to avoid slowing down the div64_u64 operation on 32bit
90 * systems.
91 */
92#ifndef div64_u64_rem
93u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder)
94{
95 u32 high = divisor >> 32;
96 u64 quot;
97
98 if (high == 0) {
99 u32 rem32;
100 quot = div_u64_rem(dividend, divisor, &rem32);
101 *remainder = rem32;
102 } else {
103 int n = 1 + fls(high);
104 quot = div_u64(dividend >> n, divisor >> n);
105
106 if (quot != 0)
107 quot--;
108
109 *remainder = dividend - quot * divisor;
110 if (*remainder >= divisor) {
111 quot++;
112 *remainder -= divisor;
113 }
114 }
115
116 return quot;
117}
118EXPORT_SYMBOL(div64_u64_rem);
119#endif
120
121/**
82 * div64_u64 - unsigned 64bit divide with 64bit divisor 122 * div64_u64 - unsigned 64bit divide with 64bit divisor
83 * @dividend: 64bit dividend 123 * @dividend: 64bit dividend
84 * @divisor: 64bit divisor 124 * @divisor: 64bit divisor