mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "David Schwartz" <davids@webmaster.com>
To: <linux-kernel@vger.kernel.org>
Subject: RE: division and cpu usage
Date: Thu, 23 Aug 2007 18:04:49 -0700	[thread overview]
Message-ID: <MDEHLPKNGKAHNMBLJOLKEEBMGGAC.davids@webmaster.com> (raw)
In-Reply-To: <46CE1BA2.8070200@gmail.com>


> Hello.
>
> I'm new to kernel development and have some questions.
>
> 1. Why can't I divide with regular casting to double ((double)a /
> (double)b)? It gives me strange errors when compiling:
>
> WARNING: "__divdf3" [/root....] undefined!
> WARNING: "__addf3" [/root/...] undefined!
> WARNING: "__floatsidf" [/root/...] undefined!
>
> And if I compile with normal integers, I get zero as the result.

As the HOWTO says:

"The kernel is written using GNU C and the GNU toolchain.  While it
adheres to the ISO C89 standard, it uses a number of extensions that are
not featured in the standard.  The kernel is a freestanding C
environment, with no reliance on the standard C library, so some
portions of the C standard are not supported.  Arbitrary long long
divisions and floating point are not allowed.  It can sometimes be
difficult to understand the assumptions the kernel has on the toolchain
and the extensions that it uses, and unfortunately there is no
definitive reference for them.  Please check the gcc info pages (`info
gcc`) for some information on them."

The short version is simply that it's very expensive to allow this, adding
overhead even in cases where it isn't used, and there is very little
benefit. For almost every imaginable case where you would want floating
point in the kernel, fixed point works as well or better.

Just scale your numbers by shifting them.

DS



  reply	other threads:[~2007-08-24  1:05 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-08-23 23:43 Luka Napotnik
2007-08-24  1:04 ` David Schwartz [this message]
2007-08-24 11:34 ` linux-os (Dick Johnson)
2007-08-24 12:46   ` Jan Engelhardt
2007-08-25 23:25     ` Luka Napotnik
2007-08-27 22:07     ` Luka Napotnik
2007-08-28  6:45       ` Jan Engelhardt
2007-08-28 10:41         ` Luka Napotnik
2007-08-28 12:11           ` Jan Engelhardt

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=MDEHLPKNGKAHNMBLJOLKEEBMGGAC.davids@webmaster.com \
    --to=davids@webmaster.com \
    --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®