[lkml]   [1996]   [Nov]   [26]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
SubjectRe: 64-bit math in the kernel

Albert Cahalan wrote:
> What is the best way to divide a __u64 by a __u32 in the kernel?
> The result will fit in a __u32.

In one of my ATM drivers, I have the following non-portable and therefore
ugly solution (inspired by arch/i386/kernel/time.c:do_fast_gettimeoffset):

* zatm_dev->factor = (interval << TIMER_SHIFT)/
* (ticks-zatm_dev->last_clk);
#define S(x) #x /* "stringification" ... */
#define SX(x) S(x)
asm("movl %2,%%ebx\n\t"
"subl %3,%%ebx\n\t"
"xorl %%edx,%%edx\n\t"
"shldl $" SX(TIMER_SHIFT) ",%1,%%edx\n\t"
"shl $" SX(TIMER_SHIFT) ",%1\n\t"
"divl %%ebx\n\t"
: "=eax" (zatm_dev->factor)
: "eax" (interval-diff),"g" (ticks),
"g" (zatm_dev->last_clk)
: "ebx","edx","cc");
#undef S
#undef SX

> It seems gcc requires libgcc to do that, but libgcc is not available.

Right, I didn't dare to link the kernel with libgcc either. I think it
would be a very good idea to have basic 64 bit arithmetic available in
the kernel too.

- Werner

/ Werner Almesberger, DI-LRC,EPFL,CH /

 \ /
  Last update: 2005-03-22 13:37    [W:0.044 / U:0.628 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site