public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: hpa@zytor.com (H. Peter Anvin)
To: linux-kernel@vger.kernel.org
Subject: Re: kernel/microcode.c error from new 64bit code
Date: Sun, 22 Feb 2004 20:12:25 +0000 (UTC)	[thread overview]
Message-ID: <c1b2f9$sfj$1@terminus.zytor.com> (raw)
In-Reply-To: Pine.LNX.4.58.0402210914530.3301@ppc970.osdl.org

Followup to:  <Pine.LNX.4.58.0402210914530.3301@ppc970.osdl.org>
By author:    Linus Torvalds <torvalds@osdl.org>
In newsgroup: linux.dev.kernel
>
> 
> 
> On Sat, 21 Feb 2004, Pavel Machek wrote:
> >
> > > +	wrmsr(MSR_IA32_UCODE_WRITE,
> > > +		(unsigned long) uci->mc->bits, 
> > > +		(unsigned long) uci->mc->bits >> 16 >> 16);
> > 				             ~~~~~~~~~~~~
> > 
> > I see what you are doing, but this is evil. At least comment /* ">> 32"
> > is undefined on i386 */ ?
> 
> Sorry, but you're wrong.
> 
> ">> 32" is underfined PERIOD! It has nothing to do with x86, it's a C
> standards issue. It's undefined on any 32-bit architecture. (shifting by
> the wordsize or bigger is simply not a defined C operation).
> 
> The above is not evil. The above is the standard way of doing this in C if 
> you know the word-size is 32-bits or bigger.
> 

Actually, what is undefined is shifting with the size of the data type or higher.

If the cast of uci->mc->bits had been an uint64_t (unsigned long
long), >> 32 would have been perfectly well-defined.

The above code is just plain wrong: the cast to (unsigned long) has
higher precedence than the shift, so on i386 (which I presume this is)
it will become an unsigned long, and the shifts will bring it down to
zero.

You might as well write zero if that's what you mean.

	-hpa

  parent reply	other threads:[~2004-02-22 20:12 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-02-18 22:52 kernel/microcode.c error from new 64bit code Stephen Hemminger
2004-02-18 23:08 ` Linus Torvalds
2004-02-18 23:21   ` Linus Torvalds
2004-02-21 14:16   ` Pavel Machek
2004-02-21 17:18     ` Linus Torvalds
2004-02-21 17:34       ` Pavel Machek
2004-02-21 17:44         ` Linus Torvalds
2004-02-21 18:36           ` Eric W. Biederman
2004-02-21 18:48             ` Pavel Machek
2004-02-21 19:03             ` Linus Torvalds
2004-02-21 19:30               ` Eric W. Biederman
2004-02-22 20:12       ` H. Peter Anvin [this message]
2004-02-22 20:32         ` Linus Torvalds
2004-02-22 20:33           ` H. Peter Anvin
2004-02-22 20:41           ` H. Peter Anvin
  -- strict thread matches above, loose matches on Subject: below --
2004-02-19  0:12 Nakajima, Jun

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='c1b2f9$sfj$1@terminus.zytor.com' \
    --to=hpa@zytor.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