2 * Copyright (C) 2000, 2004 Maciej W. Rozycki
3 * Copyright (C) 2003 Ralf Baechle
5 * This file is subject to the terms and conditions of the GNU General Public
6 * License. See the file "COPYING" in the main directory of this archive
12 #if (_MIPS_SZLONG == 32)
14 #include <asm/compiler.h>
17 * No traps on overflows for any of these...
20 #define do_div64_32(res, high, low, base) ({ \
21 unsigned long __quot, __mod; \
22 unsigned long __cf, __tmp, __tmp2, __i; \
24 __asm__(".set push\n\t" \
26 ".set noreorder\n\t" \
32 "sll $1, %0, 0x1\n\t" \
33 "srl %3, %0, 0x1f\n\t" \
35 "sll %1, %1, 0x1\n\t" \
39 " sltu %5, %0, %z6\n\t" \
42 " addiu %4, %4, -1\n\t" \
43 "subu %0, %0, %z6\n\t" \
47 " srl %5, %1, 0x1f\n\t" \
49 : "=&r" (__mod), "=&r" (__tmp), "=&r" (__quot), "=&r" (__cf), \
50 "=&r" (__i), "=&r" (__tmp2) \
51 : "Jr" (base), "0" (high), "1" (low)); \
56 #define do_div(n, base) ({ \
57 unsigned long long __quot; \
58 unsigned long __mod; \
59 unsigned long long __div; \
60 unsigned long __upper, __low, __high, __base; \
65 __high = __div >> 32; \
70 __asm__("divu $0, %z2, %z3" \
71 : "=h" (__upper), "=l" (__high) \
72 : "Jr" (__high), "Jr" (__base) \
75 __mod = do_div64_32(__low, __upper, __low, __base); \
78 __quot = __quot << 32 | __low; \
81 #endif /* (_MIPS_SZLONG == 32) */
83 #if (_MIPS_SZLONG == 64)
86 * Hey, we're already 64-bit, no
87 * need to play games..
89 #define do_div(n, base) ({ \
90 unsigned long __quot; \
92 unsigned long __div; \
93 unsigned int __base; \
98 __mod = __div % __base; \
99 __quot = __div / __base; \
104 #endif /* (_MIPS_SZLONG == 64) */
106 #endif /* _ASM_DIV64_H */