diff options
-rw-r--r-- | include/linux/math64.h | 19 | ||||
-rw-r--r-- | lib/div64.c | 19 |
2 files changed, 7 insertions, 31 deletions
diff --git a/include/linux/math64.h b/include/linux/math64.h index 931a619407bf..b8ba85544721 100644 --- a/include/linux/math64.h +++ b/include/linux/math64.h | |||
@@ -30,15 +30,6 @@ static inline s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder) | |||
30 | } | 30 | } |
31 | 31 | ||
32 | /** | 32 | /** |
33 | * div64_u64_rem - unsigned 64bit divide with 64bit divisor | ||
34 | */ | ||
35 | static inline u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder) | ||
36 | { | ||
37 | *remainder = dividend % divisor; | ||
38 | return dividend / divisor; | ||
39 | } | ||
40 | |||
41 | /** | ||
42 | * div64_u64 - unsigned 64bit divide with 64bit divisor | 33 | * div64_u64 - unsigned 64bit divide with 64bit divisor |
43 | */ | 34 | */ |
44 | static inline u64 div64_u64(u64 dividend, u64 divisor) | 35 | static inline u64 div64_u64(u64 dividend, u64 divisor) |
@@ -70,16 +61,8 @@ static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder) | |||
70 | extern s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder); | 61 | extern s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder); |
71 | #endif | 62 | #endif |
72 | 63 | ||
73 | #ifndef div64_u64_rem | ||
74 | extern u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder); | ||
75 | #endif | ||
76 | |||
77 | #ifndef div64_u64 | 64 | #ifndef div64_u64 |
78 | static inline u64 div64_u64(u64 dividend, u64 divisor) | 65 | extern u64 div64_u64(u64 dividend, u64 divisor); |
79 | { | ||
80 | u64 remainder; | ||
81 | return div64_u64_rem(dividend, divisor, &remainder); | ||
82 | } | ||
83 | #endif | 66 | #endif |
84 | 67 | ||
85 | #ifndef div64_s64 | 68 | #ifndef div64_s64 |
diff --git a/lib/div64.c b/lib/div64.c index 3af5728d95fd..a163b6caef73 100644 --- a/lib/div64.c +++ b/lib/div64.c | |||
@@ -79,10 +79,9 @@ EXPORT_SYMBOL(div_s64_rem); | |||
79 | #endif | 79 | #endif |
80 | 80 | ||
81 | /** | 81 | /** |
82 | * div64_u64_rem - unsigned 64bit divide with 64bit divisor and 64bit remainder | 82 | * div64_u64 - unsigned 64bit divide with 64bit divisor |
83 | * @dividend: 64bit dividend | 83 | * @dividend: 64bit dividend |
84 | * @divisor: 64bit divisor | 84 | * @divisor: 64bit divisor |
85 | * @remainder: 64bit remainder | ||
86 | * | 85 | * |
87 | * This implementation is a modified version of the algorithm proposed | 86 | * This implementation is a modified version of the algorithm proposed |
88 | * by the book 'Hacker's Delight'. The original source and full proof | 87 | * by the book 'Hacker's Delight'. The original source and full proof |
@@ -90,33 +89,27 @@ EXPORT_SYMBOL(div_s64_rem); | |||
90 | * | 89 | * |
91 | * 'http://www.hackersdelight.org/HDcode/newCode/divDouble.c.txt' | 90 | * 'http://www.hackersdelight.org/HDcode/newCode/divDouble.c.txt' |
92 | */ | 91 | */ |
93 | #ifndef div64_u64_rem | 92 | #ifndef div64_u64 |
94 | u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder) | 93 | u64 div64_u64(u64 dividend, u64 divisor) |
95 | { | 94 | { |
96 | u32 high = divisor >> 32; | 95 | u32 high = divisor >> 32; |
97 | u64 quot; | 96 | u64 quot; |
98 | 97 | ||
99 | if (high == 0) { | 98 | if (high == 0) { |
100 | u32 rem32; | 99 | quot = div_u64(dividend, divisor); |
101 | quot = div_u64_rem(dividend, divisor, &rem32); | ||
102 | *remainder = rem32; | ||
103 | } else { | 100 | } else { |
104 | int n = 1 + fls(high); | 101 | int n = 1 + fls(high); |
105 | quot = div_u64(dividend >> n, divisor >> n); | 102 | quot = div_u64(dividend >> n, divisor >> n); |
106 | 103 | ||
107 | if (quot != 0) | 104 | if (quot != 0) |
108 | quot--; | 105 | quot--; |
109 | 106 | if ((dividend - quot * divisor) >= divisor) | |
110 | *remainder = dividend - quot * divisor; | ||
111 | if (*remainder >= divisor) { | ||
112 | quot++; | 107 | quot++; |
113 | *remainder -= divisor; | ||
114 | } | ||
115 | } | 108 | } |
116 | 109 | ||
117 | return quot; | 110 | return quot; |
118 | } | 111 | } |
119 | EXPORT_SYMBOL(div64_u64_rem); | 112 | EXPORT_SYMBOL(div64_u64); |
120 | #endif | 113 | #endif |
121 | 114 | ||
122 | /** | 115 | /** |