All of lore.kernel.org
 help / color / mirror / Atom feed
From: Chris Torek <chris.torek@windriver.com>
To: sparclinux@vger.kernel.org
Subject: Re: Unify module.*
Date: Mon, 22 Dec 2008 22:34:27 +0000	[thread overview]
Message-ID: <200812222234.mBMMYRn07972@elf.torek.net> (raw)
In-Reply-To: <20081222220745.GA30716@uranus.ravnborg.org>

>I really did not like this part:
>#ifdef CONFIG_SPARC64
>                BUG_ON(((u64)location >> (u64)32) != (u64)0);
>#endif /* CONFIG_SPARC64 */
>
>I think it should be safe to do:
>
>		BUG_ON(((unsigned long)location >> (unsigned long)32) !>		       (unsigned long)0);

No, you can't safely shift a 32-bit value by 32 bits (the compiler
is allowed to turn this into a shift of 0 bits for instance, by
using a 5-bit mask for the shift distance).  However it should be
safe to do this, which is exactly the same in practice:

		BUG_ON((((unsigned long)location >> 31) >> 1) !		       (unsigned long)0);

>But I did not really see the point of the BUG_ON in the first place,
>and my limited digging did not turn up when it was added.

Not sure who uses it and why it was added, but it's equivalent to:

	BUG_ON((unsigned long)location > 0xffffffff);

which I personally prefer to the shift version -- I think it makes
the intent more obvious -- but this might still draw a warning about
being always-false on 32-bit.  Of course, if gcc gets any smarter,
so might the shift version.

Chris

      parent reply	other threads:[~2008-12-22 22:34 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-12-22 22:07 Unify module.* Sam Ravnborg
2008-12-22 22:31 ` Sam Ravnborg
2008-12-22 22:34 ` Chris Torek [this message]

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=200812222234.mBMMYRn07972@elf.torek.net \
    --to=chris.torek@windriver.com \
    --cc=sparclinux@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.