From patchwork Wed Jul 22 16:44:07 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 51373 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f69.google.com (mail-la0-f69.google.com [209.85.215.69]) by patches.linaro.org (Postfix) with ESMTPS id 5D0C4228EF for ; Wed, 22 Jul 2015 16:50:25 +0000 (UTC) Received: by laah7 with SMTP id h7sf33579391laa.2 for ; Wed, 22 Jul 2015 09:50:24 -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:date :message-id:in-reply-to:references:cc:subject:precedence:list-id :list-unsubscribe:list-archive:list-post:list-help:list-subscribe :errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list; bh=kzuYrTjpz32tFNJBHr9Qrwk4I9uZqt1o3M50rn+fJYA=; b=KZ0UmFrJShKZKyQxVAAgJ3kwpYCLPOA4EnYj+taGzqzAXDX6dyTBv5rJ+UbhdBPqLP 2d5vcmHx4HdBJ2iWxfOh2b8QfxqP5lrL/4Z0uTXNm7SEuUeIxE2NlSgRVOSX3VhbF6Ff WpofvEjFDa1GJSkxxanUpQy61mE35RV7V+x9ZD7ac06+MNKzl3UtcGWEQXgBKxbLJ7Pa Mbt7wZqqkF7r4K5z8OHKKreSD86aC4PVsfra4MoPHqnKWBwvP8+6hIERNNSHgWW8tnsP vxVlEB1r3K2yZjD3ipttiOk69HTPeWj3X/TY0vXFT0CADRoW1yx3pgiulck9jwHU+Fsa I7jQ== X-Gm-Message-State: ALoCoQk1Udo1cme0shm+NvdEo8uslSZbm9x095Ek14dWsAivBQS4mlil9241s6FeCIEVqSsFQ7yU X-Received: by 10.112.253.135 with SMTP id aa7mr1610299lbd.11.1437583824369; Wed, 22 Jul 2015 09:50:24 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.6.73 with SMTP id y9ls108285lay.18.gmail; Wed, 22 Jul 2015 09:50:24 -0700 (PDT) X-Received: by 10.112.61.132 with SMTP id p4mr3290014lbr.48.1437583824215; Wed, 22 Jul 2015 09:50:24 -0700 (PDT) Received: from mail-lb0-f175.google.com (mail-lb0-f175.google.com. [209.85.217.175]) by mx.google.com with ESMTPS id k3si1642640laf.146.2015.07.22.09.50.24 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 22 Jul 2015 09:50:24 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.175 as permitted sender) client-ip=209.85.217.175; Received: by lbbqi7 with SMTP id qi7so60314955lbb.3 for ; Wed, 22 Jul 2015 09:50:24 -0700 (PDT) X-Received: by 10.152.6.69 with SMTP id y5mr3249045lay.72.1437583824110; Wed, 22 Jul 2015 09:50:24 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.7.198 with SMTP id l6csp49163lba; Wed, 22 Jul 2015 09:50:23 -0700 (PDT) X-Received: by 10.181.13.134 with SMTP id ey6mr8390990wid.88.1437583823331; Wed, 22 Jul 2015 09:50:23 -0700 (PDT) Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id fq10si4517603wib.108.2015.07.22.09.50.22 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 22 Jul 2015 09:50:23 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Received: from localhost ([::1]:37541 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZHxDq-0001ty-4F for patch@linaro.org; Wed, 22 Jul 2015 12:50:22 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46099) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZHx85-0007li-N2 for qemu-devel@nongnu.org; Wed, 22 Jul 2015 12:44:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZHx80-0004cv-Fx for qemu-devel@nongnu.org; Wed, 22 Jul 2015 12:44:25 -0400 Received: from mnementh.archaic.org.uk ([2001:8b0:1d0::1]:34676) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZHx80-0004ZT-81 for qemu-devel@nongnu.org; Wed, 22 Jul 2015 12:44:20 -0400 Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.80) (envelope-from ) id 1ZHx7r-0002X3-Oi; Wed, 22 Jul 2015 17:44:11 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Date: Wed, 22 Jul 2015 17:44:07 +0100 Message-Id: <1437583451-9677-9-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1437583451-9677-1-git-send-email-peter.maydell@linaro.org> References: <1437583451-9677-1-git-send-email-peter.maydell@linaro.org> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2001:8b0:1d0::1 Cc: patches@linaro.org Subject: [Qemu-devel] [PATCH 08/12] qemu-common.h: Move muldiv64() to host-utils.h X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.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.175 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 Move the muldiv64() function from qemu-common.h to host-utils.h. This puts it together with all the other arithmetic functions where we provide a version with __int128_t and a fallback without, and allows headers which need muldiv64() to avoid including qemu-common.h. We don't include host-utils from qemu-common.h, to avoid dragging more things into qemu-common.h than it already has; in practice everywhere that needs muldiv64() can get it via qemu/timer.h. Signed-off-by: Peter Maydell --- include/qemu-common.h | 31 ------------------------------- include/qemu/host-utils.h | 29 +++++++++++++++++++++++++++++ include/qemu/timer.h | 1 + 3 files changed, 30 insertions(+), 31 deletions(-) diff --git a/include/qemu-common.h b/include/qemu-common.h index de4ae53..8d8b9d5 100644 --- a/include/qemu-common.h +++ b/include/qemu-common.h @@ -299,37 +299,6 @@ static inline uint8_t from_bcd(uint8_t val) return ((val >> 4) * 10) + (val & 0x0f); } -/* compute with 96 bit intermediate result: (a*b)/c */ -#ifdef CONFIG_INT128 -static inline uint64_t muldiv64(uint64_t a, uint32_t b, uint32_t c) -{ - return (__int128_t)a * b / c; -} -#else -static inline uint64_t muldiv64(uint64_t a, uint32_t b, uint32_t c) -{ - union { - uint64_t ll; - struct { -#ifdef HOST_WORDS_BIGENDIAN - uint32_t high, low; -#else - uint32_t low, high; -#endif - } l; - } u, res; - uint64_t rl, rh; - - u.ll = a; - rl = (uint64_t)u.l.low * (uint64_t)b; - rh = (uint64_t)u.l.high * (uint64_t)b; - rh += (rl >> 32); - res.l.high = rh / c; - res.l.low = (((rh % c) << 32) + (rl & 0xffffffff)) / c; - return res.ll; -} -#endif - /* Round number down to multiple */ #define QEMU_ALIGN_DOWN(n, m) ((n) / (m) * (m)) diff --git a/include/qemu/host-utils.h b/include/qemu/host-utils.h index d4f21c9..c27d3dc 100644 --- a/include/qemu/host-utils.h +++ b/include/qemu/host-utils.h @@ -45,6 +45,12 @@ static inline void muls64(uint64_t *plow, uint64_t *phigh, *phigh = r >> 64; } +/* compute with 96 bit intermediate result: (a*b)/c */ +static inline uint64_t muldiv64(uint64_t a, uint32_t b, uint32_t c) +{ + return (__int128_t)a * b / c; +} + static inline int divu128(uint64_t *plow, uint64_t *phigh, uint64_t divisor) { if (divisor == 0) { @@ -75,6 +81,29 @@ void muls64(uint64_t *phigh, uint64_t *plow, int64_t a, int64_t b); void mulu64(uint64_t *phigh, uint64_t *plow, uint64_t a, uint64_t b); int divu128(uint64_t *plow, uint64_t *phigh, uint64_t divisor); int divs128(int64_t *plow, int64_t *phigh, int64_t divisor); + +static inline uint64_t muldiv64(uint64_t a, uint32_t b, uint32_t c) +{ + union { + uint64_t ll; + struct { +#ifdef HOST_WORDS_BIGENDIAN + uint32_t high, low; +#else + uint32_t low, high; +#endif + } l; + } u, res; + uint64_t rl, rh; + + u.ll = a; + rl = (uint64_t)u.l.low * (uint64_t)b; + rh = (uint64_t)u.l.high * (uint64_t)b; + rh += (rl >> 32); + res.l.high = rh / c; + res.l.low = (((rh % c) << 32) + (rl & 0xffffffff)) / c; + return res.ll; +} #endif /** diff --git a/include/qemu/timer.h b/include/qemu/timer.h index 5923d60..9939246 100644 --- a/include/qemu/timer.h +++ b/include/qemu/timer.h @@ -4,6 +4,7 @@ #include "qemu/typedefs.h" #include "qemu-common.h" #include "qemu/notify.h" +#include "qemu/host-utils.h" #define NANOSECONDS_PER_SECOND 1000000000LL