From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42886) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VDAyO-0007N2-77 for qemu-devel@nongnu.org; Sat, 24 Aug 2013 06:21:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VDAyJ-0000ox-51 for qemu-devel@nongnu.org; Sat, 24 Aug 2013 06:21:36 -0400 Received: from mail-la0-f48.google.com ([209.85.215.48]:58482) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VDAyI-0000oc-Tb for qemu-devel@nongnu.org; Sat, 24 Aug 2013 06:21:31 -0400 Received: by mail-la0-f48.google.com with SMTP id er20so1150355lab.7 for ; Sat, 24 Aug 2013 03:21:29 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <5217A54A.6040300@twiddle.net> References: <1377274359-8707-1-git-send-email-peter.maydell@linaro.org> <1377274359-8707-2-git-send-email-peter.maydell@linaro.org> <5217A54A.6040300@twiddle.net> From: Peter Maydell Date: Sat, 24 Aug 2013 11:21:09 +0100 Message-ID: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH 1/2] target-arm: Use sextract32() in branch decode List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Richard Henderson Cc: QEMU Developers , Patch Tracking On 23 August 2013 19:09, Richard Henderson wrote: > On 08/23/2013 09:12 AM, Peter Maydell wrote: >> - offset =3D (((int32_t)insn << 8) >> 8); >> - val +=3D (offset << 2) + 4; >> + offset =3D sextract32(insn << 2, 0, 26); >> + val +=3D offset + 4; > > I read this incorrectly at first, considering the shift of insn, and > I wonder if it's really the best way to write this because of that. > > What about just changing the one line to sextract(insn, 0, 24)? > > The second line by itself ought not trigger a warning from clang, > because the << 2 never changes the sign bit. If it still does, > perhaps just multiply by 4 instead... No, left shift of a negative value is undefined: "If E1 has a signed type and nonnegative value, and E1 =C3=97 2E2 is representable in the result type, then that is the resulting value; otherwise, the behavior is undefined." Also the ARM ARM pseudocode defines this operation as "first append two zero bits and then sign extend" so I prefer it if we actually implement it that way round. > It's a stupid warning. When was the last ones-compliment machine built? The stupidity is that the C standard hasn't mandated 2s-complement. -- PMM