From patchwork Mon Oct 24 17:39:17 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 686136 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 3t2m5W641rz9t15 for ; Tue, 25 Oct 2016 06:08:15 +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=yJpi19h4; dkim-atps=neutral Received: from localhost ([::1]:49165 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bykbU-0004DP-QY for incoming@patchwork.ozlabs.org; Mon, 24 Oct 2016 15:08:12 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39920) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1byjE6-0002He-Ac for qemu-devel@nongnu.org; Mon, 24 Oct 2016 13:39:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1byjE4-0005LP-IM for qemu-devel@nongnu.org; Mon, 24 Oct 2016 13:39:58 -0400 Received: from mail-pf0-x242.google.com ([2607:f8b0:400e:c00::242]:35295) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1byjE4-0005Ka-3R for qemu-devel@nongnu.org; Mon, 24 Oct 2016 13:39:56 -0400 Received: by mail-pf0-x242.google.com with SMTP id s8so17105705pfj.2 for ; Mon, 24 Oct 2016 10:39:55 -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=zZKTMACnBkgVKOR32WoQruZUQdHG4n8wzHbl49VgYbc=; b=yJpi19h4D7eoQWeiMIz5MB0DONblknlMImyf/oJdPvf64NM4ZhqrVKd/R/uJ8Z2mAx ldauZQvRdwRDjXbWGVQLgrBwnyevcigUtFMPGYOXrNdrYQI8dwMndzhBgoECumlvsZQ0 Rn8byx9OO4oI6PsJTF+R4kfYc4M/ioNG3VRNQ+BUte3XmKaT9T9PmCuJh/lQHBEKtNL4 OvvMN48JwOcct17XQRIkMOtSPVHMGOsSG369gTRfsfjwIZgXZD3yfeHRHobgLPtkCa2F pf+1wKj3hpxC0rp3ojIt4R4CQ7xf1OOBNJunaoJXFKRQNONNgaVbbzVGYd8s5hDgHJLu URvQ== 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=zZKTMACnBkgVKOR32WoQruZUQdHG4n8wzHbl49VgYbc=; b=SN9OJe1OOzVykeLeS3MwBAxxoaP4s9FCOSUkryfMMXw5qzBZMqh4W2uxgwzeKJDdwf T7Q+7TrLovx8GLoF6XAfOKAv13gFwqYkvwd89rIc2ukNnDGAqKe5ZrqFSrqORUkvvzD2 0uWjLbHSyX+CtNZLeQ86Ykriv1UPAJQL5pl8Ic0gM72KJQUPeonXqrXubPzWqKVco6WS SS6TI9VeLKxz97eE17HOkU59dPMubz5PVGn9J+Xu3O3/QCaB3VISYTS2IUV01IT/qHgE si7FfuXaPKctQozA1LnXjsHeSA7BzqbutHDq9SjMvLw4hDTsqZA/xEMHqNaAkiHCxppW 0/3w== X-Gm-Message-State: ABUngvd4M2zKv8VbrM5eszb95pqv9e25NvqNzsudPjAFXcQLkeM2Ai2sA8tC43bqHxsIMA== X-Received: by 10.98.41.3 with SMTP id p3mr30728329pfp.92.1477330794500; Mon, 24 Oct 2016 10:39:54 -0700 (PDT) Received: from bigtime.twiddle.net (174-24-157-40.tukw.qwest.net. [174.24.157.40]) by smtp.gmail.com with ESMTPSA id c15sm26908312pfd.53.2016.10.24.10.39.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 24 Oct 2016 10:39:54 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Mon, 24 Oct 2016 10:39:17 -0700 Message-Id: <1477330788-14996-7-git-send-email-rth@twiddle.net> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1477330788-14996-1-git-send-email-rth@twiddle.net> References: <1477330788-14996-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:400e:c00::242 Subject: [Qemu-devel] [PATCH v8 06/37] int128: Use __int128 if available 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, cota@braap.org, alex.bennee@linaro.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Reviewed-by: Emilio G. Cota Reviewed-by: Alex Bennée Signed-off-by: Richard Henderson --- include/qemu/int128.h | 135 +++++++++++++++++++++++++++++++++++++++++++++++++- tests/test-int128.c | 22 ++++---- 2 files changed, 145 insertions(+), 12 deletions(-) diff --git a/include/qemu/int128.h b/include/qemu/int128.h index 52aaf99..64a7aca 100644 --- a/include/qemu/int128.h +++ b/include/qemu/int128.h @@ -1,6 +1,138 @@ #ifndef INT128_H #define INT128_H +#ifdef CONFIG_INT128 + +typedef __int128_t Int128; + +static inline Int128 int128_make64(uint64_t a) +{ + return a; +} + +static inline uint64_t int128_get64(Int128 a) +{ + uint64_t r = a; + assert(r == a); + return r; +} + +static inline uint64_t int128_getlo(Int128 a) +{ + return a; +} + +static inline int64_t int128_gethi(Int128 a) +{ + return a >> 64; +} + +static inline Int128 int128_zero(void) +{ + return 0; +} + +static inline Int128 int128_one(void) +{ + return 1; +} + +static inline Int128 int128_2_64(void) +{ + return (Int128)1 << 64; +} + +static inline Int128 int128_exts64(int64_t a) +{ + return a; +} + +static inline Int128 int128_and(Int128 a, Int128 b) +{ + return a & b; +} + +static inline Int128 int128_rshift(Int128 a, int n) +{ + return a >> n; +} + +static inline Int128 int128_add(Int128 a, Int128 b) +{ + return a + b; +} + +static inline Int128 int128_neg(Int128 a) +{ + return -a; +} + +static inline Int128 int128_sub(Int128 a, Int128 b) +{ + return a - b; +} + +static inline bool int128_nonneg(Int128 a) +{ + return a >= 0; +} + +static inline bool int128_eq(Int128 a, Int128 b) +{ + return a == b; +} + +static inline bool int128_ne(Int128 a, Int128 b) +{ + return a != b; +} + +static inline bool int128_ge(Int128 a, Int128 b) +{ + return a >= b; +} + +static inline bool int128_lt(Int128 a, Int128 b) +{ + return a < b; +} + +static inline bool int128_le(Int128 a, Int128 b) +{ + return a <= b; +} + +static inline bool int128_gt(Int128 a, Int128 b) +{ + return a > b; +} + +static inline bool int128_nz(Int128 a) +{ + return a != 0; +} + +static inline Int128 int128_min(Int128 a, Int128 b) +{ + return a < b ? a : b; +} + +static inline Int128 int128_max(Int128 a, Int128 b) +{ + return a > b ? a : b; +} + +static inline void int128_addto(Int128 *a, Int128 b) +{ + *a += b; +} + +static inline void int128_subfrom(Int128 *a, Int128 b) +{ + *a -= b; +} + +#else /* !CONFIG_INT128 */ typedef struct Int128 Int128; @@ -153,4 +285,5 @@ static inline void int128_subfrom(Int128 *a, Int128 b) *a = int128_sub(*a, b); } -#endif +#endif /* CONFIG_INT128 */ +#endif /* INT128_H */ diff --git a/tests/test-int128.c b/tests/test-int128.c index 4390123..b86a3c7 100644 --- a/tests/test-int128.c +++ b/tests/test-int128.c @@ -41,7 +41,7 @@ static Int128 expand(uint32_t x) uint64_t l, h; l = expand16(x & 65535); h = expand16(x >> 16); - return (Int128) {l, h}; + return (Int128) int128_make128(l, h); }; static void test_and(void) @@ -54,8 +54,8 @@ static void test_and(void) Int128 b = expand(tests[j]); Int128 r = expand(tests[i] & tests[j]); Int128 s = int128_and(a, b); - g_assert_cmpuint(r.lo, ==, s.lo); - g_assert_cmpuint(r.hi, ==, s.hi); + g_assert_cmpuint(int128_getlo(r), ==, int128_getlo(s)); + g_assert_cmpuint(int128_gethi(r), ==, int128_gethi(s)); } } } @@ -70,8 +70,8 @@ static void test_add(void) Int128 b = expand(tests[j]); Int128 r = expand(tests[i] + tests[j]); Int128 s = int128_add(a, b); - g_assert_cmpuint(r.lo, ==, s.lo); - g_assert_cmpuint(r.hi, ==, s.hi); + g_assert_cmpuint(int128_getlo(r), ==, int128_getlo(s)); + g_assert_cmpuint(int128_gethi(r), ==, int128_gethi(s)); } } } @@ -86,8 +86,8 @@ static void test_sub(void) Int128 b = expand(tests[j]); Int128 r = expand(tests[i] - tests[j]); Int128 s = int128_sub(a, b); - g_assert_cmpuint(r.lo, ==, s.lo); - g_assert_cmpuint(r.hi, ==, s.hi); + g_assert_cmpuint(int128_getlo(r), ==, int128_getlo(s)); + g_assert_cmpuint(int128_gethi(r), ==, int128_gethi(s)); } } } @@ -100,8 +100,8 @@ static void test_neg(void) Int128 a = expand(tests[i]); Int128 r = expand(-tests[i]); Int128 s = int128_neg(a); - g_assert_cmpuint(r.lo, ==, s.lo); - g_assert_cmpuint(r.hi, ==, s.hi); + g_assert_cmpuint(int128_getlo(r), ==, int128_getlo(s)); + g_assert_cmpuint(int128_gethi(r), ==, int128_gethi(s)); } } @@ -180,8 +180,8 @@ test_rshift_one(uint32_t x, int n, uint64_t h, uint64_t l) { Int128 a = expand(x); Int128 r = int128_rshift(a, n); - g_assert_cmpuint(r.lo, ==, l); - g_assert_cmpuint(r.hi, ==, h); + g_assert_cmpuint(int128_getlo(r), ==, l); + g_assert_cmpuint(int128_gethi(r), ==, h); } static void test_rshift(void)