2003-03-17 08:31:59

by dave

[permalink] [raw]
Subject: error using unsigned long long not working in 2.4.x

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


Attachments:
lnvrm_nv05Pramdac.c (2.11 kB)

2003-03-17 08:43:30

by Matti Aarnio

[permalink] [raw]
Subject: Re: 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

2003-03-17 18:59:08

by Randy.Dunlap

[permalink] [raw]
Subject: Re: error using unsigned long long not working in 2.4.x

On Mon, 17 Mar 2003 21:44:16 -0800 "dave" <[email protected]> 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

Other alternatives are search the lkml archive for a patch from
George Anzinger on 2003-mar-05,
subject: [PATCH] Functions to do easy scaled math.

or if all you need is 64-bit mul and div, and only during setup
(when speed isn't a huge factor), you could use the divrem64()
function in this sample /procfs module:
http://www.xenotime.net/linux/procfs_ex/procdiv64.c

--
~Randy