Committer: Michael Beasley <mike@snafu.setup>
[mikesnafu-overlay.git] / include / linux / calc64.h
blobebf4b8f38d8820a95ca258b2345a800b951d2980
1 #ifndef _LINUX_CALC64_H
2 #define _LINUX_CALC64_H
4 #include <linux/types.h>
5 #include <asm/div64.h>
7 /*
8 * This is a generic macro which is used when the architecture
9 * specific div64.h does not provide a optimized one.
11 * The 64bit dividend is divided by the divisor (data type long), the
12 * result is returned and the remainder stored in the variable
13 * referenced by remainder (data type long *). In contrast to the
14 * do_div macro the dividend is kept intact.
16 #ifndef div_long_long_rem
17 #define div_long_long_rem(dividend, divisor, remainder) \
18 do_div_llr((dividend), divisor, remainder)
20 static inline unsigned long do_div_llr(const long long dividend,
21 const long divisor, long *remainder)
23 u64 result = dividend;
25 *(remainder) = do_div(result, divisor);
26 return (unsigned long) result;
28 #endif
31 * Sign aware variation of the above. On some architectures a
32 * negative dividend leads to an divide overflow exception, which
33 * is avoided by the sign check.
35 static inline long div_long_long_rem_signed(const long long dividend,
36 const long divisor, long *remainder)
38 long res;
40 if (unlikely(dividend < 0)) {
41 res = -div_long_long_rem(-dividend, divisor, remainder);
42 *remainder = -(*remainder);
43 } else
44 res = div_long_long_rem(dividend, divisor, remainder);
46 return res;
49 #endif