From patchwork Mon Dec 29 03:37:46 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yao Qi X-Patchwork-Id: 4448 Received: (qmail 12649 invoked by alias); 29 Dec 2014 03:38:13 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 12626 invoked by uid 89); 29 Dec 2014 03:38:10 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.7 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 X-HELO: relay1.mentorg.com Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 29 Dec 2014 03:38:07 +0000 Received: from svr-orw-fem-02x.mgc.mentorg.com ([147.34.96.206] helo=SVR-ORW-FEM-02.mgc.mentorg.com) by relay1.mentorg.com with esmtp id 1Y5R9f-0004UZ-2l from Yao_Qi@mentor.com ; Sun, 28 Dec 2014 19:38:03 -0800 Received: from GreenOnly (147.34.91.1) by svr-orw-fem-02.mgc.mentorg.com (147.34.96.168) with Microsoft SMTP Server id 14.3.224.2; Sun, 28 Dec 2014 19:38:02 -0800 From: Yao Qi To: Joel Brobecker CC: Subject: Re: [PATCH] Clear upper bits during sign extension References: <1419815569-21854-1-git-send-email-yao@codesourcery.com> <20141229030659.GB2123@adacore.com> Date: Mon, 29 Dec 2014 11:37:46 +0800 In-Reply-To: <20141229030659.GB2123@adacore.com> (Joel Brobecker's message of "Mon, 29 Dec 2014 07:06:59 +0400") Message-ID: <87d273w2gl.fsf@codesourcery.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) MIME-Version: 1.0 X-IsSubscribed: yes Joel Brobecker writes: > I think you can simplify the above with just: > > value &= ((LONGEST) 1 << bit) - 1; > > ? I don't know if the cast to LONGEST is really necessary, but we use > it for signbit, so I did the same for the mask... Yeah, that is better, or even we can left shift signbit by one. diff --git a/gdb/utils.c b/gdb/utils.c index 47adb67..61873f7 100644 --- a/gdb/utils.c +++ b/gdb/utils.c @@ -3032,6 +3032,9 @@ gdb_sign_extend (LONGEST value, int bit) { LONGEST signbit = ((LONGEST) 1) << (bit - 1); + /* Clear upper bits from bit BIT. */ + value &= (signbit << 1) - 1; + value = (value ^ signbit) - signbit; }