On Wed, Dec 14, 2005 at 17:49:53 +0100, Jesper Juhl wrote: > On 12/14/05, Jan Hudec <bulb@xxxxxx> wrote: > > On Tue, Dec 13, 2005 at 23:05:57 +0100, Jesper Juhl wrote: > > > On 12/13/05, ppunnam@xxxxxxxxxxx <ppunnam@xxxxxxxxxxx> wrote: > > > > > > > > > > > > Hi, > > > > can any one tell me how can we caluculate the 64 bit division in > > > > user space. I got two __u64 variables, something similar to the > > > > do_div (asm/div64.h) in kernel. > > > > > > > > > > Just do a normal division. If you are using a 64bit architecture with > > > a 64bit userspace / compiler / toolchain and doing divisions on 64bit > > > long types, then your compiler should take care of generating the > > > proper 64bit div's all on its own. > > > > You don't have to be on a 64-bit architecture nor use 64-bit userspace. > > You just need a compiler that supports 64-bit integeral type. Then > > simply use / (but make sure both operands and result are 64-bit). > > > Well, true, but if it's not a 64bit arch, then the division will end > up being done in multiple steps whereas on a 64bit arch with proper > instructions for 64bit math it can usually be done with a single div > instruction on two 64bit registers. But you don't know that and you don't care about that. x / y, given x and y are declared __u64 and given the result is also declared __u64, will do 64-bit division, whatever way it can be done on given target. > But you are right, nothing's stopping you from dividing 64bit (or 128 > bit or any arbitraily sized) integers on a 32bit arch, you just need > to do more work to arrive at the result - the GNU Multiple Precision > Arithmetic Library (http://www.swox.com/gmp/) is a nice example. No. For 64-bit division, if the compiler supports it - GCC does support it on /ALL/ targets*, not just 64-bit ones - it's the compiler that needs to do more work. 128-bit is another case, because AFAIK no compiler provides 128-bit integeral type and thus, obviously, does not support division in that type. * But on 32-bit targets is calls function from libgcc to do it. Kernel is not linked against that library though, which is why it needs it's own implementation. But all userland stuff is, so you can safely use normal division there. -- Jan 'Bulb' Hudec <bulb@xxxxxx>
Attachment:
signature.asc
Description: Digital signature