Messages in this thread | | | Date | Wed, 12 May 2004 22:08:12 +0100 (BST) | From | Anton Altaparmakov <> | Subject | Re: [2.6.6-BK] x86_64 has buggy ffs() implementation |
| |
On Wed, 12 May 2004, H. Peter Anvin wrote: > 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 ... */
If you are going to play with that why not just use generic_ffs() instead of doing it by hand?
Best regards,
Anton
> } else { > __asm__("bsfl %1,%0\n\t" > "cmovzl %2,%0" > : "=r" (r) : "rm" (x), "r" (-1)); > return r+1; > } > }
-- Anton Altaparmakov <aia21 at cam.ac.uk> (replace at with @) Unix Support, Computing Service, University of Cambridge, CB2 3QH, UK Linux NTFS maintainer / IRC: #ntfs on irc.freenode.net WWW: http://linux-ntfs.sf.net/ & http://www-stu.christs.cam.ac.uk/~aia21/ - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
| |