From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60205) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1brLMi-0003QE-2r for qemu-devel@nongnu.org; Tue, 04 Oct 2016 04:46:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1brLMd-0003vU-4l for qemu-devel@nongnu.org; Tue, 04 Oct 2016 04:46:19 -0400 Received: from mail-wm0-x233.google.com ([2a00:1450:400c:c09::233]:37189) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1brLMc-0003v8-UK for qemu-devel@nongnu.org; Tue, 04 Oct 2016 04:46:15 -0400 Received: by mail-wm0-x233.google.com with SMTP id b201so130233995wmb.0 for ; Tue, 04 Oct 2016 01:46:14 -0700 (PDT) References: <1474048017-26696-1-git-send-email-rth@twiddle.net> <1474048017-26696-6-git-send-email-rth@twiddle.net> From: Alex =?utf-8?Q?Benn=C3=A9e?= In-reply-to: <1474048017-26696-6-git-send-email-rth@twiddle.net> Date: Tue, 04 Oct 2016 09:46:12 +0100 Message-ID: <87y424sdrf.fsf@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Subject: Re: [Qemu-devel] [PATCH v4 05/35] int128: Add int128_make128 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Richard Henderson Cc: qemu-devel@nongnu.org Richard Henderson writes: > Allows Int128 to be used more generally, rather than having to > begin with 64-bit inputs and accumulate. > > Signed-off-by: Richard Henderson Reviewed-by: Alex Bennée > --- > 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 08f1db1..67440fa 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 (unsigned __int128)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) -- Alex Bennée