From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35513) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YPnnK-0001ZY-J4 for qemu-devel@nongnu.org; Mon, 23 Feb 2015 02:51:11 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YPnnF-0001a4-7M for qemu-devel@nongnu.org; Mon, 23 Feb 2015 02:51:10 -0500 Received: from e23smtp01.au.ibm.com ([202.81.31.143]:55639) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YPnnE-0001Za-Dl for qemu-devel@nongnu.org; Mon, 23 Feb 2015 02:51:05 -0500 Received: from /spool/local by e23smtp01.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 23 Feb 2015 17:50:59 +1000 Received: from d23relay09.au.ibm.com (d23relay09.au.ibm.com [9.185.63.181]) by d23dlp02.au.ibm.com (Postfix) with ESMTP id 99AE02BB0051 for ; Mon, 23 Feb 2015 18:50:55 +1100 (EST) Received: from d23av03.au.ibm.com (d23av03.au.ibm.com [9.190.234.97]) by d23relay09.au.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id t1N7okBF43122866 for ; Mon, 23 Feb 2015 18:50:55 +1100 Received: from d23av03.au.ibm.com (localhost [127.0.0.1]) by d23av03.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id t1N7oLqV030359 for ; Mon, 23 Feb 2015 18:50:21 +1100 From: Alexey Kardashevskiy Date: Mon, 23 Feb 2015 18:49:56 +1100 Message-Id: <1424677796-3044-1-git-send-email-aik@ozlabs.ru> Subject: [Qemu-devel] [RFC PATCH] utils: Add up_pow_of_two() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Alexey Kardashevskiy , Alexander Graf This adds a helper to get closest bigger power-of-two value. Signed-off-by: Alexey Kardashevskiy --- 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