[pve-devel] [PATCH v2 qemu-server 1/1] migrate cache-size : power of 2

Alexandre DERUMIER aderumier at odiso.com
Mon Feb 12 13:07:48 CET 2018


to be honest, I copy paste from perlmonk
http://www.perlmonks.org/?node_id=46889

;)


>>Please just use: 
>>return 1 if $_[0] < 2; 
>>return 2 << int(log($_[0]-1)/log(2)); 

ok, I'll fix it.


----- Mail original -----
De: "Wolfgang Bumiller" <w.bumiller at proxmox.com>
À: "aderumier" <aderumier at odiso.com>
Cc: "pve-devel" <pve-devel at pve.proxmox.com>
Envoyé: Lundi 12 Février 2018 10:54:24
Objet: Re: [pve-devel] [PATCH v2 qemu-server 1/1] migrate cache-size : power of 2

On Mon, Feb 12, 2018 at 09:27:07AM +0100, Alexandre Derumier wrote: 
> +sub round_powerof2 { 

Please just use: 
return 1 if $_[0] < 2; 
return 2 << int(log($_[0]-1)/log(2)); 


> + local $_ = (shift)-1; 
> + my $num = (2**int(log($_)/log(2)))-1; 
> + return ++($_ |= $num); 
This ties knots into my brain when reading it. 
This gets a power of two less than or equal to our number (eg for 
numbers 8 through 15 we get 8), then decrement to set all lower bits 1 
(=> 7) which is then bitor-ed into our original number producing 15 
which is then incremented to 16. However, on '8' we actually want to 
stick with 8 ;-) iow. if we already have a power of two, don't double 
it. 




More information about the pve-devel mailing list