Messages in this thread | | | Date | Wed, 30 Apr 2003 18:07:13 -0700 (PDT) | From | Linus Torvalds <> | Subject | Re: [RFC][PATCH] Faster generic_fls |
| |
On 1 May 2003, Falk Hueffner wrote: > > There appears to be hardware support for fls, too. This is what gcc > generates for
Yeah, except if you want best code generation you should probably use
static inline int fls(int x) { int bit; /* Only well-defined for non-zero */ asm("bsrl %1,%0":"=r" (bit):"rm" (x)); return x ? bit : 32; }
which should generate (assuming you give "-march=xxxx" to tell gcc to use cmov):
movl $32, %eax bsrl %edx,%ecx testl %edx, %edx cmovne %ecx, %eax
which looks pretty optimal.
Linus
- 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/
| |