qemu-devel
[Top][All Lists]
Advanced

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

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


From: Eric Blake
Subject: Re: [Qemu-devel] [PATCH v3] bitops: unify bitops_ffsl with the one in host-utils.h, call it bitops_ctzl
Date: Sat, 02 Feb 2013 08:11:16 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130110 Thunderbird/17.0.2

On 02/02/2013 06:30 AM, Peter Maydell wrote:

>> - * Undefined if no bit exists, so code should check against 0 first.
>> + * Returns -1 if no bit exists.  Note that compared to the C library
>> + * routine ffsl, this one returns one less.
>>   */
> 
> Do any of our callers actually use the "-1 on 0 input" semantics?
> (I guess that means "your new code you added" since the previous
> callers all were happy with the undefined-on-zero semantics).

Yes, Paolo's code was replacing:

ffsl(var) - 1

with

bitops_ctzl(var)

where var==0 was a definite possibility, so we DO have code that depends
on this semantic of returning -1.

> It seems an odd choice, since I can see a justification for:
>  (a) "return number of bits in word" [every bit in the word is
>      a trailing zero in some sense]
>  (b) "undefined" [matches gcc builtin_ctz semantics]

For all non-zero values of var, ffsl(var) == bitops_ctzl(var)+1.
Extending the equivalency for var==0 makes the function usable in the
most places.

-- 
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]