On 11/28/25 2:58 AM, Kito Cheng wrote:
I know we're already in stage 3, so I'm basically asking for a review and am
fine with deferring this to GCC 17. But if it's acceptable for GCC 16, that
would be great too. :P
---
The previous reversed CRC implementation used explicit bit reflection
before and after the CRC computation:
reflect(crc_init);
reflect(data);
for (int i = 0; i < data_bit_size / 8; i++)
crc = (crc << 8) ^ table[(crc >> (crc_bit_size - 8))
^ (data >> (data_bit_size - (i+1) * 8) & 0xFF)];
reflect(crc);
This patch generates a reversed polynomial lookup table directly,
eliminating the need for bit reflection operations. The new algorithm:
for (int i = 0; i < data_bit_size / 8; i++)
crc = (crc >> 8) ^ table[(crc ^ (data >> (i * 8))) & 0xFF];
This improves code generation for all targets using table-based reversed
CRC, as it removes the overhead of reflecting input data and CRC values.
Ref:
[1] "Reversing CRC - Theory and Practice"
https://sar.informatik.hu-berlin.de/research/publications/SAR-PR-2006-05/SAR-PR-2006-05_.pdf
I'd suggest deferring to gcc-17.
Jeff