From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:43288) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TTQpK-0002aG-Qk for qemu-devel@nongnu.org; Wed, 31 Oct 2012 01:26:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TTQpJ-0008CE-Jw for qemu-devel@nongnu.org; Wed, 31 Oct 2012 01:26:54 -0400 Received: from mail-da0-f45.google.com ([209.85.210.45]:64709) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TTQpJ-0008CA-DT for qemu-devel@nongnu.org; Wed, 31 Oct 2012 01:26:53 -0400 Received: by mail-da0-f45.google.com with SMTP id n15so443018dad.4 for ; Tue, 30 Oct 2012 22:26:52 -0700 (PDT) Sender: Richard Henderson Message-ID: <5090B693.4080604@twiddle.net> Date: Wed, 31 Oct 2012 16:26:43 +1100 From: Richard Henderson MIME-Version: 1.0 References: <874D219413C17C42B1D2E0432B92BE5CBBE221FF@exchdb03.mips.com> <874D219413C17C42B1D2E0432B92BE5CBBE22307@exchdb03.mips.com> In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v12 09/14] target-mips: Add ASE DSP bit/manipulation instructions List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Peter Maydell Cc: "Jovanovic, Petar" , Jia Liu , "qemu-devel@nongnu.org" On 2012-10-31 01:44, Peter Maydell wrote: > On 30 October 2012 15:34, Jia Liu wrote: >> On Mon, Oct 29, 2012 at 9:40 PM, Jovanovic, Petar wrote: >>>> imm = (int16_t)(imm << 6) >> 6; >>> >>> result of a bitwise shift of a signed type and a negative vlaue is >>> implementation-defined, so you can not rely on that. >>> >> >> I think it will take a 10bits signed value sign extend into 16bits >> signed value, and I've tested it with negative values, it working >> well. > > You cannot rely on the behaviour of a specific compiler implementation > as evidence that a piece of code is correct. C has a standard which > defines what is and is not valid. Indeed. The only portable way is val = ((val & (sign | (sign - 1))) ^ sign) - sign with all unsigned types, and "sign" set to the sign bit. > > Having said that, right shift of negative signed integers is one of > those bits of implementation defined behaviour which we allow ourselves > to rely on in QEMU because all the platforms we care about behave > that way. (That integers are 2s complement representation is another.) Also very true. I don't like seeing the code in question though. We've several implementations of sign-extend-to-N-bits functions throughout qemu; we ought to unify them. r~