diff options
| author | Patrick Palka <ppalka@redhat.com> | 2024-02-13 14:26:48 -0500 |
|---|---|---|
| committer | Patrick Palka <ppalka@redhat.com> | 2024-02-13 14:26:48 -0500 |
| commit | 0eb9265fe737d901f484e4bcd73ffe386eb35693 (patch) | |
| tree | 3d03034cf4d3d884ec7bc8c6efd88ebd3f5764f7 /gcc/cp/module.cc | |
| parent | cb76d7e47693364861e63ea3bb274b1b5295a943 (diff) | |
| download | gcc-0eb9265fe737d901f484e4bcd73ffe386eb35693.zip gcc-0eb9265fe737d901f484e4bcd73ffe386eb35693.tar.gz gcc-0eb9265fe737d901f484e4bcd73ffe386eb35693.tar.bz2 | |
c++/modules: use optimized crc32 from zlib
The current implementation of bytes::calc_crc computes the checksum one
byte at a time which turns out to be quite slow, accounting for 15% of
streaming in time for a modular Hello World. We have a crc32_unsigned
version that processes 4 bytes at a time which we could use here, but
since we bundle zlib we might as well use its highly optimized crc
routines that can process up to 32 bytes at a time.
So this patch makes us use zlib's crc32 in this hot code path. This
reduces stream in time for a modular Hello World by around 15% for me
with a release compiler.
gcc/cp/ChangeLog:
* Make-lang.in (CFLAGS-cp/module.o): Add $(ZLIBINC).
* module.cc: Include <zlib.h>.
(bytes::calc_crc): Use crc32 from zlib.
(bytes_out::set_crc): Use crc32_combine from zlib.
Reviewed-by: Jason Merill <jason@redhat.com>
Diffstat (limited to 'gcc/cp/module.cc')
| -rw-r--r-- | gcc/cp/module.cc | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc index 34fafe7..0291d45 100644 --- a/gcc/cp/module.cc +++ b/gcc/cp/module.cc @@ -233,6 +233,7 @@ Classes used: /* This TU doesn't need or want to see the networking. */ #define CODY_NETWORKING 0 #include "mapper-client.h" +#include <zlib.h> // for crc32, crc32_combine #if 0 // 1 for testing no mmap #define MAPPED_READING 0 @@ -487,10 +488,7 @@ protected: unsigned bytes::calc_crc (unsigned l) const { - unsigned crc = 0; - for (size_t ix = 4; ix < l; ix++) - crc = crc32_byte (crc, buffer[ix]); - return crc; + return crc32 (0, (unsigned char *)buffer + 4, l - 4); } class elf_in; @@ -717,7 +715,7 @@ bytes_out::set_crc (unsigned *crc_ptr) unsigned crc = calc_crc (pos); unsigned accum = *crc_ptr; /* Only mix the existing *CRC_PTR if it is non-zero. */ - accum = accum ? crc32_unsigned (accum, crc) : crc; + accum = accum ? crc32_combine (accum, crc, pos - 4) : crc; *crc_ptr = accum; /* Buffer will be sufficiently aligned. */ |
