qemu-devel
[Top][All Lists]
Advanced

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

Re: [Qemu-devel] [PATCH v14 04/13] Add cache handling functions


From: Eric Blake
Subject: Re: [Qemu-devel] [PATCH v14 04/13] Add cache handling functions
Date: Tue, 03 Jul 2012 13:49:12 -0600
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:13.0) Gecko/20120615 Thunderbird/13.0.1

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.

-- 
Eric Blake   address@hidden    +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]