2 * Copyright (C) 2000, 2004 Maciej W. Rozycki
3 * Copyright (C) 2003, 07 Ralf Baechle (ralf@linux-mips.org)
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 #include <linux/types.h>
14 #if (_MIPS_SZLONG == 32)
16 #include <asm/compiler.h>
19 * No traps on overflows for any of these...
22 #define do_div64_32(res, high, low, base) ({ \
23 unsigned long __quot, __mod; \
24 unsigned long __cf, __tmp, __tmp2, __i; \
26 __asm__(".set push\n\t" \
28 ".set noreorder\n\t" \
34 "sll $1, %0, 0x1\n\t" \
35 "srl %3, %0, 0x1f\n\t" \
37 "sll %1, %1, 0x1\n\t" \
41 " sltu %5, %0, %z6\n\t" \
44 " addiu %4, %4, -1\n\t" \
45 "subu %0, %0, %z6\n\t" \
49 " srl %5, %1, 0x1f\n\t" \
51 : "=&r" (__mod), "=&r" (__tmp), "=&r" (__quot), "=&r" (__cf), \
52 "=&r" (__i), "=&r" (__tmp2) \
53 : "Jr" (base), "0" (high), "1" (low)); \
58 #define do_div(n, base) ({ \
59 unsigned long long __quot; \
60 unsigned long __mod; \
61 unsigned long long __div; \
62 unsigned long __upper, __low, __high, __base; \
67 __high = __div >> 32; \
72 __asm__("divu $0, %z2, %z3" \
73 : "=h" (__upper), "=l" (__high) \
74 : "Jr" (__high), "Jr" (__base) \
77 __mod = do_div64_32(__low, __upper, __low, __base); \
80 __quot = __quot << 32 | __low; \
84 extern uint64_t div64_64(uint64_t dividend, uint64_t divisor);
85 #endif /* (_MIPS_SZLONG == 32) */
87 #if (_MIPS_SZLONG == 64)
90 * Hey, we're already 64-bit, no
91 * need to play games..
93 #define do_div(n, base) ({ \
94 unsigned long __quot; \
96 unsigned long __div; \
97 unsigned int __base; \
102 __mod = __div % __base; \
103 __quot = __div / __base; \
108 static inline uint64_t div64_64(uint64_t dividend, uint64_t divisor)
110 return dividend / divisor;
113 #endif /* (_MIPS_SZLONG == 64) */
115 #endif /* _ASM_DIV64_H */