make oldconfig will rebuild these...
[linux-2.4.21-pre4.git] / include / asm-mips / div64.h
1 /*
2  * Copyright (C) 2000  Maciej W. Rozycki
3  *
4  * This file is subject to the terms and conditions of the GNU General Public
5  * License.  See the file "COPYING" in the main directory of this archive
6  * for more details.
7  */
8 #ifndef _ASM_DIV64_H
9 #define _ASM_DIV64_H
10
11 #include <asm/sgidefs.h>
12
13 /*
14  * No traps on overflows for any of these...
15  */
16
17 #define do_div64_32(res, high, low, base) ({ \
18         unsigned long __quot, __mod; \
19         unsigned long __cf, __tmp, __tmp2, __i; \
20         \
21         __asm__(".set   push\n\t" \
22                 ".set   noat\n\t" \
23                 ".set   noreorder\n\t" \
24                 "move   %2, $0\n\t" \
25                 "move   %3, $0\n\t" \
26                 "b      1f\n\t" \
27                 " li    %4, 0x21\n" \
28                 "0:\n\t" \
29                 "sll    $1, %0, 0x1\n\t" \
30                 "srl    %3, %0, 0x1f\n\t" \
31                 "or     %0, $1, %5\n\t" \
32                 "sll    %1, %1, 0x1\n\t" \
33                 "sll    %2, %2, 0x1\n" \
34                 "1:\n\t" \
35                 "bnez   %3, 2f\n\t" \
36                 "sltu   %5, %0, %z6\n\t" \
37                 "bnez   %5, 3f\n\t" \
38                 "2:\n\t" \
39                 " addiu %4,%4,-1\n\t" \
40                 "subu   %0, %0, %z6\n\t" \
41                 "addiu  %2, %2, 1\n" \
42                 "3:\n\t" \
43                 "bnez   %4, 0b\n\t" \
44                 " srl   %5, %1, 0x1f\n\t" \
45                 ".set   pop" \
46                 : "=&r" (__mod), "=&r" (__tmp), "=&r" (__quot), "=&r" (__cf), \
47                   "=&r" (__i), "=&r" (__tmp2) \
48                 : "Jr" (base), "0" (high), "1" (low)); \
49         \
50         (res) = __quot; \
51         __mod; })
52
53 #define do_div(n, base) ({ \
54         unsigned long long __quot; \
55         unsigned long __upper, __low, __high, __mod; \
56         \
57         __quot = (n); \
58         __high = __quot >> 32; \
59         __low = __quot; \
60         __upper = __high; \
61         \
62         if (__high) \
63                 __asm__("divu   $0,%z2,%z3" \
64                         : "=h" (__upper), "=l" (__high) \
65                         : "Jr" (__high), "Jr" (base)); \
66         \
67         __mod = do_div64_32(__low, __upper, __low, base); \
68         \
69         __quot = __high; \
70         __quot = __quot << 32 | __low; \
71         (n) = __quot; \
72         __mod; })
73
74 #endif /* _ASM_DIV64_H */