Re: [PATCH v3 1/6] internal: add macro to round value to the next closest power of 2

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

 



On 11/20/14 20:21, Pavel Hrdina wrote:
> There are two special cases, if the input number is 0 or the number is
> larger then 2^31 (for 32bit unsigned int). For the special cases the
> return value is 0 because they cannot be rounded.
> 
> Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1076098
> 
> Signed-off-by: Pavel Hrdina <phrdina@xxxxxxxxxx>
> ---
>  bootstrap.conf   |  1 +
>  src/internal.h   |  7 +++++++
>  tests/utiltest.c | 39 +++++++++++++++++++++++++++++++++++++++
>  3 files changed, 47 insertions(+)
> 
> diff --git a/bootstrap.conf b/bootstrap.conf
> index d24a714..e7ea9c9 100644
> --- a/bootstrap.conf
> +++ b/bootstrap.conf
> @@ -35,6 +35,7 @@ clock-time
>  close
>  connect
>  configmake
> +count-leading-zeros
>  count-one-bits
>  crypto/md5
>  crypto/sha256
> diff --git a/src/internal.h b/src/internal.h
> index f6a88b2..765b853 100644
> --- a/src/internal.h
> +++ b/src/internal.h
> @@ -62,6 +62,7 @@
>  
>  # include "c-strcase.h"
>  # include "ignore-value.h"
> +# include "count-leading-zeros.h"
>  
>  /* On architectures which lack these limits, define them (ie. Cygwin).
>   * Note that the libvirt code should be robust enough to handle the
> @@ -382,6 +383,12 @@
>  /* round up value to the closest multiple of size */
>  # define VIR_ROUND_UP(value, size) (VIR_DIV_UP(value, size) * (size))
>  
> +/* Round up to the next closest power of 2. It will return rounded number or 0
> + * for 0 or number more than 2^31 (for 32bit unsigned int). */
> +# define VIR_ROUND_UP_POWER_OF_TWO(value)                                   \
> +    ((value) > 0 && (value) <= 1U<<(sizeof(unsigned int)*8 - 1) ?           \
> +     1U<<(sizeof(unsigned int)*8 - count_leading_zeros((value) - 1)) : 0)

You should add spaces around the multiplication and shift operators to
comply with our coding style.

ACK with that changed.

Peter


Attachment: signature.asc
Description: OpenPGP digital signature

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]