Re: __udivdi3 and linux kernel u64 division question [x86]

From: Jan-Benedict Glaw
Date: Tue May 24 2005 - 08:11:30 EST


On Tue, 2005-05-24 14:29:44 +0200, Mateusz Berezecki <mateuszb@xxxxxxxxx> wrote:
> u64 mconst = somebig64bitvalue;
> u64 tmp = some32bitvalue;
> u64 r = mconst / tmp;
>
> I encounter compilation error and gcc reporting __udivdi3 has not been
> found!
> After firing up cscope I found that this function has never(?) been
> implemented for
> x86 architecture. How is it possible that during compilation process of
> some module
> make system tries to link with nonexisting function?
>
> I've also found a do_div() and it was sufficent for my purposes but Im
> still curious about
> __udivdi3. Can someone explain this issue to me?

In some cases, gcc decides that a given division is too complicated to
do it in one assembler instruction. That's especially true for things
that newer CPUs support but older lack. In these cases, gcc emits a
function call instead of the actual division and normally, libgcc would
provide these functions.

However, it's each architecture's decision to link-in libgcc or not,
because it can open another can of worms. Alternatively, you can
implement these little functions on your own and put them somewhere in
some library file.

MfG, JBG

--
Jan-Benedict Glaw jbglaw@xxxxxxxxxx . +49-172-7608481 _ O _
"Eine Freie Meinung in einem Freien Kopf | Gegen Zensur | Gegen Krieg _ _ O
fuer einen Freien Staat voll Freier BÃrger" | im Internet! | im Irak! O O O
ret = do_actions((curr | FREE_SPEECH) & ~(NEW_COPYRIGHT_LAW | DRM | TCPA));

Attachment: signature.asc
Description: Digital signature