mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: hpa@zytor.com (H. Peter Anvin)
To: linux-kernel@vger.kernel.org
Subject: Re: [2.6.6-BK] x86_64 has buggy ffs() implementation
Date: Wed, 12 May 2004 20:31:56 +0000 (UTC)	[thread overview]
Message-ID: <c7u1js$1h2$1@terminus.zytor.com> (raw)
In-Reply-To: <1084369416.16624.53.camel@imp.csi.cam.ac.uk>

Followup to:  <1084369416.16624.53.camel@imp.csi.cam.ac.uk>
By author:    Anton Altaparmakov <aia21@cam.ac.uk>
In newsgroup: linux.dev.kernel
>
> Hi Andi, Andrew, Linus,
> 
> x86_64 has incorrect include/asm-x86_64/bitops.h::ffs() implementation. 
> It uses "g" instead of "rm" in the insline assembled bsfl instruction. 
> (This was spotted by Yuri Per.)
> 
> bsfl does not accept constant values but only memory ones.  On i386 the
> correct "rm" is used.
> 
> This causes NTFS build to fail as gcc optimizes a variable into a
> constant and ffs() then fails to assemble.
> 

Of course, this is a good reason to do a __builtin_constant_p()
wrapper that gcc can optimize:

static __inline__ __attribute_const__ int ffs(int x)
{  
	if ( __builtin_constant_p(x) ) {
		unsigned int y = (unsigned int)x;
		if ( y >= 0x80000000 )
			return 32;
		else if ( y >= 0x40000000 )
			return 31;
		else if /* ... you get the idea ... */
	} else {
		__asm__("bsfl %1,%0\n\t"
			"cmovzl %2,%0" 
			: "=r" (r) : "rm" (x), "r" (-1));
		return r+1;
	}
}

	-hpa

  parent reply	other threads:[~2004-05-12 20:33 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-05-12 13:43 Anton Altaparmakov
2004-05-12 14:02 ` Andi Kleen
2004-05-12 20:31 ` H. Peter Anvin [this message]
2004-05-12 21:08   ` Anton Altaparmakov
2004-05-12 21:11   ` Gabriel Paubert
2004-05-12 22:29     ` H. Peter Anvin

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='c7u1js$1h2$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

all inboxes | Powered by JetHome®