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
10 * - modifies the 64-bit dividend _in_place_
11 * - returns the 32-bit remainder
13 * This ends up being the most efficient "calling
16 #define do_div(n,base) ({ \
17 unsigned long __upper, __low, __high, __mod, __base; \
19 asm("":"=a" (__low), "=d" (__high):"A" (n)); \
22 __upper = __high % (__base); \
23 __high = __high / (__base); \
25 asm("divl %2":"=a" (__low), "=d" (__mod):"rm" (__base), "0" (__low), "1" (__upper)); \
26 asm("":"=A" (n):"a" (__low),"d" (__high)); \
31 * (long)X = ((long long)divs) / (long)div
32 * (long)rem = ((long long)divs) % (long)div
34 * Warning, this will do an exception if X overflows.
36 #define div_long_long_rem(a,b,c) div_ll_X_l_rem(a,b,c)
39 div_ll_X_l_rem(long long divs
, long div
, long *rem
)
42 __asm__("divl %2":"=a"(dum2
), "=d"(*rem
)
43 : "rm"(div
), "A"(divs
));