Re: [RFC][PATCH] Faster generic_fls

From: Falk Hueffner (falk.hueffner@student.uni-tuebingen.de)
Date: Wed Apr 30 2003 - 19:12:10 EST


Linus Torvalds <torvalds@transmeta.com> writes:

> On 30 Apr 2003, Alan Cox wrote:
> >
> > It ought to be basically the same as ffs because if I remember rightly
> >
> > ffs(x^(x-1)) == fls(x)
>
> So did anybody time this? ffs() we have hardware support for on x86,
> and it's even reasonably efficient on some CPU's ..

There appears to be hardware support for fls, too. This is what gcc
generates for

int fls(int x) {
    return x ? 32 - __builtin_clz(x) : 0;
}

fls:
        pushl %ebp
        xorl %edx, %edx
        movl %esp, %ebp
        movl 8(%ebp), %eax
        testl %eax, %eax
        je .L3
        bsrl %eax, %ecx
        movl $32, %edx
        xorl $31, %ecx
        subl %ecx, %edx
.L3:
        popl %ebp
        movl %edx, %eax
        ret

-- 
	Falk
-
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/



This archive was generated by hypermail 2b29 : Wed Apr 30 2003 - 22:00:37 EST