Re: [Qemu-devel] [PATCH v2] utils: Add pow2ceil()

2015-03-13 Thread Richard Henderson
On 03/12/2015 09:45 AM, Eric Blake wrote: > On 03/12/2015 09:29 AM, Richard Henderson wrote: >> On 02/25/2015 02:45 AM, Markus Armbruster wrote: >>> return 0x8000u >> (clz64(value - 1) - 1); >> >> I realize this was weeks ago, but it would certainly be preferable to shift a >> small con

Re: [Qemu-devel] [PATCH v2] utils: Add pow2ceil()

2015-03-13 Thread Markus Armbruster
Richard Henderson writes: > On 02/25/2015 02:45 AM, Markus Armbruster wrote: >> return 0x8000u >> (clz64(value - 1) - 1); > > I realize this was weeks ago, but it would certainly be preferable to shift a > small constant left than a large constant right. > > Most RISC machines can't f

Re: [Qemu-devel] [PATCH v2] utils: Add pow2ceil()

2015-03-12 Thread Eric Blake
On 03/12/2015 09:29 AM, Richard Henderson wrote: > On 02/25/2015 02:45 AM, Markus Armbruster wrote: >> return 0x8000u >> (clz64(value - 1) - 1); > > I realize this was weeks ago, but it would certainly be preferable to shift a > small constant left than a large constant right. > > Mos

Re: [Qemu-devel] [PATCH v2] utils: Add pow2ceil()

2015-03-12 Thread Richard Henderson
On 02/25/2015 02:45 AM, Markus Armbruster wrote: > return 0x8000u >> (clz64(value - 1) - 1); I realize this was weeks ago, but it would certainly be preferable to shift a small constant left than a large constant right. Most RISC machines can't form 0x8000ull without loadi

Re: [Qemu-devel] [PATCH v2] utils: Add pow2ceil()

2015-02-25 Thread Markus Armbruster
Alexey Kardashevskiy writes: > On 02/24/2015 12:59 AM, Markus Armbruster wrote: >> Alexey Kardashevskiy writes: >> >>> This adds a helper to get closest bigger power-of-two value. >>> >>> Signed-off-by: Alexey Kardashevskiy >>> --- >>> Changes: >>> v2: >>> * s/up_pow_of_two/pow2ceil/ >>> --- >>

Re: [Qemu-devel] [PATCH v2] utils: Add pow2ceil()

2015-02-24 Thread Alexey Kardashevskiy
On 02/24/2015 12:59 AM, Markus Armbruster wrote: Alexey Kardashevskiy writes: This adds a helper to get closest bigger power-of-two value. Signed-off-by: Alexey Kardashevskiy --- Changes: v2: * s/up_pow_of_two/pow2ceil/ --- include/qemu-common.h | 2 ++ util/cutils.c | 9 +

Re: [Qemu-devel] [PATCH v2] utils: Add pow2ceil()

2015-02-24 Thread Markus Armbruster
Peter Maydell writes: > On 24 February 2015 at 18:39, Markus Armbruster wrote: >> Eric Blake writes: >>> Because 0x8000u is only required to be a 'long', and on >>> 32-bit machines, your constant would overflow long. See, for example, >>> commit 5cb6be2ca. You NEED the 'll' suffix

Re: [Qemu-devel] [PATCH v2] utils: Add pow2ceil()

2015-02-24 Thread Peter Maydell
On 24 February 2015 at 18:39, Markus Armbruster wrote: > Eric Blake writes: >> Because 0x8000u is only required to be a 'long', and on >> 32-bit machines, your constant would overflow long. See, for example, >> commit 5cb6be2ca. You NEED the 'll' suffix to ensure that the compiler >

Re: [Qemu-devel] [PATCH v2] utils: Add pow2ceil()

2015-02-24 Thread Markus Armbruster
Eric Blake writes: > On 02/23/2015 10:40 AM, Markus Armbruster wrote: > int64_t pow2floor(int64_t value) { assert(value > 0); return 0x8000u >> clz64(value); } >>> >>> Needs to be 0x8000ull for 32-bit machines to compile correctly. >> >> W

Re: [Qemu-devel] [PATCH v2] utils: Add pow2ceil()

2015-02-23 Thread Eric Blake
On 02/23/2015 10:40 AM, Markus Armbruster wrote: >>> int64_t pow2floor(int64_t value) >>> { >>> assert(value > 0); >>> return 0x8000u >> clz64(value); >>> } >> >> Needs to be 0x8000ull for 32-bit machines to compile correctly. > > Why? Because 0x8000u

Re: [Qemu-devel] [PATCH v2] utils: Add pow2ceil()

2015-02-23 Thread Eric Blake
On 02/23/2015 06:59 AM, Markus Armbruster wrote: > Alexey Kardashevskiy writes: > >> This adds a helper to get closest bigger power-of-two value. >> > > Here's how I'd do these functions: > > int64_t pow2floor(int64_t value) > { > assert(value > 0); > return 0x8000u >> clz6

Re: [Qemu-devel] [PATCH v2] utils: Add pow2ceil()

2015-02-23 Thread Markus Armbruster
Alexey Kardashevskiy writes: > This adds a helper to get closest bigger power-of-two value. > > Signed-off-by: Alexey Kardashevskiy > --- > Changes: > v2: > * s/up_pow_of_two/pow2ceil/ > --- > include/qemu-common.h | 2 ++ > util/cutils.c | 9 + > 2 files changed, 11 insertions(

[Qemu-devel] [PATCH v2] utils: Add pow2ceil()

2015-02-23 Thread Alexey Kardashevskiy
This adds a helper to get closest bigger power-of-two value. Signed-off-by: Alexey Kardashevskiy --- Changes: v2: * s/up_pow_of_two/pow2ceil/ --- include/qemu-common.h | 2 ++ util/cutils.c | 9 + 2 files changed, 11 insertions(+) diff --git a/include/qemu-common.h b/include/qem