mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Linus Torvalds <torvalds@osdl.org>
To: Zachary Amsden <zach@vmware.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH] Remove some divide instructions
Date: Wed, 27 Oct 2004 17:11:37 -0700 (PDT)	[thread overview]
Message-ID: <Pine.LNX.4.58.0410271704520.28839@ppc970.osdl.org> (raw)
In-Reply-To: <41801DE1.6000007@vmware.com>



On Wed, 27 Oct 2004, Zachary Amsden wrote:
> 
> Backed out everything but i386 and generic.  For the generic version, I 
> compiled and tested this code outside of the kernel.  Actually, I found 
> that at least for my tool chain, the generic version
> 
> +# define do_div(n,base) ({                                             \
> +       uint32_t __rem;                                                 \
> +       if (__builtin_constant_p(base) && !((base) & ((base)-1))) {     \
> +               __rem = ((uint64_t)(n)) % (base);                       \
> +               (n) = ((uint64_t)(n)) / (base);                         \
> +       } else {                                                        \
> +               uint32_t __base = (base);                               \
> +               __rem = ((uint64_t)(n)) % __base;                       \
> +               (n) = ((uint64_t)(n)) / __base;                         \
> +       }                                                               \
> +       __rem;          
> 
> Does indeed generate different code for the constant case - without it, 
> due to the assignment to __base, the shift / mask optimization does not 
> take place.

Oh, damn. That's a separate issue, apparently, and there you just use 
"__builtin_constant_p()" as a way to check that there are no side effects 
on "base".

Might as well drop the check for the value, since it doesn't matter.

Alternatively, we could just document the fact that neither "base" nor "n"
are normal arguments to a function. After all, we already _do_ change "n", 
and the strange calling convention is already documented as nothing but a 
sick hack to make architectures able to use inline assembly efficiently.

I could add a sparse check for "no side effects", if anybody cares (so 
that you could do

	__builtin_warning(
		!__builtin_nosideeffects(base),
		"expression has side effects");

in macros like these.. Sparse already has the logic internally..

		Linus

  reply	other threads:[~2004-10-28  0:14 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-10-27 16:14 Zachary Amsden
2004-10-27 16:28 ` Linus Torvalds
2004-10-27 18:05   ` Zachary Amsden
2004-10-27 20:16   ` Zachary Amsden
2004-10-27 21:24     ` Linus Torvalds
2004-10-27 22:08   ` Thayne Harbaugh
2004-10-27 22:14   ` Zachary Amsden
2004-10-28  0:11     ` Linus Torvalds [this message]
2004-10-28  0:47       ` Linus Torvalds
2004-10-29  0:47         ` Zachary Amsden
2004-10-29  4:52           ` Linus Torvalds
2004-10-29 19:10             ` Geert Uytterhoeven
2004-10-28  0:59       ` Maciej W. Rozycki

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=Pine.LNX.4.58.0410271704520.28839@ppc970.osdl.org \
    --to=torvalds@osdl.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=zach@vmware.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®