Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Andreas Arnez <arnez@linux.vnet.ibm.com>
To: gdb-patches@sourceware.org
Subject: Re: [PATCH 2/3] Fix copy_bitwise()
Date: Tue, 15 Nov 2016 18:58:00 -0000	[thread overview]
Message-ID: <m3wpg4vadt.fsf@oc1027705133.ibm.com> (raw)
In-Reply-To: <1479135786-31150-3-git-send-email-arnez@linux.vnet.ibm.com>	(Andreas Arnez's message of "Mon, 14 Nov 2016 16:02:25 +0100")

[-- Attachment #1: Type: text/plain, Size: 288 bytes --]

On Mon, Nov 14 2016, Andreas Arnez wrote:

[...]

> diff --git a/gdb/dwarf2loc.c b/gdb/dwarf2loc.c
> index 93aec1f..3a241a8 100644
> --- a/gdb/dwarf2loc.c
> +++ b/gdb/dwarf2loc.c

[...]

For reference, since the patch itself might be a bit clumsy to read,
here's the resulting function:


[-- Attachment #2: copy_bitwise.c --]
[-- Type: text/plain, Size: 1870 bytes --]

/* Copy NBITS bits from SOURCE to DEST starting at the given bit
   offsets.  Use the bit order as specified by BITS_BIG_ENDIAN.
   Source and destination buffers must not overlap.  */

static void
copy_bitwise (gdb_byte *dest, ULONGEST dest_offset,
	      const gdb_byte *source, ULONGEST source_offset,
	      ULONGEST nbits, int bits_big_endian)
{
  unsigned int buf, avail;

  if (nbits == 0)
    return;

  if (bits_big_endian)
    {
      /* Start from the end, then work backwards.  */
      dest_offset += nbits - 1;
      dest += dest_offset / 8;
      dest_offset = 7 - dest_offset % 8;
      source_offset += nbits - 1;
      source += source_offset / 8;
      source_offset = 7 - source_offset % 8;
    }
  else
    {
      dest += dest_offset / 8;
      dest_offset %= 8;
      source += source_offset / 8;
      source_offset %= 8;
    }

  /* Fill BUF with DEST_OFFSET bits from the destination and 8 -
     SOURCE_OFFSET bits from the source.  */
  buf = *(bits_big_endian ? source-- : source++) >> source_offset;
  buf <<= dest_offset;
  buf |= *dest & ((1 << dest_offset) - 1);

  /* NBITS: bits yet to be written; AVAIL: BUF's fill level.  */
  nbits += dest_offset;
  avail = dest_offset + 8 - source_offset;

  /* Flush 8 bits from BUF, if appropriate.  */
  if (nbits >= 8 && avail >= 8)
    {
      *(bits_big_endian ? dest-- : dest++) = buf;
      buf >>= 8;
      avail -= 8;
      nbits -= 8;
    }

  /* Copy the middle part.  */
  if (nbits >= 8)
    {
      size_t len = nbits / 8;

      while (len--)
	{
	  buf |= *(bits_big_endian ? source-- : source++) << avail;
	  *(bits_big_endian ? dest-- : dest++) = buf;
	  buf >>= 8;
	}
      nbits %= 8;
    }

  /* Write the last byte.  */
  if (nbits)
    {
      if (avail < nbits)
	buf |= *source << avail;

      buf &= (1 << nbits) - 1;
      *dest = (*dest & (~0 << nbits)) | buf;
    }
}

  parent reply	other threads:[~2016-11-15 18:58 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-14 15:03 [PATCH 0/3] Support DW_AT_data_bit_offset Andreas Arnez
2016-11-14 15:04 ` [PATCH 1/3] Fix PR12616 - gdb does not implement DW_AT_data_bit_offset Andreas Arnez
2016-11-14 15:38   ` Luis Machado
2016-11-14 15:04 ` [PATCH 2/3] Fix copy_bitwise() Andreas Arnez
2016-11-14 15:38   ` Luis Machado
2016-11-14 17:54     ` Andreas Arnez
2016-11-14 17:58       ` Luis Machado
2016-11-15 18:58   ` Andreas Arnez [this message]
2016-11-15 19:42   ` Pedro Alves
2016-11-17 19:36     ` Andreas Arnez
2016-11-17 20:30       ` Pedro Alves
2016-11-18 15:06         ` Andreas Arnez
2016-11-22 23:18           ` Pedro Alves
2016-11-24 16:15             ` Andreas Arnez
2016-11-24 16:32               ` Pedro Alves
2016-11-24 16:55                 ` Andreas Arnez
2016-11-14 15:05 ` [PATCH 3/3] Optimize byte-aligned copies in copy_bitwise() Andreas Arnez
2016-11-14 15:38   ` Luis Machado

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=m3wpg4vadt.fsf@oc1027705133.ibm.com \
    --to=arnez@linux.vnet.ibm.com \
    --cc=gdb-patches@sourceware.org \
    /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