blob: 6d760d75c4f789e95776adc7733aba3fbe850829 [file] [log] [blame]
Stefan Roese9eefe2a2009-03-19 15:35:05 +01001#ifndef _LINUX_MATH64_H
2#define _LINUX_MATH64_H
3
4#include <linux/types.h>
5
6#if BITS_PER_LONG == 64
7
8/**
9 * div_u64_rem - unsigned 64bit divide with 32bit divisor with remainder
10 *
11 * This is commonly provided by 32bit archs to provide an optimized 64bit
12 * divide.
13 */
14static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
15{
16 *remainder = dividend % divisor;
17 return dividend / divisor;
18}
19
20/**
21 * div_s64_rem - signed 64bit divide with 32bit divisor with remainder
22 */
23static inline s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
24{
25 *remainder = dividend % divisor;
26 return dividend / divisor;
27}
28
29/**
30 * div64_u64 - unsigned 64bit divide with 64bit divisor
31 */
32static inline u64 div64_u64(u64 dividend, u64 divisor)
33{
34 return dividend / divisor;
35}
36
37#elif BITS_PER_LONG == 32
38
39#ifndef div_u64_rem
40static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
41{
42 *remainder = do_div(dividend, divisor);
43 return dividend;
44}
45#endif
46
47#ifndef div_s64_rem
48extern s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder);
49#endif
50
51#ifndef div64_u64
52extern u64 div64_u64(u64 dividend, u64 divisor);
53#endif
54
55#endif /* BITS_PER_LONG */
56
57/**
58 * div_u64 - unsigned 64bit divide with 32bit divisor
59 *
60 * This is the most common 64bit divide and should be used if possible,
61 * as many 32bit archs can optimize this variant better than a full 64bit
62 * divide.
63 */
64#ifndef div_u64
65static inline u64 div_u64(u64 dividend, u32 divisor)
66{
67 u32 remainder;
68 return div_u64_rem(dividend, divisor, &remainder);
69}
70#endif
71
72/**
73 * div_s64 - signed 64bit divide with 32bit divisor
74 */
75#ifndef div_s64
76static inline s64 div_s64(s64 dividend, s32 divisor)
77{
78 s32 remainder;
79 return div_s64_rem(dividend, divisor, &remainder);
80}
81#endif
82
83u32 iter_div_u64_rem(u64 dividend, u32 divisor, u64 *remainder);
84
85#endif /* _LINUX_MATH64_H */