diff options
author | Thomas Gleixner <tglx@linutronix.de> | 2006-01-09 23:52:20 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@g5.osdl.org> | 2006-01-10 11:01:35 -0500 |
commit | 5cca7619a562c9d98a3a0123dc878d79bf3c8fb3 (patch) | |
tree | 5efaebf38b6e546e8653f010209bbe3a29831810 /include/linux/calc64.h | |
parent | af4cd3fe4cfa75ca74f8d8622867371289043a8d (diff) |
[PATCH] hrtimer: move div_long_long_rem out of jiffies.h
move div_long_long_rem() from jiffies.h into a new calc64.h include file, as
it is a general math function useful for other things than the jiffy code.
Convert it to an inline function
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'include/linux/calc64.h')
-rw-r--r-- | include/linux/calc64.h | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/include/linux/calc64.h b/include/linux/calc64.h new file mode 100644 index 000000000000..ebf4b8f38d88 --- /dev/null +++ b/include/linux/calc64.h | |||
@@ -0,0 +1,49 @@ | |||
1 | #ifndef _LINUX_CALC64_H | ||
2 | #define _LINUX_CALC64_H | ||
3 | |||
4 | #include <linux/types.h> | ||
5 | #include <asm/div64.h> | ||
6 | |||
7 | /* | ||
8 | * This is a generic macro which is used when the architecture | ||
9 | * specific div64.h does not provide a optimized one. | ||
10 | * | ||
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. | ||
15 | */ | ||
16 | #ifndef div_long_long_rem | ||
17 | #define div_long_long_rem(dividend, divisor, remainder) \ | ||
18 | do_div_llr((dividend), divisor, remainder) | ||
19 | |||
20 | static inline unsigned long do_div_llr(const long long dividend, | ||
21 | const long divisor, long *remainder) | ||
22 | { | ||
23 | u64 result = dividend; | ||
24 | |||
25 | *(remainder) = do_div(result, divisor); | ||
26 | return (unsigned long) result; | ||
27 | } | ||
28 | #endif | ||
29 | |||
30 | /* | ||
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. | ||
34 | */ | ||
35 | static inline long div_long_long_rem_signed(const long long dividend, | ||
36 | const long divisor, long *remainder) | ||
37 | { | ||
38 | long res; | ||
39 | |||
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); | ||
45 | |||
46 | return res; | ||
47 | } | ||
48 | |||
49 | #endif | ||