aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/linux/math64.h19
-rw-r--r--lib/div64.c15
2 files changed, 20 insertions, 14 deletions
diff --git a/include/linux/math64.h b/include/linux/math64.h
index 177785e1e4a3..c87f1528703a 100644
--- a/include/linux/math64.h
+++ b/include/linux/math64.h
@@ -83,4 +83,23 @@ static inline s64 div_s64(s64 dividend, s32 divisor)
83 83
84u32 iter_div_u64_rem(u64 dividend, u32 divisor, u64 *remainder); 84u32 iter_div_u64_rem(u64 dividend, u32 divisor, u64 *remainder);
85 85
86static __always_inline u32
87__iter_div_u64_rem(u64 dividend, u32 divisor, u64 *remainder)
88{
89 u32 ret = 0;
90
91 while (dividend >= divisor) {
92 /* The following asm() prevents the compiler from
93 optimising this loop into a modulo operation. */
94 asm("" : "+rm"(dividend));
95
96 dividend -= divisor;
97 ret++;
98 }
99
100 *remainder = dividend;
101
102 return ret;
103}
104
86#endif /* _LINUX_MATH64_H */ 105#endif /* _LINUX_MATH64_H */
diff --git a/lib/div64.c b/lib/div64.c
index 76c01542d3e1..a111eb8de9cf 100644
--- a/lib/div64.c
+++ b/lib/div64.c
@@ -105,19 +105,6 @@ EXPORT_SYMBOL(div64_u64);
105 */ 105 */
106u32 iter_div_u64_rem(u64 dividend, u32 divisor, u64 *remainder) 106u32 iter_div_u64_rem(u64 dividend, u32 divisor, u64 *remainder)
107{ 107{
108 u32 ret = 0; 108 return __iter_div_u64_rem(dividend, divisor, remainder);
109
110 while (dividend >= divisor) {
111 /* The following asm() prevents the compiler from
112 optimising this loop into a modulo operation. */
113 asm("" : "+rm"(dividend));
114
115 dividend -= divisor;
116 ret++;
117 }
118
119 *remainder = dividend;
120
121 return ret;
122} 109}
123EXPORT_SYMBOL(iter_div_u64_rem); 110EXPORT_SYMBOL(iter_div_u64_rem);