div64.h

Go to the documentation of this file.
00001 #ifndef __I386_DIV64
00002 #define __I386_DIV64
00003 
00004 /*
00005  * do_div() is NOT a C function. It wants to return
00006  * two values (the quotient and the remainder), but
00007  * since that doesn't work very well in C, what it
00008  * does is:
00009  *
00010  * - modifies the 64-bit dividend _in_place_
00011  * - returns the 32-bit remainder
00012  *
00013  * This ends up being the most efficient "calling
00014  * convention" on x86.
00015  */
00016 #define do_div(n,base) ({ \
00017         unsigned long __upper, __low, __high, __mod, __base; \
00018         __base = (base); \
00019         asm("":"=a" (__low), "=d" (__high):"A" (n)); \
00020         __upper = __high; \
00021         if (__high) { \
00022                 __upper = __high % (__base); \
00023                 __high = __high / (__base); \
00024         } \
00025         asm("divl %2":"=a" (__low), "=d" (__mod):"rm" (__base), "0" (__low), "1" (__upper)); \
00026         asm("":"=A" (n):"a" (__low),"d" (__high)); \
00027         __mod; \
00028 })
00029 
00030 /*
00031  * (long)X = ((long long)divs) / (long)div
00032  * (long)rem = ((long long)divs) % (long)div
00033  *
00034  * Warning, this will do an exception if X overflows.
00035  */
00036 #define div_long_long_rem(a,b,c) div_ll_X_l_rem(a,b,c)
00037 
00038 extern inline long
00039 div_ll_X_l_rem(long long divs, long div, long *rem)
00040 {
00041         long dum2;
00042       __asm__("divl %2":"=a"(dum2), "=d"(*rem)
00043       : "rm"(div), "A"(divs));
00044 
00045         return dum2;
00046 
00047 }
00048 #endif

Generated on Mon Dec 29 10:54:06 2008 for coreboot by  doxygen 1.5.5