Optimize byte-aligned copies in copy_bitwise()
authorAndreas Arnez <arnez@linux.vnet.ibm.com>
Thu, 24 Nov 2016 16:48:04 +0000 (17:48 +0100)
committerAndreas Arnez <arnez@linux.vnet.ibm.com>
Thu, 24 Nov 2016 16:48:04 +0000 (17:48 +0100)
The function copy_bitwise used for copying DWARF pieces can potentially
be invoked for large chunks of data.  For instance, consider a large
struct one of whose members is currently located in a register.  In this
case copy_bitwise would still copy the data bitwise in a loop, which is
much slower than necessary.

This change uses memcpy for the large part instead, if possible.

gdb/ChangeLog:

* dwarf2loc.c (copy_bitwise): Use memcpy for the middle part, if
it is byte-aligned.

gdb/ChangeLog
gdb/dwarf2loc.c

index d667a3748195d7a870b6ef511b2b4938e8880e94..51787adf019c10babbc848b08da5e7d828644fa8 100644 (file)
@@ -1,3 +1,8 @@
+2016-11-24  Andreas Arnez  <arnez@linux.vnet.ibm.com>
+
+       * dwarf2loc.c (copy_bitwise): Use memcpy for the middle part, if
+       it is byte-aligned.
+
 2016-11-24  Andreas Arnez  <arnez@linux.vnet.ibm.com>
            Pedro Alves  <palves@redhat.com>
 
index 61f197b27982c8ab8981ed85829557228480e778..128f65468b8794463d260fc4e7b9ac1e188fd806 100644 (file)
@@ -1548,11 +1548,30 @@ copy_bitwise (gdb_byte *dest, ULONGEST dest_offset,
     {
       size_t len = nbits / 8;
 
-      while (len--)
+      /* Use a faster method for byte-aligned copies.  */
+      if (avail == 0)
        {
-         buf |= *(bits_big_endian ? source-- : source++) << avail;
-         *(bits_big_endian ? dest-- : dest++) = buf;
-         buf >>= 8;
+         if (bits_big_endian)
+           {
+             dest -= len;
+             source -= len;
+             memcpy (dest + 1, source + 1, len);
+           }
+         else
+           {
+             memcpy (dest, source, len);
+             dest += len;
+             source += len;
+           }
+       }
+      else
+       {
+         while (len--)
+           {
+             buf |= *(bits_big_endian ? source-- : source++) << avail;
+             *(bits_big_endian ? dest-- : dest++) = buf;
+             buf >>= 8;
+           }
        }
       nbits %= 8;
     }
This page took 0.031083 seconds and 4 git commands to generate.