]>
git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blob - include/linux/math64.h
1 #ifndef _LINUX_MATH64_H
2 #define _LINUX_MATH64_H
4 #include <linux/types.h>
7 #if BITS_PER_LONG == 64
9 #define div64_long(x, y) div64_s64((x), (y))
10 #define div64_ul(x, y) div64_u64((x), (y))
13 * div_u64_rem - unsigned 64bit divide with 32bit divisor with remainder
15 * This is commonly provided by 32bit archs to provide an optimized 64bit
18 static inline u64
div_u64_rem(u64 dividend
, u32 divisor
, u32
*remainder
)
20 *remainder
= dividend
% divisor
;
21 return dividend
/ divisor
;
25 * div_s64_rem - signed 64bit divide with 32bit divisor with remainder
27 static inline s64
div_s64_rem(s64 dividend
, s32 divisor
, s32
*remainder
)
29 *remainder
= dividend
% divisor
;
30 return dividend
/ divisor
;
34 * div64_u64 - unsigned 64bit divide with 64bit divisor
36 static inline u64
div64_u64(u64 dividend
, u64 divisor
)
38 return dividend
/ divisor
;
42 * div64_s64 - signed 64bit divide with 64bit divisor
44 static inline s64
div64_s64(s64 dividend
, s64 divisor
)
46 return dividend
/ divisor
;
49 #elif BITS_PER_LONG == 32
51 #define div64_long(x, y) div_s64((x), (y))
52 #define div64_ul(x, y) div_u64((x), (y))
55 static inline u64
div_u64_rem(u64 dividend
, u32 divisor
, u32
*remainder
)
57 *remainder
= do_div(dividend
, divisor
);
63 extern s64
div_s64_rem(s64 dividend
, s32 divisor
, s32
*remainder
);
67 extern u64
div64_u64(u64 dividend
, u64 divisor
);
71 extern s64
div64_s64(s64 dividend
, s64 divisor
);
74 #endif /* BITS_PER_LONG */
77 * div_u64 - unsigned 64bit divide with 32bit divisor
79 * This is the most common 64bit divide and should be used if possible,
80 * as many 32bit archs can optimize this variant better than a full 64bit
84 static inline u64
div_u64(u64 dividend
, u32 divisor
)
87 return div_u64_rem(dividend
, divisor
, &remainder
);
92 * div_s64 - signed 64bit divide with 32bit divisor
95 static inline s64
div_s64(s64 dividend
, s32 divisor
)
98 return div_s64_rem(dividend
, divisor
, &remainder
);
102 u32
iter_div_u64_rem(u64 dividend
, u32 divisor
, u64
*remainder
);
104 static __always_inline u32
105 __iter_div_u64_rem(u64 dividend
, u32 divisor
, u64
*remainder
)
109 while (dividend
>= divisor
) {
110 /* The following asm() prevents the compiler from
111 optimising this loop into a modulo operation. */
112 asm("" : "+rm"(dividend
));
118 *remainder
= dividend
;
123 #endif /* _LINUX_MATH64_H */