aboutsummaryrefslogtreecommitdiffstats
path: root/include/asm-i386/div64.h
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /include/asm-i386/div64.h
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'include/asm-i386/div64.h')
-rw-r--r--include/asm-i386/div64.h48
1 files changed, 48 insertions, 0 deletions
diff --git a/include/asm-i386/div64.h b/include/asm-i386/div64.h
new file mode 100644
index 000000000000..28ed8b296afc
--- /dev/null
+++ b/include/asm-i386/div64.h
@@ -0,0 +1,48 @@
1#ifndef __I386_DIV64
2#define __I386_DIV64
3
4/*
5 * do_div() is NOT a C function. It wants to return
6 * two values (the quotient and the remainder), but
7 * since that doesn't work very well in C, what it
8 * does is:
9 *
10 * - modifies the 64-bit dividend _in_place_
11 * - returns the 32-bit remainder
12 *
13 * This ends up being the most efficient "calling
14 * convention" on x86.
15 */
16#define do_div(n,base) ({ \
17 unsigned long __upper, __low, __high, __mod, __base; \
18 __base = (base); \
19 asm("":"=a" (__low), "=d" (__high):"A" (n)); \
20 __upper = __high; \
21 if (__high) { \
22 __upper = __high % (__base); \
23 __high = __high / (__base); \
24 } \
25 asm("divl %2":"=a" (__low), "=d" (__mod):"rm" (__base), "0" (__low), "1" (__upper)); \
26 asm("":"=A" (n):"a" (__low),"d" (__high)); \
27 __mod; \
28})
29
30/*
31 * (long)X = ((long long)divs) / (long)div
32 * (long)rem = ((long long)divs) % (long)div
33 *
34 * Warning, this will do an exception if X overflows.
35 */
36#define div_long_long_rem(a,b,c) div_ll_X_l_rem(a,b,c)
37
38extern inline long
39div_ll_X_l_rem(long long divs, long div, long *rem)
40{
41 long dum2;
42 __asm__("divl %2":"=a"(dum2), "=d"(*rem)
43 : "rm"(div), "A"(divs));
44
45 return dum2;
46
47}
48#endif