From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45642) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZQOcg-0006fW-3h for qemu-devel@nongnu.org; Fri, 14 Aug 2015 19:42:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZQOce-0007I7-TP for qemu-devel@nongnu.org; Fri, 14 Aug 2015 19:42:54 -0400 Sender: Paolo Bonzini References: <1437741192-20955-1-git-send-email-peter.maydell@linaro.org> <1437741192-20955-7-git-send-email-peter.maydell@linaro.org> From: Paolo Bonzini Message-ID: <55CE7CF4.4020706@redhat.com> Date: Sat, 15 Aug 2015 01:42:44 +0200 MIME-Version: 1.0 In-Reply-To: <1437741192-20955-7-git-send-email-peter.maydell@linaro.org> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v2 6/6] Make pow2ceil() and pow2floor() inline List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Peter Maydell , qemu-devel@nongnu.org Cc: Kevin Wolf , Keith Busch , patches@linaro.org, qemu-block@nongnu.org, "Michael S. Tsirkin" On 24/07/2015 14:33, Peter Maydell wrote: > Since the pow2floor() function is now used in a hot code path, > make it inline; for consistency, provide pow2ceil() as an inline > function too. > > Because these functions use ctz64() we have to put the inline > versions into host-utils.h, so they have access to ctz64(), > and move the inline is_power_of_2() along with them. > > We then need to include host-utils.h from qemu-common.h so that > the files which use these functions via qemu-common.h still have > access to them. > > Signed-off-by: Peter Maydell > --- > include/qemu-common.h | 16 +--------------- > include/qemu/host-utils.h | 33 +++++++++++++++++++++++++++++++++ > util/cutils.c | 23 ----------------------- > 3 files changed, 34 insertions(+), 38 deletions(-) > > diff --git a/include/qemu-common.h b/include/qemu-common.h > index bc6f8f8..3d4279c 100644 > --- a/include/qemu-common.h > +++ b/include/qemu-common.h > @@ -43,6 +43,7 @@ > #include > #include "glib-compat.h" > #include "qemu/option.h" > +#include "qemu/host-utils.h" > > #ifdef _WIN32 > #include "sysemu/os-win32.h" > @@ -405,21 +406,6 @@ static inline uint64_t muldiv64(uint64_t a, uint32_t b, uint32_t c) > /* Round number up to multiple */ > #define QEMU_ALIGN_UP(n, m) QEMU_ALIGN_DOWN((n) + (m) - 1, (m)) > > -static inline bool is_power_of_2(uint64_t value) > -{ > - if (!value) { > - return 0; > - } > - > - return !(value & (value - 1)); > -} > - > -/* round down to the nearest power of 2*/ > -int64_t pow2floor(int64_t value); > - > -/* round up to the nearest power of 2 (0 if overflow) */ > -uint64_t pow2ceil(uint64_t value); > - > #include "qemu/module.h" > > /* > diff --git a/include/qemu/host-utils.h b/include/qemu/host-utils.h > index d4f21c9..9ed5cdd 100644 > --- a/include/qemu/host-utils.h > +++ b/include/qemu/host-utils.h > @@ -27,6 +27,7 @@ > > #include "qemu/compiler.h" /* QEMU_GNUC_PREREQ */ > #include > +#include > > #ifdef CONFIG_INT128 > static inline void mulu64(uint64_t *plow, uint64_t *phigh, > @@ -379,4 +380,36 @@ static inline int ctpop64(uint64_t val) > # error Unknown sizeof long > #endif > > +static inline bool is_power_of_2(uint64_t value) > +{ > + if (!value) { > + return 0; > + } > + > + return !(value & (value - 1)); > +} > + > +/* round down to the nearest power of 2*/ > +static inline int64_t pow2floor(int64_t value) > +{ > + if (!is_power_of_2(value)) { > + value = 0x8000000000000000ULL >> clz64(value); > + } > + return value; > +} > + > +/* round up to the nearest power of 2 (0 if overflow) */ > +static inline uint64_t pow2ceil(uint64_t value) > +{ > + uint8_t nlz = clz64(value); > + > + if (is_power_of_2(value)) { > + return value; > + } > + if (!nlz) { > + return 0; > + } > + return 1ULL << (64 - nlz); > +} > + > #endif > diff --git a/util/cutils.c b/util/cutils.c > index 43aafde..9234452 100644 > --- a/util/cutils.c > +++ b/util/cutils.c > @@ -469,29 +469,6 @@ int qemu_parse_fd(const char *param) > return fd; > } > > -/* round down to the nearest power of 2*/ > -int64_t pow2floor(int64_t value) > -{ > - if (!is_power_of_2(value)) { > - value = 0x8000000000000000ULL >> clz64(value); > - } > - return value; > -} > - > -/* round up to the nearest power of 2 (0 if overflow) */ > -uint64_t pow2ceil(uint64_t value) > -{ > - uint8_t nlz = clz64(value); > - > - if (is_power_of_2(value)) { > - return value; > - } > - if (!nlz) { > - return 0; > - } > - return 1ULL << (64 - nlz); > -} > - > /* > * Implementation of ULEB128 (http://en.wikipedia.org/wiki/LEB128) > * Input is limited to 14-bit numbers > Reviewed-by: Paolo Bonzini