Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: "Rohr, Stephan" <stephan.rohr@intel.com>
To: Robert Dubner <rdubner@symas.com>,
	"gdb-patches@sourceware.org" <gdb-patches@sourceware.org>
Subject: RE: [PATCH] gdb: Preserve neighboring bits when writing floating-point fields
Date: Thu, 5 Nov 2026 12:48:20 +0000	[thread overview]
Message-ID: <IA3PR11MB4446329F78DAE1E127663DFB5493772@IA3PR11MB444632.namprd11.prod.outlook.com> (raw)
In-Reply-To: <039301dd6bc2$8fbb09d0$af311d70$@symas.com>

Hi Robert,

thanks for the patch.

I think the implementation and the commit message looks good now.

It would be nice to add a test for this.  I'd suggest adding a unit-test
in target-float.c.

Please format the patches such that they can be correctly applied:

git format-patch -v2 --cover-letter --base=auto -o <out dir>

Then, use git send-email to send:

git send-email --suppress-cc=all --confirm=always --validate \
  --to=gdb-patches@sourceware.org --cc=.. <dir>

Thanks
Stephan

> -----Original Message-----
> From: Robert Dubner <rdubner@symas.com>
> Sent: Tuesday, 3 November 2026 19:39
> To: gdb-patches@sourceware.org
> Cc: Rohr, Stephan <stephan.rohr@intel.com>
> Subject: [PATCH] gdb: Preserve neighboring bits when writing floating-point
> fields
> 
> From 2c1ada5e34da71f2575d7857ae78db559a972126 Mon Sep 17
> 00:00:00 2001
> From: Robert Dubner <rdubner@symas.com>
> Date: Tue, 3 Nov 2026 13:12:57 -0500
> Subject: [PATCH] gdb: Preserve neighboring bits when writing
> floating-point
>  fields
> 
> put_field can clear bits outside the requested field when the field
> fits within part of a byte.  For IEEE binary16, writing the exponent
> can clear the adjacent sign bit, turning a negative value positive.
> 
> Limit both clearing and setting to the requested field width.  Derive
> the mask from cur_bitshift so it accounts for the little-endian
> adjustment for formats whose total size is not a multiple of eight bits.
> 
> Also correct the function comment to describe lengths in bits and
> storing into the buffer, and document that STUFF_TO_PUT must fit in
> LEN bits.
> 
> With a volatile _Float16 variable f16, before this change:
> 
>   (gdb) set var f16 = -1.5
>   (gdb) print f16
>   $1 = 1.5
> 
> After this change:
> 
>   (gdb) set var f16 = -1.5
>   (gdb) print f16
>   $1 = -1.5
> 
> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=34927
> ---
>  gdb/target-float.c | 15 ++++++++-------
>  1 file changed, 8 insertions(+), 7 deletions(-)
> 
> diff --git a/gdb/target-float.c b/gdb/target-float.c
> index b278295138e..bf86a158fa0 100644
> --- a/gdb/target-float.c
> +++ b/gdb/target-float.c
> @@ -229,8 +229,9 @@ get_field (const bfd_byte *data, enum
> floatformat_byteorders order,
>    return result;
>  }
> 
> -/* Set a field which starts at START and is LEN bytes long.  DATA and
> -   TOTAL_LEN are the thing we are extracting it from, in byteorder ORDER.
> */
> +/* Set a field which starts at START and is LEN bits long.  DATA is the
> +   buffer we are storing into, with TOTAL_LEN bits in byteorder ORDER.
> +   STUFF_TO_PUT must fit in LEN bits.  */
>  static void
>  put_field (unsigned char *data, enum floatformat_byteorders order,
>  	   unsigned int total_len, unsigned int start, unsigned int len,
> @@ -260,11 +261,11 @@ put_field (unsigned char *data, enum
> floatformat_byteorders order,
>      }
>    if (cur_bitshift > -FLOATFORMAT_CHAR_BIT)
>      {
> -      *(data + cur_byte) &=
> -	~(((1 << ((start + len) % FLOATFORMAT_CHAR_BIT)) - 1)
> -	  << (-cur_bitshift));
> -      *(data + cur_byte) |=
> -	(stuff_to_put & ((1 << FLOATFORMAT_CHAR_BIT) - 1)) <<
> (-cur_bitshift);
> +      unsigned int bits
> +	= std::min (len, (unsigned int) (FLOATFORMAT_CHAR_BIT +
> cur_bitshift));
> +      unsigned int mask = ((1 << bits) - 1) << (-cur_bitshift);
> +      *(data + cur_byte) &= ~mask;
> +      *(data + cur_byte) |= (stuff_to_put << (-cur_bitshift)) & mask;
>      }
>    cur_bitshift += FLOATFORMAT_CHAR_BIT;
>    if (order == floatformat_little)
> --
> 2.34.1

________________________________________
Intel Deutschland GmbH 

Registered Address: Dornacher Strasse 1, 85622 Feldkirchen, Germany 

Tel: +49 (89) 99143-0 

www.intel.de 

Managing Directors: Candice Moore, Jeffrey Schneiderman, Ramachandran Sitaraman

Chairperson of the Supervisory Board: Sonja Pierer

Registered Seat: Munich Commercial Register B: Amtsgericht Munich HRB 186928

This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.

      reply	other threads:[~2026-11-05 12:48 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-03 18:38 Robert Dubner
2026-11-05 12:48 ` Rohr, Stephan [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=IA3PR11MB4446329F78DAE1E127663DFB5493772@IA3PR11MB444632.namprd11.prod.outlook.com \
    --to=stephan.rohr@intel.com \
    --cc=gdb-patches@sourceware.org \
    --cc=rdubner@symas.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox