mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Bernardo Innocenti <bernie@develer.com>
To: Peter Chubb <peter@chubb.wattle.id.au>
Cc: Andrew Morton <akpm@digeo.com>,
	linux-kernel@vger.kernel.org,
	Linus Torvalds <torvalds@transmeta.com>
Subject: Re: [PATCH] Kill div64.h dupes, parenthesize do_div() macro params
Date: Wed, 2 Jul 2003 06:37:24 +0200	[thread overview]
Message-ID: <200307020637.24459.bernie@develer.com> (raw)
In-Reply-To: <16130.21283.122787.362837@wombat.chubb.wattle.id.au>

On Wednesday 02 July 2003 05:36, Peter Chubb wrote:

 > Bernardo> If there are architectures where gcc doesn't implement
 > Bernardo> divisions correctly, this issue should be solved in gcc, not
 > Bernardo> by adding a silly macro to the kernel.
 >
 > The issue is that on 32-bit platforms, 64bit divided by 32 bit is
 > handed off to a subroutine _udivdi3 which isn't linked into the
 > kernel, and  which in any case does a full 64 bit by 64-bit division
 > (which is slow).

 I see. It's ashaming that the gcc people didn't care special casing
the quite common 64/32 case in the x86 machine description or at least
in libgcc.

 > Using do_div() allows one to generate near-optimal code for a 64by32
 > bit division/remainder on platforms (e.g., IA32) which have problems,
 > and generating something sane for other platforms (e.g., IA64).

 I agree. I'd prefer to see it fixed in gcc, but until then...


 > Platforms that never expect to deal with a 64-bit number just redefine
 > the macro in terms of long.  Which means that printing out long longs
 > doesn't work properly on those architectures.

 A function which changes its semantics depending on the platform is
definitely a ugly hack.

 A cleaner way to address this problem would be using platform-specific
typedefs to reduce the size of specific objects to 32bits on smaller systems.


 In mm/vmscan.c:shrink_slab() you'll find this:

       long long delta;

       delta = scanned * shrinker->seeks;
       delta *= (*shrinker->shrinker)(0, gfp_mask);
       do_div(delta, pages + 1);
       shrinker->nr += delta;

 This is _BAD_ because delta will be 128bits on some 64bit systems
and 64bit, but truncated to 32bit in do_div(), on some other systems.

 Using at least uint64_t would solve the first problem, but anyone
looking at this code wouldn't realize the result could get truncated
by some do_div() implementations.

 What can we do about that? This time I don't have a clean solution to
advocate.

-- 
  // Bernardo Innocenti - Develer S.r.l., R&D dept.
\X/  http://www.develer.com/

Please don't send Word attachments - http://www.gnu.org/philosophy/no-word-attachments.html



  reply	other threads:[~2003-07-02  4:23 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-07-02  0:32 Bernardo Innocenti
     [not found] ` <20030701173612.280d1296.akpm@digeo.com>
2003-07-02  2:24   ` Bernardo Innocenti
2003-07-02  2:32     ` Andrew Morton
2003-07-02  3:15       ` Bernardo Innocenti
2003-07-02  5:12         ` Linus Torvalds
2003-07-02  7:53         ` Russell King
2003-07-02  8:14           ` Ian Molton
2003-07-02  5:09       ` Linus Torvalds
2003-07-02  7:02         ` Bernardo Innocenti
2003-07-02  7:54           ` Matti Aarnio
2003-07-02  3:36     ` Peter Chubb
2003-07-02  4:37       ` Bernardo Innocenti [this message]
2003-07-02  5:57       ` Andrea Arcangeli
2003-07-02  6:52         ` Bernardo Innocenti
2003-07-02  7:19           ` Andrea Arcangeli
2003-07-02  7:28             ` Bernardo Innocenti
2003-07-02  8:38               ` Andrea Arcangeli
2003-07-02 16:16           ` Linus Torvalds
2003-07-03 10:43             ` [PATCH] Fix do_div() for all architectures Bernardo Innocenti
2003-07-02  7:56         ` [PATCH] Kill div64.h dupes, parenthesize do_div() macro params Russell King
2003-07-02  5:06     ` Linus Torvalds
2003-07-02 14:23       ` Geert Uytterhoeven

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=200307020637.24459.bernie@develer.com \
    --to=bernie@develer.com \
    --cc=akpm@digeo.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=peter@chubb.wattle.id.au \
    --cc=torvalds@transmeta.com \
    /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®