On 01/30/2013 01:41 PM, Peter Maydell wrote:
>> -#if LONG_MAX > 0x7FFFFFFF
>> - if ((word & 0xffffffff) == 0) {
>> - num += 32;
>> - word >>= 32;
>> - }
>> - if ((word & 0xffff) == 0) {
>> - num += 16;
>> - word >>= 16;
>> - }
>> - if ((word & 0xff) == 0) {
>> - num += 8;
>> - word >>= 8;
>> - }
>> - if ((word & 0xf) == 0) {
>> - num += 4;
>> - word >>= 4;
>> - }
>> - if ((word & 0x3) == 0) {
>> - num += 2;
>> - word >>= 2;
>> - }
>> - if ((word & 0x1) == 0) {
>> - num += 1;
>> - }
>> - return num;
>> }
>
> This reimplementation appears to have an off by one error.
> For example, on an input of 4, the old algorithm returns 2
> and this one returns 3.
Ouch - you are right that the old implementation is indeed a ctz()
instead of an ffs() operation. That means we need to fix all callers of
bitops_ffsl() to either use ffsl semantics, or to add a bitops_ctzl()
that provides the old behavior.
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature
