From: Alexey Kardashevskiy <aik@ozlabs.ru>
To: qemu-devel@nongnu.org
Cc: Alexey Kardashevskiy <aik@ozlabs.ru>, Alexander Graf <agraf@suse.de>
Subject: [Qemu-devel] [RFC PATCH] utils: Add up_pow_of_two()
Date: Mon, 23 Feb 2015 18:49:56 +1100 [thread overview]
Message-ID: <1424677796-3044-1-git-send-email-aik@ozlabs.ru> (raw)
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
next reply other threads:[~2015-02-23 7:51 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-02-23 7:49 Alexey Kardashevskiy [this message]
2015-02-23 8:54 ` [Qemu-devel] [RFC PATCH] utils: Add up_pow_of_two() Peter Maydell
2015-02-23 12:20 ` Alexey Kardashevskiy
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1424677796-3044-1-git-send-email-aik@ozlabs.ru \
--to=aik@ozlabs.ru \
--cc=agraf@suse.de \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).