[lkml]   [2003]   [Mar]   [17]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
SubjectRe: error using unsigned long long not working in 2.4.x
On Mon, Mar 17, 2003 at 09:44:16PM -0800, dave wrote:
> hi i am writing a kernel 2.4.x driver and need to do maths on 64 bit ints
> (unsigned long long)
> bcause you can not use the FPU
> but when i insmod i get the error unresolved symbol __udivdi3 i need!! 64
> bit ints
> i have included the code
> thank you

The original reason for Linux kernel not being linked with -lgcc
where that routine is defined, is that of wanting to catch careless
coding of 64-bit arithmetic in kernel. It does cause massiveish
performance penalty in the system, if used unchecked in code
fast paths.

If you can do it with at most 31 bit divider, and can handle
side-effectfull division, system has do_div() macro.

Use like:

#include <asm/div64.h>

long long n, vco;
long divisor;
long remainder;

n = vco;
divisor = some_expression;
remainder = do_div(n, divisor);

You will, most likely, ignore the remainder.
BECAUSE there is side-effect of modifying the dividend (n), you must
use it like in this illustriation.

The divisor can not have value in excess of 2^31.

Also there are architectures which do not properly implement this
routine, and do merely 32/32 division, where 64/32 is really wanted.
(The i386 architecture does handle it.)

/Matti Aarnio
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to
More majordomo info at
Please read the FAQ at

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