summaryrefslogtreecommitdiffstats
path: root/include/linux/math64.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/linux/math64.h')
-rw-r--r--include/linux/math64.h29
1 files changed, 29 insertions, 0 deletions
diff --git a/include/linux/math64.h b/include/linux/math64.h
index 44282ec7b682..6e8b5b270ffe 100644
--- a/include/linux/math64.h
+++ b/include/linux/math64.h
@@ -214,4 +214,33 @@ static inline u64 mul_u64_u64_shr(u64 a, u64 b, unsigned int shift)
214 214
215#endif 215#endif
216 216
217#ifndef mul_u64_u32_div
218static inline u64 mul_u64_u32_div(u64 a, u32 mul, u32 divisor)
219{
220 union {
221 u64 ll;
222 struct {
223#ifdef __BIG_ENDIAN
224 u32 high, low;
225#else
226 u32 low, high;
227#endif
228 } l;
229 } u, rl, rh;
230
231 u.ll = a;
232 rl.ll = (u64)u.l.low * mul;
233 rh.ll = (u64)u.l.high * mul + rl.l.high;
234
235 /* Bits 32-63 of the result will be in rh.l.low. */
236 rl.l.high = do_div(rh.ll, divisor);
237
238 /* Bits 0-31 of the result will be in rl.l.low. */
239 do_div(rl.ll, divisor);
240
241 rl.l.high = rh.l.low;
242 return rl.ll;
243}
244#endif /* mul_u64_u32_div */
245
217#endif /* _LINUX_MATH64_H */ 246#endif /* _LINUX_MATH64_H */