From patchwork Fri Jul 24 12:33:12 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 51438 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f197.google.com (mail-wi0-f197.google.com [209.85.212.197]) by patches.linaro.org (Postfix) with ESMTPS id 35D2522D94 for ; Fri, 24 Jul 2015 12:33:20 +0000 (UTC) Received: by wicmm11 with SMTP id mm11sf6350919wic.3 for ; Fri, 24 Jul 2015 05:33:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=001lbihlb1V6DiyEXSJ9fEWKmUN4g4AVthNhBVhkSAg=; b=IKVhp5OcuZb1WPlRGHizCruj36sT1poR4M8jcwWXx6ocWtXrw5EtEvqU1+yeZaf46A eM/Z05T5VM0H5T+QBufoawzwdYLyHl5X9lfpAiHO/hdVJcTafri9nO0yfnBjzdLkM954 pkZUwU3+FcGEOZiPQJwEiS9dRQRW+svRRQQ2zWoz0Vncl8vA7Qs+W5TC+SrvQ6YcrfBX pvlUEiPgbXdWul2E5ZQ+kTz7Gfjk4hwEaSCZy5bfdOX8+xWD/RRRAH3QfK3ldJCgUHvx HJZbBzNOhYKW3g9ulNSNcsy5mCryWYyKRnOwNsFUQtdUbzCGs9fh1Yfgv8Y86bWHFvND rZPg== X-Gm-Message-State: ALoCoQm5s/1Nd7EMZBB5mjXiKRJiDGj0BcfeAwVFyT5rkCfUTdACAOa1YAETNk3r4whBSGvpoaMq X-Received: by 10.112.118.194 with SMTP id ko2mr6081085lbb.16.1437741199534; Fri, 24 Jul 2015 05:33:19 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.1.73 with SMTP id 9ls333462lak.17.gmail; Fri, 24 Jul 2015 05:33:19 -0700 (PDT) X-Received: by 10.112.205.1 with SMTP id lc1mr13443264lbc.94.1437741199395; Fri, 24 Jul 2015 05:33:19 -0700 (PDT) Received: from mail-lb0-f169.google.com (mail-lb0-f169.google.com. [209.85.217.169]) by mx.google.com with ESMTPS id n2si7390807lan.167.2015.07.24.05.33.19 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 24 Jul 2015 05:33:19 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.169 as permitted sender) client-ip=209.85.217.169; Received: by lbbyj8 with SMTP id yj8so14286291lbb.0 for ; Fri, 24 Jul 2015 05:33:19 -0700 (PDT) X-Received: by 10.112.120.134 with SMTP id lc6mr13485945lbb.86.1437741199272; Fri, 24 Jul 2015 05:33:19 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.112.7.198 with SMTP id l6csp1150279lba; Fri, 24 Jul 2015 05:33:18 -0700 (PDT) X-Received: by 10.152.23.4 with SMTP id i4mr13440192laf.51.1437741196193; Fri, 24 Jul 2015 05:33:16 -0700 (PDT) Received: from mnementh.archaic.org.uk (mnementh.archaic.org.uk. [2001:8b0:1d0::1]) by mx.google.com with ESMTPS id go10si7388731lbc.173.2015.07.24.05.33.15 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Fri, 24 Jul 2015 05:33:15 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 2001:8b0:1d0::1 as permitted sender) client-ip=2001:8b0:1d0::1; Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.80) (envelope-from ) id 1ZIcA5-0005Sq-20; Fri, 24 Jul 2015 13:33:13 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Cc: patches@linaro.org, Paolo Bonzini , Keith Busch , Kevin Wolf , "Michael S. Tsirkin" , qemu-block@nongnu.org Subject: [PATCH v2 6/6] Make pow2ceil() and pow2floor() inline Date: Fri, 24 Jul 2015 13:33:12 +0100 Message-Id: <1437741192-20955-7-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1437741192-20955-1-git-send-email-peter.maydell@linaro.org> References: <1437741192-20955-1-git-send-email-peter.maydell@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: peter.maydell@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.169 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , 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