On 07/03/2012 10:49 PM, Eric Blake wrote:
> On 07/03/2012 01:23 PM, Blue Swirl wrote:
> 
>>> +
>>> +static inline int64_t round2pow2(int64_t value)
> 
> round up or down?
> 
>>> +{
>>> +    while (!is_power_of_2(value)) {
>>> +        value &=  ~(1 << (ffs(value) - 1));
>>
>> ffs() only uses 'int', not int64_t.  ffsl() is not universally available.
>>
>>> +    }
>>> +    return value;
>>> +}
> 
> Not to mention that iterating one bit at a time is inefficient.  We
> already gave you several more efficient solutions; my favorite being:
> 
> static inline int64_t pow2floor(int64_t value)
> {
>     if (!is_power_of_2(value)) {
>         value = 0x8000000000000000ULL >> clz64(value);
>     }
>     return value;
> }
> 
> since clz64() is already part of qemu sources.
> 
I will fix it


Reply via email to