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
-
: send the line "unsubscribe linux-ide" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html