2 * Copyright (C) 2000, 2004, 2021 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 <asm/bitsperlong.h>
14 #if BITS_PER_LONG == 32
17 * No traps on overflows for any of these...
20 #define do_div64_32(res, high, low, base) ({ \
21 unsigned long __cf, __tmp, __tmp2, __i; \
22 unsigned long __quot32, __mod32; \
27 " .set noreorder \n" \
33 " sll $1, %0, 0x1 \n" \
34 " srl %3, %0, 0x1f \n" \
36 " sll %1, %1, 0x1 \n" \
37 " sll %2, %2, 0x1 \n" \
40 " sltu %5, %0, %z6 \n" \
43 " addiu %4, %4, -1 \n" \
44 " subu %0, %0, %z6 \n" \
45 " addiu %2, %2, 1 \n" \
48 " srl %5, %1, 0x1f \n" \
50 : "=&r" (__mod32), "=&r" (__tmp), \
51 "=&r" (__quot32), "=&r" (__cf), \
52 "=&r" (__i), "=&r" (__tmp2) \
53 : "Jr" (base), "0" (high), "1" (low)); \
59 #define __div64_32(n, base) ({ \
60 unsigned long __upper, __low, __high, __radix; \
61 unsigned long long __quot; \
62 unsigned long long __div; \
63 unsigned long __mod; \
68 __high = __div >> 32; \
71 if (__high < __radix) { \
75 __upper = __high % __radix; \
79 __mod = do_div64_32(__low, __upper, __low, __radix); \
82 __quot = __quot << 32 | __low; \
87 #endif /* BITS_PER_LONG == 32 */
89 #include <asm-generic/div64.h>
91 #endif /* __ASM_DIV64_H */