From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49655) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VCSTf-0003Cs-1v for qemu-devel@nongnu.org; Thu, 22 Aug 2013 06:51:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VCSTR-00059c-WD for qemu-devel@nongnu.org; Thu, 22 Aug 2013 06:50:54 -0400 Received: from mail-pb0-f45.google.com ([209.85.160.45]:42168) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VCSTR-00059V-O7 for qemu-devel@nongnu.org; Thu, 22 Aug 2013 06:50:41 -0400 Received: by mail-pb0-f45.google.com with SMTP id mc17so1605434pbc.4 for ; Thu, 22 Aug 2013 03:50:40 -0700 (PDT) Message-ID: <5215ECFB.6080908@ozlabs.ru> Date: Thu, 22 Aug 2013 20:50:35 +1000 From: Alexey Kardashevskiy MIME-Version: 1.0 References: <1377159632-7446-1-git-send-email-aik@ozlabs.ru> <1377159632-7446-2-git-send-email-aik@ozlabs.ru> <5215D561.3050702@redhat.com> <5215DE80.4030203@redhat.com> In-Reply-To: <5215DE80.4030203@redhat.com> Content-Type: text/plain; charset=KOI8-R Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v2 1/3] int128: add int128_exts64() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Paolo Bonzini Cc: Peter Maydell , Alex Williamson , QEMU Developers On 08/22/2013 07:48 PM, Paolo Bonzini wrote: > Il 22/08/2013 11:47, Peter Maydell ha scritto: >> On 22 August 2013 10:09, Paolo Bonzini wrote: >>> Il 22/08/2013 10:20, Alexey Kardashevskiy ha scritto: >>>> +static inline Int128 int128_exts64(int64_t a) >>>> +{ >>>> + return (Int128) { .lo = a, .hi = (a >> 63) ? -1 : 0 }; >>>> +} >>> >>> The "? -1 : 0" is not necessary, but the compiler will remove it at -O1 >>> or more (interestingly, or -O0 it will remove the shift and leave the >>> conditional!). >> >> We can avoid relying on implementation defined >> behaviour here by using >> .hi = (a < 0) ? -1 : 0; >> >> (I know we allow ourselves to assume right-shift of signed >> ints is arithmetic shift, but I think it's nicer to avoid it unless >> it really makes the code better.) > > This is what Alexey proposed. I suggested (a >> 63) without the ?: but > he misunderstood my (probably not clear enough) suggestion. Yes, I misunderstood. It was not obvious to me that (signed long long)-1>>63 will be still -1. I really (really) envy people who can easily read stuff like but I cannot :( 1) return (Int128) { .lo = a, .hi = (a < 0) ? -1 : 0 }; 2) return (Int128) { .lo = a, .hi = (a < 0) }; 3) return (Int128) { .lo = a, .hi = a >> 63 }; So with which one should I repost the patch? -- Alexey