initial commit with v2.6.9
[linux-2.6.9-moxart.git] / include / asm-mips / div64.h
blob7e7e2ea0d6cf9c47bc61585ad41d8fc8e17f7172
1 /*
2 * Copyright (C) 2000 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
7 * for more details.
8 */
9 #ifndef _ASM_DIV64_H
10 #define _ASM_DIV64_H
12 #if (_MIPS_SZLONG == 32)
15 * No traps on overflows for any of these...
18 #define do_div64_32(res, high, low, base) ({ \
19 unsigned long __quot, __mod; \
20 unsigned long __cf, __tmp, __tmp2, __i; \
22 __asm__(".set push\n\t" \
23 ".set noat\n\t" \
24 ".set noreorder\n\t" \
25 "move %2, $0\n\t" \
26 "move %3, $0\n\t" \
27 "b 1f\n\t" \
28 " li %4, 0x21\n" \
29 "0:\n\t" \
30 "sll $1, %0, 0x1\n\t" \
31 "srl %3, %0, 0x1f\n\t" \
32 "or %0, $1, %5\n\t" \
33 "sll %1, %1, 0x1\n\t" \
34 "sll %2, %2, 0x1\n" \
35 "1:\n\t" \
36 "bnez %3, 2f\n\t" \
37 " sltu %5, %0, %z6\n\t" \
38 "bnez %5, 3f\n" \
39 "2:\n\t" \
40 " addiu %4, %4, -1\n\t" \
41 "subu %0, %0, %z6\n\t" \
42 "addiu %2, %2, 1\n" \
43 "3:\n\t" \
44 "bnez %4, 0b\n\t" \
45 " srl %5, %1, 0x1f\n\t" \
46 ".set pop" \
47 : "=&r" (__mod), "=&r" (__tmp), "=&r" (__quot), "=&r" (__cf), \
48 "=&r" (__i), "=&r" (__tmp2) \
49 : "Jr" (base), "0" (high), "1" (low)); \
51 (res) = __quot; \
52 __mod; })
54 #define do_div(n, base) ({ \
55 unsigned long long __quot; \
56 unsigned long __mod; \
57 unsigned long long __div; \
58 unsigned long __upper, __low, __high, __base; \
60 __div = (n); \
61 __base = (base); \
63 __high = __div >> 32; \
64 __low = __div; \
65 __upper = __high; \
67 if (__high) \
68 __asm__("divu $0, %z2, %z3" \
69 : "=h" (__upper), "=l" (__high) \
70 : "Jr" (__high), "Jr" (__base)); \
72 __mod = do_div64_32(__low, __upper, __low, __base); \
74 __quot = __high; \
75 __quot = __quot << 32 | __low; \
76 (n) = __quot; \
77 __mod; })
78 #endif /* (_MIPS_SZLONG == 32) */
80 #if (_MIPS_SZLONG == 64)
83 * Don't use this one in new code
85 #define do_div64_32(res, high, low, base) ({ \
86 unsigned int __quot, __mod; \
87 unsigned long __div; \
88 unsigned int __low, __high, __base; \
90 __high = (high); \
91 __low = (low); \
92 __div = __high; \
93 __div = __div << 32 | __low; \
94 __base = (base); \
96 __mod = __div % __base; \
97 __div = __div / __base; \
99 __quot = __div; \
100 (res) = __quot; \
101 __mod; })
104 * Hey, we're already 64-bit, no
105 * need to play games..
107 #define do_div(n, base) ({ \
108 unsigned long __quot; \
109 unsigned int __mod; \
110 unsigned long __div; \
111 unsigned int __base; \
113 __div = (n); \
114 __base = (base); \
116 __mod = __div % __base; \
117 __quot = __div / __base; \
119 (n) = __quot; \
120 __mod; })
122 #endif /* (_MIPS_SZLONG == 64) */
124 #endif /* _ASM_DIV64_H */