mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Matti Aarnio <matti.aarnio@zmailer.org>
To: dave <davekern@ihug.co.nz>
Cc: linux-kernel@vger.kernel.org
Subject: Re: error using unsigned long long not working in 2.4.x
Date: Mon, 17 Mar 2003 10:54:20 +0200	[thread overview]
Message-ID: <20030317085420.GZ29167@mea-ext.zmailer.org> (raw)
In-Reply-To: <002d01c2ed11$6ba7a110$0b721cac@stacy>

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

  reply	other threads:[~2003-03-17  8:43 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-03-18  5:44 dave
2003-03-17  8:54 ` Matti Aarnio [this message]
2003-03-17 19:06 ` Randy.Dunlap

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20030317085420.GZ29167@mea-ext.zmailer.org \
    --to=matti.aarnio@zmailer.org \
    --cc=davekern@ihug.co.nz \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®