>
How about adding something like this to modules/crc:
Done
> People using the crc module who want to disable the faster/larger CRC32
> implementation can add 'gl_crc_slice_by_8=yes' to their
configure.ac> before invoking gnulib.
I've been running tests with `./gnulib-tool --with-tests --test crc` so I'm interested in a way of enabling this flag from gnulib-tool
> I still think we should check larger alignment mismatches in the test
> case, it doesn't hurt to test wildly larger mis-alignment for surprising
> behaviour.
I'm not against the idea, I just want to know what error we are detecting with these tests. The largest word we're working with is 64-bits long, and I know some CPUs will fault when these are read from a memory address that isn't 64-bit aligned, but I'm not aware of this happening on other boundaries. If we imagine CPU x that only allows you to read the first 64-bit word of every 65536bits then it would be impossible to natively address an array of uint64_t, for example. I feel it's safe to assume that if we test every alignment from 0-7 (or 0-15 to handle a potential pclmul implementation that reads 128-bit words at a time) then we will catch any alignment issues.
I do believe that unit tests need to be "as simple as possible, but no simpler"; each unit test should be solving one problem well.
> You need to add license terms (GPLv3+?) and follow GNU coding style
Done
> If code is copied then licensing terms has to be clear. RFCs have bad licensing terms, so maybe we cannot use this code at all.
The existing lib/crc.c uses code directly taken from RFC 1952 and is referenced as such, I sent off my copyright paperwork and mentioned this to them and am awaiting a reply.
> That memcpy looks weird, does it really do what you want it to do on all
> architectures? Would using something from endian.h be cleaner?
The purpose is to work around alignment issues. The signature for crc32_update_no_xor() takes a char* and casting up to a uint64_t is undefined by C. Using memcpy lets the compiler and runtime be smart and insulates us from nonaligned memory accesses. I am open to other ideas around this (we can step forward byte by byte until we reach an aligned pointer and then do 8-byte blocks from there, for example, but then we need to detect alignment and do the upcasting ourselves)
You are correct that this breaks under big endian though, thanks for the tip for endian.h. I've added a le64toh() call and this should make it work correctly on big endian systems (how do we go about testing these btw? I don't have one on me).