mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Linus Torvalds <torvalds@linux-foundation.org>
To: Ingo Molnar <mingo@elte.hu>
Cc: linux-kernel@vger.kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
	Borislav Petkov <petkovbb@googlemail.com>,
	Peter Zijlstra <a.p.zijlstra@chello.nl>,
	Thomas Gleixner <tglx@linutronix.de>,
	Andrew Morton <akpm@linux-foundation.org>
Subject: Re: [GIT PULL] core/hweight changes for v2.6.35
Date: Mon, 17 May 2010 14:46:05 -0700 (PDT)	[thread overview]
Message-ID: <alpine.LFD.2.00.1005171443060.4195@i5.linux-foundation.org> (raw)
In-Reply-To: <20100517212138.GA21629@elte.hu>



On Mon, 17 May 2010, Ingo Molnar wrote:
>
> +#ifdef CONFIG_64BIT
> +/* popcnt %rdi, %rax */
> +#define POPCNT ".byte 0xf3,0x48,0x0f,0xb8,0xc7"
> +#define REG_IN "D"
> +#define REG_OUT "a"
...
> +/*
> + * __sw_hweightXX are called from within the alternatives below
> + * and callee-clobbered registers need to be taken care of. See
> + * ARCH_HWEIGHT_CFLAGS in <arch/x86/Kconfig> for the respective
> + * compiler switches.
> + */
> +static inline unsigned int __arch_hweight32(unsigned int w)
> +{
> +	unsigned int res = 0;
> +
> +	asm (ALTERNATIVE("call __sw_hweight32", POPCNT, X86_FEATURE_POPCNT)
> +		     : "="REG_OUT (res)
> +		     : REG_IN (w));
> +
> +	return res;
> +}

I do not believe this is correct.

On x86-64, you are using a 64-bit instruction, but

	REG_IN (w)

does _not_ guarantee that the register is zero in the high bits.

Yes, yes, in practice it _probably_ is, because the register almost 
certainly got loaded with some kind of zero-extending mov instruction. But 
as far as I can tell, the code is buggy. You're telling gcc that you are 
using a 32-bit register, but you're actually counting bits in the full 64 
bits.

Am I missing something?

		Linus

  reply	other threads:[~2010-05-17 21:49 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-05-17 21:21 Ingo Molnar
2010-05-17 21:46 ` Linus Torvalds [this message]
2010-05-17 22:06   ` H. Peter Anvin
2010-05-17 22:57   ` [tip:core/hweight] x86, hweight: Use a 32-bit popcnt for __arch_hweight32() tip-bot for H. Peter Anvin
2010-05-17 23:04   ` [GIT PULL] UPDATED - core/hweight changes for v2.6.35 H. Peter Anvin
2010-08-13 21:42 ` [GIT PULL] " Mike Frysinger
2010-08-13 21:56   ` H. Peter Anvin
2010-08-13 21:59     ` Mike Frysinger
2010-08-14  0:11       ` H. Peter Anvin
2010-08-14 13:44         ` Borislav Petkov
2010-08-14  0:32   ` [PATCH] arch/tile: Rename the hweight() implementations to __arch_hweight() Chris Metcalf
2010-08-14  1:02     ` Mike Frysinger

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=alpine.LFD.2.00.1005171443060.4195@i5.linux-foundation.org \
    --to=torvalds@linux-foundation.org \
    --cc=a.p.zijlstra@chello.nl \
    --cc=akpm@linux-foundation.org \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=petkovbb@googlemail.com \
    --cc=tglx@linutronix.de \
    /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

Powered by JetHome