Re: Integer Division on 32 Bit Machines

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Andreas,

Replying to the list this time...

On Tue, Sep 7, 2010 at 3:02 AM, Andreas Leppert <wudmx@xxxxxx> wrote:
> Hello,
>
> I have encountered a problem on my 32 bit machine. Here some code
> snippets:
...snip...
> optimizer/built-in.o: In function `sys_optStopMeasure':
> /source/trunk/linux-2.6.34/optimizer/sys_optStopMeasure.c:144: undefined
> reference to `__divdi3'
>
> Another person which has tried the code had no problems - he compiled
> the code for a 64 bit machine. Can you explain to me the problem? Why
> does the code work on 64 but not on 32 bit?
>
> I've looked for some workarounds and found do_div(). Is this the way to
> go? Or are there better ways?

32-bit kernels do not support 64-bit divides in the kernel. Using
do_div is the correct way to do things.

The reason it works in a 64-bit kernel is because a 64-bit CPU can do
64-bit divides. A 32-but CPU can only do 32-bit divides.

You also have to consider that the linux kernel runs on more platforms
that just x86. It also runs on ARM, MIPS, PowerPC, etc.

The general rule is: there is no floating point support in kernel
space (as a general rule: it may happen to work on some CPUs).

Another general rule, is that on 32-bit CPUs you can only do 32-bit
arithmetic, with 64-bit addition, subtraction, and multiplications.
64-bit divides must be done using do_div or do_div64.

--
Dave Hylands
Shuswap, BC, Canada
http://www.DaveHylands.com/

--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx
Please read the FAQ at http://kernelnewbies.org/FAQ



[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux