Line | |
---|
1 | #ifndef __I386_DIV64 |
---|
2 | #define __I386_DIV64 |
---|
3 | |
---|
4 | #include <xen/types.h> |
---|
5 | |
---|
6 | #if BITS_PER_LONG == 64 |
---|
7 | |
---|
8 | # define do_div(n,base) ({ \ |
---|
9 | uint32_t __base = (base); \ |
---|
10 | uint32_t __rem; \ |
---|
11 | __rem = ((uint64_t)(n)) % __base; \ |
---|
12 | (n) = ((uint64_t)(n)) / __base; \ |
---|
13 | __rem; \ |
---|
14 | }) |
---|
15 | |
---|
16 | #else |
---|
17 | |
---|
18 | /* |
---|
19 | * do_div() is NOT a C function. It wants to return |
---|
20 | * two values (the quotient and the remainder), but |
---|
21 | * since that doesn't work very well in C, what it |
---|
22 | * does is: |
---|
23 | * |
---|
24 | * - modifies the 64-bit dividend _in_place_ |
---|
25 | * - returns the 32-bit remainder |
---|
26 | * |
---|
27 | * This ends up being the most efficient "calling |
---|
28 | * convention" on x86. |
---|
29 | */ |
---|
30 | #define do_div(n,base) ({ \ |
---|
31 | unsigned long __upper, __low, __high, __mod, __base; \ |
---|
32 | __base = (base); \ |
---|
33 | asm("":"=a" (__low), "=d" (__high):"A" (n)); \ |
---|
34 | __upper = __high; \ |
---|
35 | if (__high) { \ |
---|
36 | __upper = __high % (__base); \ |
---|
37 | __high = __high / (__base); \ |
---|
38 | } \ |
---|
39 | asm("divl %2":"=a" (__low), "=d" (__mod):"rm" (__base), "0" (__low), "1" (__upper)); \ |
---|
40 | asm("":"=A" (n):"a" (__low),"d" (__high)); \ |
---|
41 | __mod; \ |
---|
42 | }) |
---|
43 | |
---|
44 | #endif |
---|
45 | |
---|
46 | #endif |
---|
Note: See
TracBrowser
for help on using the repository browser.