1 From: Ralf Baechle <ralf@linux-mips.org>
2 Date: Thu, 30 Apr 2009 16:14:56 +0000 (+0200)
3 Subject: MIPS: Rewrite <asm/div64.h> to work with gcc 4.4.0.
4 X-Git-Url: http://www.linux-mips.org/git?p=linux.git;a=commitdiff_plain;h=a1b68289997030df64cba8478d5767fe10e42a58
6 MIPS: Rewrite <asm/div64.h> to work with gcc 4.4.0.
8 The inline assembler used on 32-bit kernels was using the "h" constraint
9 which was considered dangerous and removed for gcc 4.4.0.
11 Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
14 --- a/include/asm-mips/div64.h
15 +++ b/include/asm-mips/div64.h
17 * License. See the file "COPYING" in the main directory of this archive
22 +#ifndef __ASM_DIV64_H
23 +#define __ASM_DIV64_H
25 -#include <linux/types.h>
26 +#include <asm-generic/div64.h>
28 -#if (_MIPS_SZLONG == 32)
29 +#if BITS_PER_LONG == 64
31 -#include <asm/compiler.h>
32 +#include <linux/types.h>
35 * No traps on overflows for any of these...
38 -#define do_div64_32(res, high, low, base) ({ \
39 - unsigned long __quot32, __mod32; \
40 - unsigned long __cf, __tmp, __tmp2, __i; \
42 - __asm__(".set push\n\t" \
44 - ".set noreorder\n\t" \
50 - "sll $1, %0, 0x1\n\t" \
51 - "srl %3, %0, 0x1f\n\t" \
52 - "or %0, $1, %5\n\t" \
53 - "sll %1, %1, 0x1\n\t" \
54 - "sll %2, %2, 0x1\n" \
57 - " sltu %5, %0, %z6\n\t" \
60 - " addiu %4, %4, -1\n\t" \
61 - "subu %0, %0, %z6\n\t" \
62 - "addiu %2, %2, 1\n" \
65 - " srl %5, %1, 0x1f\n\t" \
67 - : "=&r" (__mod32), "=&r" (__tmp), \
68 - "=&r" (__quot32), "=&r" (__cf), \
69 - "=&r" (__i), "=&r" (__tmp2) \
70 - : "Jr" (base), "0" (high), "1" (low)); \
75 -#define do_div(n, base) ({ \
76 - unsigned long long __quot; \
77 - unsigned long __mod; \
78 - unsigned long long __div; \
79 - unsigned long __upper, __low, __high, __base; \
84 - __high = __div >> 32; \
89 - __asm__("divu $0, %z2, %z3" \
90 - : "=h" (__upper), "=l" (__high) \
91 - : "Jr" (__high), "Jr" (__base) \
94 - __mod = do_div64_32(__low, __upper, __low, __base); \
97 - __quot = __quot << 32 | __low; \
101 -#endif /* (_MIPS_SZLONG == 32) */
103 -#if (_MIPS_SZLONG == 64)
106 - * Hey, we're already 64-bit, no
107 - * need to play games..
109 -#define do_div(n, base) ({ \
110 - unsigned long __quot; \
111 - unsigned int __mod; \
112 - unsigned long __div; \
113 - unsigned int __base; \
118 - __mod = __div % __base; \
119 - __quot = __div / __base; \
123 +#define __div64_32(n, base) \
125 + unsigned long __cf, __tmp, __tmp2, __i; \
126 + unsigned long __quot32, __mod32; \
127 + unsigned long __high, __low; \
128 + unsigned long long __n; \
130 + __high = *__n >> 32; \
135 + " .set noreorder \n" \
136 + " move %2, $0 \n" \
137 + " move %3, $0 \n" \
139 + " li %4, 0x21 \n" \
141 + " sll $1, %0, 0x1 \n" \
142 + " srl %3, %0, 0x1f \n" \
143 + " or %0, $1, %5 \n" \
144 + " sll %1, %1, 0x1 \n" \
145 + " sll %2, %2, 0x1 \n" \
147 + " bnez %3, 2f \n" \
148 + " sltu %5, %0, %z6 \n" \
149 + " bnez %5, 3f \n" \
151 + " addiu %4, %4, -1 \n" \
152 + " subu %0, %0, %z6 \n" \
153 + " addiu %2, %2, 1 \n" \
155 + " bnez %4, 0b\n\t" \
156 + " srl %5, %1, 0x1f\n\t" \
158 + : "=&r" (__mod32), "=&r" (__tmp), \
159 + "=&r" (__quot32), "=&r" (__cf), \
160 + "=&r" (__i), "=&r" (__tmp2) \
161 + : "Jr" (base), "0" (__high), "1" (__low)); \
163 + (__n) = __quot32; \
167 -#endif /* (_MIPS_SZLONG == 64) */
168 +#endif /* BITS_PER_LONG == 64 */
170 -#endif /* _ASM_DIV64_H */
171 +#endif /* __ASM_DIV64_H */