qemu-devel
[Top][All Lists]
Advanced

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

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


From: Eric Blake
Subject: Re: [Qemu-devel] [PATCH v13 04/13] Add cache handling functions
Date: Thu, 28 Jun 2012 06:15:46 -0600
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:13.0) Gecko/20120615 Thunderbird/13.0.1

On 06/28/2012 06:06 AM, Max Filippov wrote:
> On Wed, Jun 27, 2012 at 8:55 PM, Eric Blake <address@hidden> wrote:
>> On 06/27/2012 04:34 AM, Orit Wasserman wrote:
> 

>> if (!is_power_of_2(num_pages)) {
>>    num_pages |= num_pages >> 1;
>>    num_pages |= num_pages >> 2;
>>    num_pages |= num_pages >> 4;
>>    num_pages |= num_pages >> 8;
>>    num_pages |= num_pages >> 16;
>>    num_pages |= num_pages >> 32;
>>    num_pages -= num_pages / 2;
>> }
> 
> Or
> 
> if (!is_power_of_2(num_pages)) {
>     num_pages = 0x8000000000000000ULL >> clz64(num_pages);
> }

Indeed.  I knew about the gcc builtin for clz, but didn't suggest it
because it is not standardized, and didn't realize that qemu had already
wrapped it in a nice function (and one which is portable even when not
compiling with gcc).  It's a shame that libc provides ffs() but not
clz() (since the two operations are rather symmetric (just differing in
which direction they find the first bit), and both useful in
bit-twiddling operations.

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