[pve-devel] [PATCH v2 qemu-server 1/1] migrate cache-size : power of 2
Wolfgang Bumiller
w.bumiller at proxmox.com
Mon Feb 12 10:54:24 CET 2018
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