blob: dc5ea57364408a0ee2b302c169273274a78934f4 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Copyright (C) 2000, 2004 Maciej W. Rozycki
Stephen Hemminger3927f2e2007-03-25 19:54:23 -07003 * Copyright (C) 2003, 07 Ralf Baechle (ralf@linux-mips.org)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
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 */
Ralf Baechlec21004c2009-04-30 18:14:56 +02009#ifndef __ASM_DIV64_H
10#define __ASM_DIV64_H
11
12#include <asm-generic/div64.h>
13
14#if BITS_PER_LONG == 64
Linus Torvalds1da177e2005-04-16 15:20:36 -070015
Stephen Hemminger3927f2e2007-03-25 19:54:23 -070016#include <linux/types.h>
17
Linus Torvalds1da177e2005-04-16 15:20:36 -070018/*
19 * No traps on overflows for any of these...
20 */
21
Ralf Baechlec21004c2009-04-30 18:14:56 +020022#define __div64_32(n, base) \
23({ \
24 unsigned long __cf, __tmp, __tmp2, __i; \
25 unsigned long __quot32, __mod32; \
26 unsigned long __high, __low; \
27 unsigned long long __n; \
28 \
29 __high = *__n >> 32; \
30 __low = __n; \
31 __asm__( \
32 " .set push \n" \
33 " .set noat \n" \
34 " .set noreorder \n" \
35 " move %2, $0 \n" \
36 " move %3, $0 \n" \
37 " b 1f \n" \
38 " li %4, 0x21 \n" \
39 "0: \n" \
40 " sll $1, %0, 0x1 \n" \
41 " srl %3, %0, 0x1f \n" \
42 " or %0, $1, %5 \n" \
43 " sll %1, %1, 0x1 \n" \
44 " sll %2, %2, 0x1 \n" \
45 "1: \n" \
46 " bnez %3, 2f \n" \
47 " sltu %5, %0, %z6 \n" \
48 " bnez %5, 3f \n" \
49 "2: \n" \
50 " addiu %4, %4, -1 \n" \
51 " subu %0, %0, %z6 \n" \
52 " addiu %2, %2, 1 \n" \
53 "3: \n" \
54 " bnez %4, 0b\n\t" \
55 " srl %5, %1, 0x1f\n\t" \
56 " .set pop" \
57 : "=&r" (__mod32), "=&r" (__tmp), \
58 "=&r" (__quot32), "=&r" (__cf), \
59 "=&r" (__i), "=&r" (__tmp2) \
60 : "Jr" (base), "0" (__high), "1" (__low)); \
61 \
62 (__n) = __quot32; \
63 __mod32; \
64})
Linus Torvalds1da177e2005-04-16 15:20:36 -070065
Ralf Baechlec21004c2009-04-30 18:14:56 +020066#endif /* BITS_PER_LONG == 64 */
Stephen Hemminger3927f2e2007-03-25 19:54:23 -070067
Ralf Baechlec21004c2009-04-30 18:14:56 +020068#endif /* __ASM_DIV64_H */