This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [PATCH] Clear upper bits during sign extension
- From: Yao Qi <yao at codesourcery dot com>
- To: Joel Brobecker <brobecker at adacore dot com>
- Cc: <gdb-patches at sourceware dot org>
- Date: Mon, 29 Dec 2014 11:37:46 +0800
- Subject: Re: [PATCH] Clear upper bits during sign extension
- Authentication-results: sourceware.org; auth=none
- References: <1419815569-21854-1-git-send-email-yao at codesourcery dot com> <20141229030659 dot GB2123 at adacore dot com>
Joel Brobecker <brobecker@adacore.com> 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.
--
Yao (éå)
gdb:
2014-12-29 Yao Qi <yao@codesourcery.com>
* utils.c (gdb_sign_extend): Clear bits from BIT in VALUE.
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;
}