* [Qemu-devel] [PATCH v2 0/2] Fix qdev 32-bit compilation @ 2013-07-30 18:20 Richard Henderson 2013-07-30 18:20 ` [Qemu-devel] [PATCH v2 1/2] qdev: Fix 32-bit compilation in print_size Richard Henderson ` (2 more replies) 0 siblings, 3 replies; 5+ messages in thread From: Richard Henderson @ 2013-07-30 18:20 UTC (permalink / raw) To: qemu-devel; +Cc: vasilis.liaskovitis, imammedo, aliguori, afaerber The patch e8cd45c78f53501e75bd455140da63d1b7ed3685 broke compilation on 32-bit with a 40-bit shift of "long int". The first patch is the trivial fix for that bug. The second patch is an optional improvement that avoids the division loop entirely. r~ -- V2: Fixing erroneous email from mis-configured vm. Richard Henderson (2): qdev: Fix 32-bit compilation in print_size qdev: Use clz in print_size hw/core/qdev-properties.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) -- 1.8.3.1 ^ permalink raw reply [flat|nested] 5+ messages in thread
* [Qemu-devel] [PATCH v2 1/2] qdev: Fix 32-bit compilation in print_size 2013-07-30 18:20 [Qemu-devel] [PATCH v2 0/2] Fix qdev 32-bit compilation Richard Henderson @ 2013-07-30 18:20 ` Richard Henderson 2013-07-31 7:46 ` Andreas Färber 2013-07-30 18:20 ` [Qemu-devel] [PATCH v2 2/2] qdev: Use clz " Richard Henderson 2013-08-02 12:34 ` [Qemu-devel] [PATCH v2 0/2] Fix qdev 32-bit compilation Anthony Liguori 2 siblings, 1 reply; 5+ messages in thread From: Richard Henderson @ 2013-07-30 18:20 UTC (permalink / raw) To: qemu-devel; +Cc: vasilis.liaskovitis, imammedo, aliguori, afaerber Signed-off-by: Richard Henderson <rth@twiddle.net> --- hw/core/qdev-properties.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c index 8d43a8d..d6d10c9 100644 --- a/hw/core/qdev-properties.c +++ b/hw/core/qdev-properties.c @@ -1177,7 +1177,7 @@ static int print_size(DeviceState *dev, Property *prop, char *dest, size_t len) int i = 0; uint64_t div; - for (div = (long int)1 << 40; !(*ptr / div) ; div >>= 10) { + for (div = 1ULL << 40; !(*ptr / div) ; div >>= 10) { i++; } return snprintf(dest, len, "%0.03f%c", (double)*ptr/div, suffixes[i]); -- 1.8.3.1 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH v2 1/2] qdev: Fix 32-bit compilation in print_size 2013-07-30 18:20 ` [Qemu-devel] [PATCH v2 1/2] qdev: Fix 32-bit compilation in print_size Richard Henderson @ 2013-07-31 7:46 ` Andreas Färber 0 siblings, 0 replies; 5+ messages in thread From: Andreas Färber @ 2013-07-31 7:46 UTC (permalink / raw) To: Richard Henderson Cc: vasilis.liaskovitis, imammedo, aliguori, qemu-devel, Stefan Weil Anthony, Am 30.07.2013 20:20, schrieb Richard Henderson: > Signed-off-by: Richard Henderson <rth@twiddle.net> FWIW Reviewed-by: Andreas Färber <afaerber@suse.de> This is a build fix, can you please review and apply 1/2? 2/2 was outside my quick understanding so I'm not sure. ;) rth, you forgot to mark it "for-1.6". Regards, Andreas > --- > hw/core/qdev-properties.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c > index 8d43a8d..d6d10c9 100644 > --- a/hw/core/qdev-properties.c > +++ b/hw/core/qdev-properties.c > @@ -1177,7 +1177,7 @@ static int print_size(DeviceState *dev, Property *prop, char *dest, size_t len) > int i = 0; > uint64_t div; > > - for (div = (long int)1 << 40; !(*ptr / div) ; div >>= 10) { > + for (div = 1ULL << 40; !(*ptr / div) ; div >>= 10) { > i++; > } > return snprintf(dest, len, "%0.03f%c", (double)*ptr/div, suffixes[i]); > -- SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg ^ permalink raw reply [flat|nested] 5+ messages in thread
* [Qemu-devel] [PATCH v2 2/2] qdev: Use clz in print_size 2013-07-30 18:20 [Qemu-devel] [PATCH v2 0/2] Fix qdev 32-bit compilation Richard Henderson 2013-07-30 18:20 ` [Qemu-devel] [PATCH v2 1/2] qdev: Fix 32-bit compilation in print_size Richard Henderson @ 2013-07-30 18:20 ` Richard Henderson 2013-08-02 12:34 ` [Qemu-devel] [PATCH v2 0/2] Fix qdev 32-bit compilation Anthony Liguori 2 siblings, 0 replies; 5+ messages in thread From: Richard Henderson @ 2013-07-30 18:20 UTC (permalink / raw) To: qemu-devel; +Cc: vasilis.liaskovitis, imammedo, aliguori, afaerber We can compute a floor log2 value with clz rather than a division loop. Signed-off-by: Richard Henderson <rth@twiddle.net> --- hw/core/qdev-properties.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c index d6d10c9..dc8ae69 100644 --- a/hw/core/qdev-properties.c +++ b/hw/core/qdev-properties.c @@ -1172,15 +1172,21 @@ static int parse_size(DeviceState *dev, Property *prop, const char *str) static int print_size(DeviceState *dev, Property *prop, char *dest, size_t len) { - uint64_t *ptr = qdev_get_prop_ptr(dev, prop); - char suffixes[] = {'T', 'G', 'M', 'K', 'B'}; - int i = 0; - uint64_t div; + static const char suffixes[] = { 'B', 'K', 'M', 'G', 'T' }; + uint64_t div, val = *(uint64_t *)qdev_get_prop_ptr(dev, prop); + int i; - for (div = 1ULL << 40; !(*ptr / div) ; div >>= 10) { - i++; + /* Compute floor(log2(val)). */ + i = 64 - clz64(val); + + /* Find the power of 1024 that we'll display as the units. */ + i /= 10; + if (i >= ARRAY_SIZE(suffixes)) { + i = ARRAY_SIZE(suffixes) - 1; } - return snprintf(dest, len, "%0.03f%c", (double)*ptr/div, suffixes[i]); + div = 1ULL << (i * 10); + + return snprintf(dest, len, "%0.03f%c", (double)val/div, suffixes[i]); } PropertyInfo qdev_prop_size = { -- 1.8.3.1 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH v2 0/2] Fix qdev 32-bit compilation 2013-07-30 18:20 [Qemu-devel] [PATCH v2 0/2] Fix qdev 32-bit compilation Richard Henderson 2013-07-30 18:20 ` [Qemu-devel] [PATCH v2 1/2] qdev: Fix 32-bit compilation in print_size Richard Henderson 2013-07-30 18:20 ` [Qemu-devel] [PATCH v2 2/2] qdev: Use clz " Richard Henderson @ 2013-08-02 12:34 ` Anthony Liguori 2 siblings, 0 replies; 5+ messages in thread From: Anthony Liguori @ 2013-08-02 12:34 UTC (permalink / raw) To: Richard Henderson, qemu-devel Cc: vasilis.liaskovitis, imammedo, aliguori, afaerber Applied. Thanks. Regards, Anthony Liguori ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2013-08-02 14:53 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2013-07-30 18:20 [Qemu-devel] [PATCH v2 0/2] Fix qdev 32-bit compilation Richard Henderson 2013-07-30 18:20 ` [Qemu-devel] [PATCH v2 1/2] qdev: Fix 32-bit compilation in print_size Richard Henderson 2013-07-31 7:46 ` Andreas Färber 2013-07-30 18:20 ` [Qemu-devel] [PATCH v2 2/2] qdev: Use clz " Richard Henderson 2013-08-02 12:34 ` [Qemu-devel] [PATCH v2 0/2] Fix qdev 32-bit compilation Anthony Liguori
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).