From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53393) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WzReT-0006ub-2o for qemu-devel@nongnu.org; Tue, 24 Jun 2014 10:24:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WzReN-0008IL-2z for qemu-devel@nongnu.org; Tue, 24 Jun 2014 10:24:49 -0400 Received: from mail-qa0-x22e.google.com ([2607:f8b0:400d:c00::22e]:47570) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WzReM-0008IG-UF for qemu-devel@nongnu.org; Tue, 24 Jun 2014 10:24:42 -0400 Received: by mail-qa0-f46.google.com with SMTP id i13so291314qae.19 for ; Tue, 24 Jun 2014 07:24:42 -0700 (PDT) Sender: Richard Henderson Message-ID: <53A98A25.1030900@twiddle.net> Date: Tue, 24 Jun 2014 07:24:37 -0700 From: Richard Henderson MIME-Version: 1.0 References: <1402499992-64851-1-git-send-email-leon.alrae@imgtec.com> <1402499992-64851-15-git-send-email-leon.alrae@imgtec.com> <20140620205028.GB13921@ohm.rr44.fr> <53A949D5.3040805@imgtec.com> In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v2 14/22] target-mips: add Addressing and PC-relative instructions List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Peter Maydell , Leon Alrae Cc: yongbok.kim@imgtec.com, cristian.cuna@imgtec.com, QEMU Developers , Aurelien Jarno On 06/24/2014 03:00 AM, Peter Maydell wrote: > On 24 June 2014 10:50, Leon Alrae wrote: >> On 20/06/2014 21:50, Aurelien Jarno wrote: >>> I do wonder if we shouldn't use sextract32() instead of open coding that >>> now that it is available: >>> >>> offset = sextract32(ctx->opcode, 0, 19) << 3; >> >> This looks better, thanks for the suggestion (but since the offset's >> size is 18, third argument will be 18, not 19). > > This is undefined behaviour in C because of the shift into > the sign bit. Better to shift first and then signextend: > > offset = sextract32(ctx->opcode << 3, 0, 21); Not true. Because we know from the extract that the value has 13 copies of the sign bit. Shifting by 3 isn't going to cause problems. It's shifting a *different* bit into the sign position that's (one's compliment) undefined. r~ PS: Honestly, all these compilers/sanitizers should grow a "No One's Compliment" switch to disable all the stupid stuff.