* [Qemu-devel] [RFC PATCH] utils: Add up_pow_of_two()
@ 2015-02-23 7:49 Alexey Kardashevskiy
2015-02-23 8:54 ` Peter Maydell
0 siblings, 1 reply; 3+ messages in thread
From: Alexey Kardashevskiy @ 2015-02-23 7:49 UTC (permalink / raw)
To: qemu-devel; +Cc: Alexey Kardashevskiy, Alexander Graf
This adds a helper to get closest bigger power-of-two value.
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
---
It is a log2 of round up to power of two. Is there anything like this
in QEMU already? Any better name than up_pow_of_two()?
I'll use this little helper later to calculate a DMA window shift as
POWERPC PAPR architecture operates with shifts rather than bytes or TCE entries.
Thanks!
---
include/qemu/host-utils.h | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/include/qemu/host-utils.h b/include/qemu/host-utils.h
index d4f21c9..b1ad164 100644
--- a/include/qemu/host-utils.h
+++ b/include/qemu/host-utils.h
@@ -361,6 +361,17 @@ static inline int ctpop64(uint64_t val)
#endif
}
+static inline int up_pow_of_two(uint64_t x)
+{
+ int m = 63 - clz64(x);
+
+ if ((1ULL << m) == x) {
+ return m;
+ }
+
+ return m + 1;
+}
+
/* Host type specific sizes of these routines. */
#if ULONG_MAX == UINT32_MAX
--
2.0.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] [RFC PATCH] utils: Add up_pow_of_two()
2015-02-23 7:49 [Qemu-devel] [RFC PATCH] utils: Add up_pow_of_two() Alexey Kardashevskiy
@ 2015-02-23 8:54 ` Peter Maydell
2015-02-23 12:20 ` Alexey Kardashevskiy
0 siblings, 1 reply; 3+ messages in thread
From: Peter Maydell @ 2015-02-23 8:54 UTC (permalink / raw)
To: Alexey Kardashevskiy; +Cc: QEMU Developers, Alexander Graf
On 23 February 2015 at 16:49, Alexey Kardashevskiy <aik@ozlabs.ru> wrote:
> This adds a helper to get closest bigger power-of-two value.
>
> Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
> ---
>
> It is a log2 of round up to power of two. Is there anything like this
> in QEMU already? Any better name than up_pow_of_two()?
Maybe separate out the "round up to power of 2" and "log2" parts
into separate functions? If you do that then you could call the
first one of those pow2ceil(), to match our existing
pow2floor().
-- PMM
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] [RFC PATCH] utils: Add up_pow_of_two()
2015-02-23 8:54 ` Peter Maydell
@ 2015-02-23 12:20 ` Alexey Kardashevskiy
0 siblings, 0 replies; 3+ messages in thread
From: Alexey Kardashevskiy @ 2015-02-23 12:20 UTC (permalink / raw)
To: Peter Maydell; +Cc: QEMU Developers, Alexander Graf
On 02/23/2015 07:54 PM, Peter Maydell wrote:
> On 23 February 2015 at 16:49, Alexey Kardashevskiy <aik@ozlabs.ru> wrote:
>> This adds a helper to get closest bigger power-of-two value.
>>
>> Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
>> ---
>>
>> It is a log2 of round up to power of two. Is there anything like this
>> in QEMU already? Any better name than up_pow_of_two()?
>
> Maybe separate out the "round up to power of 2" and "log2" parts
> into separate functions? If you do that then you could call the
> first one of those pow2ceil(), to match our existing
> pow2floor().
good point, powe2ceil() is enough for me, I'll repost it in a sec. thanks!
--
Alexey
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2015-02-23 12:20 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-02-23 7:49 [Qemu-devel] [RFC PATCH] utils: Add up_pow_of_two() Alexey Kardashevskiy
2015-02-23 8:54 ` Peter Maydell
2015-02-23 12:20 ` Alexey Kardashevskiy
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).