1 #ifndef _LINUX_MATH64_H
2 #define _LINUX_MATH64_H
4 #include <linux/types.h>
7 #if BITS_PER_LONG == 64
10 * div_u64_rem - unsigned 64bit divide with 32bit divisor with remainder
12 * This is commonly provided by 32bit archs to provide an optimized 64bit
15 static inline u64
div_u64_rem(u64 dividend
, u32 divisor
, u32
*remainder
)
17 *remainder
= dividend
% divisor
;
18 return dividend
/ divisor
;
22 * div_s64_rem - signed 64bit divide with 32bit divisor with remainder
24 static inline s64
div_s64_rem(s64 dividend
, s32 divisor
, s32
*remainder
)
26 *remainder
= dividend
% divisor
;
27 return dividend
/ divisor
;
31 * div64_u64 - unsigned 64bit divide with 64bit divisor
33 static inline u64
div64_u64(u64 dividend
, u64 divisor
)
35 return dividend
/ divisor
;
39 * div64_s64 - signed 64bit divide with 64bit divisor
41 static inline s64
div64_s64(s64 dividend
, s64 divisor
)
43 return dividend
/ divisor
;
46 #elif BITS_PER_LONG == 32
49 static inline u64
div_u64_rem(u64 dividend
, u32 divisor
, u32
*remainder
)
51 *remainder
= do_div(dividend
, divisor
);
57 extern s64
div_s64_rem(s64 dividend
, s32 divisor
, s32
*remainder
);
61 extern u64
div64_u64(u64 dividend
, u64 divisor
);
65 extern s64
div64_s64(s64 dividend
, s64 divisor
);
68 #endif /* BITS_PER_LONG */
71 * div_u64 - unsigned 64bit divide with 32bit divisor
73 * This is the most common 64bit divide and should be used if possible,
74 * as many 32bit archs can optimize this variant better than a full 64bit
78 static inline u64
div_u64(u64 dividend
, u32 divisor
)
81 return div_u64_rem(dividend
, divisor
, &remainder
);
86 * div_s64 - signed 64bit divide with 32bit divisor
89 static inline s64
div_s64(s64 dividend
, s32 divisor
)
92 return div_s64_rem(dividend
, divisor
, &remainder
);
96 u32
iter_div_u64_rem(u64 dividend
, u32 divisor
, u64
*remainder
);
98 static __always_inline u32
99 __iter_div_u64_rem(u64 dividend
, u32 divisor
, u64
*remainder
)
103 while (dividend
>= divisor
) {
104 /* The following asm() prevents the compiler from
105 optimising this loop into a modulo operation. */
106 asm("" : "+rm"(dividend
));
112 *remainder
= dividend
;
117 #endif /* _LINUX_MATH64_H */