From patchwork Wed Oct 26 16:15:33 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 687192 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 3t3wQN0JRtz9svs for ; Thu, 27 Oct 2016 03:26:52 +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=ahCftb1S; dkim-atps=neutral Received: from localhost ([::1]:35949 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bzR2P-0002qd-AA for incoming@patchwork.ozlabs.org; Wed, 26 Oct 2016 12:26:49 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37182) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bzQsi-0002ix-Ls for qemu-devel@nongnu.org; Wed, 26 Oct 2016 12:16:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bzQsf-0002Bx-GQ for qemu-devel@nongnu.org; Wed, 26 Oct 2016 12:16:48 -0400 Received: from mail-qk0-x244.google.com ([2607:f8b0:400d:c09::244]:36050) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1bzQsf-0002AN-BW for qemu-devel@nongnu.org; Wed, 26 Oct 2016 12:16:45 -0400 Received: by mail-qk0-x244.google.com with SMTP id z190so568318qkc.3 for ; Wed, 26 Oct 2016 09:16: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=ahCftb1SMXmpH9rjmsv79RrYiu7l/bTIYG6PoSFNpysSTqFz3Cks33XhTWO8o2xPC/ njqTPE+CS8FJfFIFRGcx0uA6rvYl5xRtmeEc32YdK6tDjMwvj2TjsvUiOmU0hlctT/vB P+UFjZ+xAN9f1HWuAU5Qwh7l6x8UjQPlOG1+5IXT7CdRMTUC0FFcFw5BMb6f5wlREgZs DcDHZq3lDTQL3wknl/a5xINt+HNKGsdSV41oNyjFYx9b7gQvdG09/nmxYhjtzTiNrO4d zh2Q/9yxeHvljiwWK7xg4noSSQqUw4lRtPXeX7FYKKD2pLt/5W6Y33zqQ/4JC6WPC6AC UN+A== 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=U77Z8LhBF32RMAS1n28DStGGXIeID40UY9ZzKOtpNlQSyXNMwJdg1Ji57KvfGqa6XX ZO89YahJ0YHQinSYDXiO4geTzjTVwfJrRUUE5Xm2uT7uH1Xs+neO3k9xJQk9iIB1wDfm VRVP/kUoXsmw/30ehtr0Fkz6KCzXqvvbgAVuLjUdVL0CJGU7T7QiRkhUjwdpjnuBqdvV lG/AZGW8s6ehkKj/sOJgMj7XONxGVDoyTqKTAbuUlomBXk5V2nZS++2UiS8I1xgaJVso vWTJmi1ael2qQBiKg94qDChSVh6BTPdkj197ivAb1S/h56hPDeqxtSGrh7M1KpecwWRr gTqQ== X-Gm-Message-State: ABUngvcbOwZz41an8e2xseS49vtpVkv7T9ThaYXvv1w5H4QCilOal2tEB2D/Lwh2v+BuTg== X-Received: by 10.55.106.2 with SMTP id f2mr2319681qkc.124.1477498603786; Wed, 26 Oct 2016 09:16:43 -0700 (PDT) Received: from bigtime.com (174-24-157-40.tukw.qwest.net. [174.24.157.40]) by smtp.gmail.com with ESMTPSA id e185sm1337941qkd.13.2016.10.26.09.16.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 26 Oct 2016 09:16:43 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Wed, 26 Oct 2016 09:15:33 -0700 Message-Id: <1477498563-29091-8-git-send-email-rth@twiddle.net> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1477498563-29091-1-git-send-email-rth@twiddle.net> References: <1477498563-29091-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::244 Subject: [Qemu-devel] [PULL v2 07/37] 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: peter.maydell@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)