qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH] bitops: unify bitops_ffsl with the one in host-


From: Eric Blake
Subject: Re: [Qemu-devel] [PATCH] bitops: unify bitops_ffsl with the one in host-utils.h
Date: Wed, 30 Jan 2013 14:51:05 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130110 Thunderbird/17.0.2

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

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]