From: Yuval Shaia <yuval.shaia@oracle.com>
This function should be declared in generic header file so we can
utilize it.
Signed-off-by: Yuval Shaia <yuval.shaia@oracle.com>
Signed-off-by: Marcel Apfelbaum <marcel@redhat.com>
---
hw/pci/shpc.c | 11 +----------
include/qemu/cutils.h | 10 ++++++++++
2 files changed, 11 insertions(+), 10 deletions(-)
diff --git a/hw/pci/shpc.c b/hw/pci/shpc.c
index 69fc14b218..3d22424fd2 100644
--- a/hw/pci/shpc.c
+++ b/hw/pci/shpc.c
@@ -1,6 +1,7 @@
#include "qemu/osdep.h"
#include "qapi/error.h"
#include "qemu-common.h"
+#include "qemu/cutils.h"
#include "qemu/range.h"
#include "qemu/error-report.h"
#include "hw/pci/shpc.h"
@@ -122,16 +123,6 @@
#define SHPC_PCI_TO_IDX(pci_slot) ((pci_slot) - 1)
#define SHPC_IDX_TO_PHYSICAL(slot) ((slot) + 1)
-static int roundup_pow_of_two(int x)
-{
- x |= (x >> 1);
- x |= (x >> 2);
- x |= (x >> 4);
- x |= (x >> 8);
- x |= (x >> 16);
- return x + 1;
-}
-
static uint16_t shpc_get_status(SHPCDevice *shpc, int slot, uint16_t msk)
{
uint8_t *status = shpc->config + SHPC_SLOT_STATUS(slot);
diff --git a/include/qemu/cutils.h b/include/qemu/cutils.h
index f0878eaafa..4895334645 100644
--- a/include/qemu/cutils.h
+++ b/include/qemu/cutils.h
@@ -164,4 +164,14 @@ bool test_buffer_is_zero_next_accel(void);
int uleb128_encode_small(uint8_t *out, uint32_t n);
int uleb128_decode_small(const uint8_t *in, uint32_t *n);
+static inline int roundup_pow_of_two(int x)
+{
+ x |= (x >> 1);
+ x |= (x >> 2);
+ x |= (x >> 4);
+ x |= (x >> 8);
+ x |= (x >> 16);
+ return x + 1;
+}
+
#endif
--
2.13.5
Hi Marcel, Yuval,
On 12/17/2017 09:54 AM, Marcel Apfelbaum wrote:
> From: Yuval Shaia <yuval.shaia@oracle.com>
>
> This function should be declared in generic header file so we can
> utilize it.
>
> Signed-off-by: Yuval Shaia <yuval.shaia@oracle.com>
> Signed-off-by: Marcel Apfelbaum <marcel@redhat.com>
> ---
> hw/pci/shpc.c | 11 +----------
> include/qemu/cutils.h | 10 ++++++++++
> 2 files changed, 11 insertions(+), 10 deletions(-)
>
> diff --git a/hw/pci/shpc.c b/hw/pci/shpc.c
> index 69fc14b218..3d22424fd2 100644
> --- a/hw/pci/shpc.c
> +++ b/hw/pci/shpc.c
> @@ -1,6 +1,7 @@
> #include "qemu/osdep.h"
> #include "qapi/error.h"
> #include "qemu-common.h"
> +#include "qemu/cutils.h"
> #include "qemu/range.h"
> #include "qemu/error-report.h"
> #include "hw/pci/shpc.h"
> @@ -122,16 +123,6 @@
> #define SHPC_PCI_TO_IDX(pci_slot) ((pci_slot) - 1)
> #define SHPC_IDX_TO_PHYSICAL(slot) ((slot) + 1)
>
> -static int roundup_pow_of_two(int x)
> -{
> - x |= (x >> 1);
> - x |= (x >> 2);
> - x |= (x >> 4);
> - x |= (x >> 8);
> - x |= (x >> 16);
> - return x + 1;
> -}
> -
> static uint16_t shpc_get_status(SHPCDevice *shpc, int slot, uint16_t msk)
> {
> uint8_t *status = shpc->config + SHPC_SLOT_STATUS(slot);
> diff --git a/include/qemu/cutils.h b/include/qemu/cutils.h
> index f0878eaafa..4895334645 100644
> --- a/include/qemu/cutils.h
> +++ b/include/qemu/cutils.h
I'd rather move this function below pow2ceil() in "qemu/host-utils.h"
and rename it pow2roundup().
> @@ -164,4 +164,14 @@ bool test_buffer_is_zero_next_accel(void);
> int uleb128_encode_small(uint8_t *out, uint32_t n);
> int uleb128_decode_small(const uint8_t *in, uint32_t *n);
>
> +static inline int roundup_pow_of_two(w x)
> +{
> + x |= (x >> 1);
> + x |= (x >> 2);
> + x |= (x >> 4);
> + x |= (x >> 8);
> + x |= (x >> 16);
So this would be pow2roundup32(uint32_t value)...
Naming it pow2roundup() without specifying the integer size, I'd
directly use a uint64_t argument, and:
x |= (x >> 32);
> + return x + 1;
> +}
> +
> #endif
Naming it pow2roundup() in "qemu/host-utils.h" (regardless the arg size):
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Regards,
Phil.
On Sun, Dec 17, 2017 at 03:16:15PM -0300, Philippe Mathieu-Daudé wrote:
> Hi Marcel, Yuval,
>
> On 12/17/2017 09:54 AM, Marcel Apfelbaum wrote:
> > From: Yuval Shaia <yuval.shaia@oracle.com>
> >
> > This function should be declared in generic header file so we can
> > utilize it.
> >
> > Signed-off-by: Yuval Shaia <yuval.shaia@oracle.com>
> > Signed-off-by: Marcel Apfelbaum <marcel@redhat.com>
> > ---
> > hw/pci/shpc.c | 11 +----------
> > include/qemu/cutils.h | 10 ++++++++++
> > 2 files changed, 11 insertions(+), 10 deletions(-)
> >
> > diff --git a/hw/pci/shpc.c b/hw/pci/shpc.c
> > index 69fc14b218..3d22424fd2 100644
> > --- a/hw/pci/shpc.c
> > +++ b/hw/pci/shpc.c
> > @@ -1,6 +1,7 @@
> > #include "qemu/osdep.h"
> > #include "qapi/error.h"
> > #include "qemu-common.h"
> > +#include "qemu/cutils.h"
> > #include "qemu/range.h"
> > #include "qemu/error-report.h"
> > #include "hw/pci/shpc.h"
> > @@ -122,16 +123,6 @@
> > #define SHPC_PCI_TO_IDX(pci_slot) ((pci_slot) - 1)
> > #define SHPC_IDX_TO_PHYSICAL(slot) ((slot) + 1)
> >
> > -static int roundup_pow_of_two(int x)
> > -{
> > - x |= (x >> 1);
> > - x |= (x >> 2);
> > - x |= (x >> 4);
> > - x |= (x >> 8);
> > - x |= (x >> 16);
> > - return x + 1;
> > -}
> > -
> > static uint16_t shpc_get_status(SHPCDevice *shpc, int slot, uint16_t msk)
> > {
> > uint8_t *status = shpc->config + SHPC_SLOT_STATUS(slot);
> > diff --git a/include/qemu/cutils.h b/include/qemu/cutils.h
> > index f0878eaafa..4895334645 100644
> > --- a/include/qemu/cutils.h
> > +++ b/include/qemu/cutils.h
>
> I'd rather move this function below pow2ceil() in "qemu/host-utils.h"
> and rename it pow2roundup().
>
> > @@ -164,4 +164,14 @@ bool test_buffer_is_zero_next_accel(void);
> > int uleb128_encode_small(uint8_t *out, uint32_t n);
> > int uleb128_decode_small(const uint8_t *in, uint32_t *n);
> >
> > +static inline int roundup_pow_of_two(w x)
> > +{
> > + x |= (x >> 1);
> > + x |= (x >> 2);
> > + x |= (x >> 4);
> > + x |= (x >> 8);
> > + x |= (x >> 16);
>
> So this would be pow2roundup32(uint32_t value)...
>
> Naming it pow2roundup() without specifying the integer size, I'd
> directly use a uint64_t argument, and:
>
> x |= (x >> 32);
Make sense, will do.
>
> > + return x + 1;
> > +}
> > +
> > #endif
>
> Naming it pow2roundup() in "qemu/host-utils.h" (regardless the arg size):
> Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Thanks.
>
> Regards,
>
> Phil.
© 2016 - 2025 Red Hat, Inc.