* [PATCH] make coff_compute_checksum faster
@ 2023-04-27 18:24 Oleg Tolmatcev
2023-05-03 14:39 ` Nick Clifton
0 siblings, 1 reply; 3+ messages in thread
From: Oleg Tolmatcev @ 2023-04-27 18:24 UTC (permalink / raw)
To: binutils
This makes linking faster by reading 8 MB of data at once instead of
reading 2 bytes at once. This drastically reduces the number of system
calls.
---
bfd/coffcode.h | 52 ++++++++++++++++++++++++++++++++++++++++++--------
1 file changed, 44 insertions(+), 8 deletions(-)
diff --git a/bfd/coffcode.h b/bfd/coffcode.h
index 19a5ce18..8118ff47 100644
--- a/bfd/coffcode.h
+++ b/bfd/coffcode.h
@@ -3361,30 +3361,66 @@ coff_read_word (bfd *abfd, unsigned int
*value, unsigned int *pelength)
return true;
}
+static bool
+coff_read_word_from_buffer (unsigned char *b, int buf_size,
+ unsigned int *value, unsigned int *pelength)
+{
+
+ if (buf_size < 1)
+ {
+ *value = 0;
+ return false;
+ }
+
+ if (buf_size == 1)
+ *value = (unsigned int)b[0];
+ else
+ *value = (unsigned int)(b[0] + (b[1] << 8));
+
+ *pelength += buf_size == 1 ? 1 : 2;
+
+ return true;
+}
+
static unsigned int
coff_compute_checksum (bfd *abfd, unsigned int *pelength)
{
- bool more_data;
file_ptr filepos;
unsigned int value;
unsigned int total;
+ unsigned char *buf;
+ unsigned char *cur_buf;
+ int buf_size;
+ int cur_buf_size;
total = 0;
*pelength = 0;
- filepos = (file_ptr) 0;
+ filepos = (file_ptr)0;
+ buf = (unsigned char *)bfd_malloc (0x800000);
+ if (buf == NULL)
+ return 0;
do
{
if (bfd_seek (abfd, filepos, SEEK_SET) != 0)
- return 0;
+ return 0;
- more_data = coff_read_word (abfd, &value, pelength);
- total += value;
- total = 0xffff & (total + (total >> 0x10));
- filepos += 2;
+ buf_size = bfd_bread (buf, 0x800000, abfd);
+ cur_buf_size = buf_size;
+ cur_buf = buf;
+ while (cur_buf_size > 0)
+ {
+ coff_read_word_from_buffer (cur_buf, cur_buf_size, &value, pelength);
+ cur_buf += 2;
+ cur_buf_size -= 2;
+ total += value;
+ total = 0xffff & (total + (total >> 0x10));
+ }
+ filepos += buf_size;
}
- while (more_data);
+ while (buf_size > 0);
+ free (buf);
return (0xffff & (total + (total >> 0x10)));
}
--
2.40.0.windows.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] make coff_compute_checksum faster
2023-04-27 18:24 [PATCH] make coff_compute_checksum faster Oleg Tolmatcev
@ 2023-05-03 14:39 ` Nick Clifton
2023-05-03 18:10 ` Oleg Tolmatcev
0 siblings, 1 reply; 3+ messages in thread
From: Nick Clifton @ 2023-05-03 14:39 UTC (permalink / raw)
To: Oleg Tolmatcev, binutils
Hi Oleg,
> This makes linking faster by reading 8 MB of data at once instead of
> reading 2 bytes at once. This drastically reduces the number of system
> calls.
Thanks very much. I have applied your patch with one small change:
> + buf = (unsigned char *)bfd_malloc (0x800000);
I replaced the use of a magic number in the malloc, and subsequent
read, with a #define'd value:
buf = (unsigned char *) bfd_malloc (COFF_CHECKSUM_BUFFER_SIZE);
It just makes it easier to change the buffer size, should that
become needed in the future.
Cheers
Nick
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] make coff_compute_checksum faster
2023-05-03 14:39 ` Nick Clifton
@ 2023-05-03 18:10 ` Oleg Tolmatcev
0 siblings, 0 replies; 3+ messages in thread
From: Oleg Tolmatcev @ 2023-05-03 18:10 UTC (permalink / raw)
To: Nick Clifton; +Cc: binutils
Am Mi., 3. Mai 2023 um 16:39 Uhr schrieb Nick Clifton <nickc@redhat.com>:
>
> Hi Oleg,
>
> > This makes linking faster by reading 8 MB of data at once instead of
> > reading 2 bytes at once. This drastically reduces the number of system
> > calls.
>
> Thanks very much. I have applied your patch with one small change:
>
> > + buf = (unsigned char *)bfd_malloc (0x800000);
>
> I replaced the use of a magic number in the malloc, and subsequent
> read, with a #define'd value:
>
> buf = (unsigned char *) bfd_malloc (COFF_CHECKSUM_BUFFER_SIZE);
>
> It just makes it easier to change the buffer size, should that
> become needed in the future.
>
> Cheers
> Nick
Thank you, Nick.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-05-03 18:10 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-27 18:24 [PATCH] make coff_compute_checksum faster Oleg Tolmatcev
2023-05-03 14:39 ` Nick Clifton
2023-05-03 18:10 ` Oleg Tolmatcev
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).