This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Clear upper bits during sign extension


> Yeah, that is better, or even we can left shift signbit by one.

Indeed!

> 2014-12-29  Yao Qi  <yao@codesourcery.com>
> 
>         * utils.c (gdb_sign_extend): Clear bits from BIT in VALUE.

Looks good to me.

> 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;
>      }

-- 
Joel


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]