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 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. -- Jesper Juhl <jesper.juhl@xxxxxxxxx> Don't top-post http://www.catb.org/~esr/jargon/html/T/top-post.html Plain text mails only, please http://www.expita.com/nomime.html -- Kernelnewbies: Help each other learn about the Linux kernel. Archive: http://mail.nl.linux.org/kernelnewbies/ FAQ: http://kernelnewbies.org/faq/