From patchwork Wed Oct 19 17:21:37 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 684252 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3szf6h5hwSz9sBR for ; Thu, 20 Oct 2016 04:28:28 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=QCZD5Dzq; dkim-atps=neutral Received: from localhost ([::1]:49929 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bwufB-00048t-L1 for incoming@patchwork.ozlabs.org; Wed, 19 Oct 2016 13:28:25 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47501) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bwuZi-0006Sf-4r for qemu-devel@nongnu.org; Wed, 19 Oct 2016 13:22:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bwuZh-0002t8-6H for qemu-devel@nongnu.org; Wed, 19 Oct 2016 13:22:46 -0400 Received: from mail-qk0-x241.google.com ([2607:f8b0:400d:c09::241]:35100) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1bwuZh-0002sZ-0D for qemu-devel@nongnu.org; Wed, 19 Oct 2016 13:22:45 -0400 Received: by mail-qk0-x241.google.com with SMTP id v138so2504548qka.2 for ; Wed, 19 Oct 2016 10:22:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Abq6zWikNo+PAjPL/jlgtQUF6mhfW+mJkVsO7X+hB6A=; b=QCZD5DzqrH/6nSqBkaRA5tqCIgpJ9jvpypmLd7GUCUXapzSPYOJbbxc34lHEon2bqt CjNKEID6D9KmPYXXXV+eCsG097J/rRNl0x4hhzZfKYSXVipjCIpCi/2KWPZWgvT/xzft JUQ42NFVcyWLXbowtRge27IQ5iktiw1pWmZzuZ9lcISMQL293jo+gNXIv2m0jrxDLJcD cWXpdvoNmoU6BLffK5rpT/Ap1ngbn+tqMvtB2hhDkM9KCOCDA2COZqYX55eN/biAMpP3 tdPpM4yBPMvMvgspFH6+9xje9QAVeOErJYPIVYjUgELqwpjsKlcOIKLcreEUBeuYGFXs tb0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=Abq6zWikNo+PAjPL/jlgtQUF6mhfW+mJkVsO7X+hB6A=; b=JwX4EE+gsjw7sAmkCZ2J4FA4HbNynMYCEh2qS3hvBa14T22zb1Zns7ug5NYMfBMqdZ ingvO1E/luMvuGj2siCfeyFjWcykLqLGlMATofVoNguMoTvabXoA/h9iz/4oysuraliN Jyyaz90ZLWbML/sl4N/6lOz2DF+tacI62K86c2HGf3n38eDTT92yW2HdcIFlmuCEb/Ec fOq/W/dUm1ChBM+hOFzNWqDYMFU/7sJlNTmYlZ9mLld/qqQkU8ZrYpRbKBF9WuY8Otwi vxGuP3Nt2kVnhYr48Q0xtw2kErB6BztD9Pjqy3niKg+Mk7smkfmoLlb52nZW4UbWuV9F 9VIw== X-Gm-Message-State: ABUngvdBMuWEintSqAw6A8O86d/REPsXy6AZbLBxX8mEs7EijM+w5waH64kLgLazbXdUYw== X-Received: by 10.55.10.15 with SMTP id 15mr6723497qkk.99.1476897764048; Wed, 19 Oct 2016 10:22:44 -0700 (PDT) Received: from bigtime.com (174-24-157-40.tukw.qwest.net. [174.24.157.40]) by smtp.gmail.com with ESMTPSA id 16sm18357530qtf.36.2016.10.19.10.22.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 19 Oct 2016 10:22:43 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Wed, 19 Oct 2016 10:21:37 -0700 Message-Id: <1476897727-791-6-git-send-email-rth@twiddle.net> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1476897727-791-1-git-send-email-rth@twiddle.net> References: <1476897727-791-1-git-send-email-rth@twiddle.net> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:400d:c09::241 Subject: [Qemu-devel] [PATCH v7 05/35] int128: Add int128_make128 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: cota@braap.org, alex.bennee@linaro.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Allows Int128 to be used more generally, rather than having to begin with 64-bit inputs and accumulate. Reviewed-by: Emilio G. Cota Reviewed-by: Alex Bennée Signed-off-by: Richard Henderson --- include/qemu/int128.h | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/include/qemu/int128.h b/include/qemu/int128.h index 64a7aca..d4c6e44 100644 --- a/include/qemu/int128.h +++ b/include/qemu/int128.h @@ -10,6 +10,11 @@ static inline Int128 int128_make64(uint64_t a) return a; } +static inline Int128 int128_make128(uint64_t lo, uint64_t hi) +{ + return (__uint128_t)hi << 64 | lo; +} + static inline uint64_t int128_get64(Int128 a) { uint64_t r = a; @@ -146,6 +151,11 @@ static inline Int128 int128_make64(uint64_t a) return (Int128) { a, 0 }; } +static inline Int128 int128_make128(uint64_t lo, uint64_t hi) +{ + return (Int128) { lo, hi }; +} + static inline uint64_t int128_get64(Int128 a) { assert(!a.hi); @@ -195,9 +205,9 @@ static inline Int128 int128_rshift(Int128 a, int n) } h = a.hi >> (n & 63); if (n >= 64) { - return (Int128) { h, h >> 63 }; + return int128_make128(h, h >> 63); } else { - return (Int128) { (a.lo >> n) | ((uint64_t)a.hi << (64 - n)), h }; + return int128_make128((a.lo >> n) | ((uint64_t)a.hi << (64 - n)), h); } } @@ -211,18 +221,18 @@ static inline Int128 int128_add(Int128 a, Int128 b) * * So the carry is lo < a.lo. */ - return (Int128) { lo, (uint64_t)a.hi + b.hi + (lo < a.lo) }; + return int128_make128(lo, (uint64_t)a.hi + b.hi + (lo < a.lo)); } static inline Int128 int128_neg(Int128 a) { uint64_t lo = -a.lo; - return (Int128) { lo, ~(uint64_t)a.hi + !lo }; + return int128_make128(lo, ~(uint64_t)a.hi + !lo); } static inline Int128 int128_sub(Int128 a, Int128 b) { - return (Int128){ a.lo - b.lo, (uint64_t)a.hi - b.hi - (a.lo < b.lo) }; + return int128_make128(a.lo - b.lo, (uint64_t)a.hi - b.hi - (a.lo < b.lo)); } static inline bool int128_nonneg(Int128 a)