Messages in this thread | | | Subject | Re: [RFC][PATCH] Faster generic_fls | From | Alan Cox <> | Date | 30 Apr 2003 23:22:28 +0100 |
| |
On Mer, 2003-04-30 at 22:59, Falk Hueffner wrote: > > ffs(x^(x-1)) == fls(x) > > I don't think so. Maybe you are thinking of ffs(x) == fls(x & -x). So > you can calculate ffs with fls, but not easily the other way round.
Well I asked my CPU to double check. If I got the code right it thinks that ffs(i^(i-1))==fls(i) is true for 1->2^32-1
If you think about it it seems to make sense
x-1 turns the lowest 100..0 sequence into 01......1
The xor removes unchanged higher bits
so 10100 -1 10011 XOR 00111
- 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/
| |