linux-ide.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Linux Question
@ 2006-04-10 16:32 Carlos Pardo
  2006-04-10 17:56 ` Jeff Garzik
  0 siblings, 1 reply; 2+ messages in thread
From: Carlos Pardo @ 2006-04-10 16:32 UTC (permalink / raw)
  To: Tejun Heo, Jeff Garzik; +Cc: linux-ide

Linux Gurus,

Does anyone know a way to do 64bit/32bit division in linux kernel space? I'm rewriting a lot of code to use the do_div macro in div64.h but I'm wondering if there's an easier way of doing this.  Anyone fought this problem before?

Carlos

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Linux Question
  2006-04-10 16:32 Linux Question Carlos Pardo
@ 2006-04-10 17:56 ` Jeff Garzik
  0 siblings, 0 replies; 2+ messages in thread
From: Jeff Garzik @ 2006-04-10 17:56 UTC (permalink / raw)
  To: Carlos Pardo; +Cc: Tejun Heo, linux-ide

Carlos Pardo wrote:
> Does anyone know a way to do 64bit/32bit division in linux kernel space? I'm rewriting a lot of code to use the do_div macro in div64.h but I'm wondering if there's an easier way of doing this.  Anyone fought this problem before?

(please turn on word wrap)

Here's the whole story:

A 64/32 division is normally promoted to 64/64 when generating the asm, 
IIRC.  With gcc, on a 32-bit platform such as x86, a 64/64 division 
causes gcc to emit a function call to do the division, rather than doing 
it inline.  The 64/64 division operation on 32-bit is so expensive that 
it is done in libgcc (a shared library), rather than directly by code 
generated from the compiler.

The kernel never links with libgcc (or any other lib, such as libc), 
never uses floating point/SSE registers[1], and thus can never contain 
code that causes gcc to call libgcc functions.

Often 64/64 can be reduced manually to 64/32, but that requires the use 
of do_div() to prevent gcc from generating a call to function that does 
not exist in the kernel.

So yes, you'll have to use do_div(), if you cannot accomplish the 
division via power-of-2 shifting or similar techniques.

	Jeff



[1] well, there are rare cases such as RAID XOR

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2006-04-10 17:56 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-04-10 16:32 Linux Question Carlos Pardo
2006-04-10 17:56 ` Jeff Garzik

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).