Trivial case in compile_time_utils.h
maths644311798 opened this issue · 3 comments
maths644311798 commented
compile_time_utils.h中有代码
template <>
constexpr uint32_t crc32<static_cast<size_t>(-1)>(
[[maybe_unused]] const char* str) {
return 0xFFFFFFFF;
}
这个特殊情况对应零多项式,应该返回0吧。
Jamie-Cui commented
可以参考一下这个逻辑,和 yacl 里面的 crc32 recursion 逻辑正好相反
https://web.mit.edu/freebsd/head/sys/libkern/crc32.c
/*
* A function that calculates the CRC-32 based on the table above is
* given below for documentation purposes. An equivalent implementation
* of this function that's actually used in the kernel can be found
* in sys/libkern.h, where it can be inlined.
*
* uint32_t
* crc32(const void *buf, size_t size)
* {
* const uint8_t *p = buf;
* uint32_t crc;
*
* crc = ~0U; /* 初始化为 0xFFFFFFFF */
* while (size--)
* crc = crc32_tab[(crc ^ *p++) & 0xFF] ^ (crc >> 8);
* return crc ^ ~0U;
* }
*/
maths644311798 commented
我承认Yacl的实现和 https://web.mit.edu/freebsd/head/sys/libkern/crc32.c 有相同功能。但是
char c[2] = { 0x0,0x00 };
cout << hex << CT_CRC32(c) << '\n';
这段代码会输出 d202ef8d,如何解释?对于零多项式,按照CRC32算法预期应该输出0。
maths644311798 commented
明白了,我看了IEEE 802.3标准,确实首尾有取反操作。