Move crc32c_pad to util/crc32c.c

This commit is contained in:
Vitaliy Filippov
2025-08-10 18:03:17 +03:00
parent 4793dbe9c3
commit 1de53ef7e6
4 changed files with 30 additions and 31 deletions
+28
View File
@@ -372,3 +372,31 @@ uint32_t crc32c(uint32_t crc, const void *buf, size_t len)
return sse42 ? crc32c_hw(crc, buf, len) : crc32c_sw(crc, buf, len);
#endif
}
static uint8_t zero_page[4096] = {};
uint32_t crc32c_pad(uint32_t prev_crc, const void *buf, size_t len, size_t left_pad, size_t right_pad)
{
uint32_t r = prev_crc;
while (left_pad >= 4096)
{
r = crc32c(r, zero_page, 4096);
left_pad -= 4096;
}
if (left_pad > 0)
r = crc32c(r, zero_page, left_pad);
r = crc32c(r, buf, len);
while (right_pad >= 4096)
{
r = crc32c(r, zero_page, 4096);
right_pad -= 4096;
}
if (left_pad > 0)
r = crc32c(r, zero_page, right_pad);
return r;
}
uint32_t crc32c_nopad(uint32_t prev_crc, const void *buf, size_t len, size_t left_pad, size_t right_pad)
{
return crc32c(0, buf, len);
}
+2
View File
@@ -12,6 +12,8 @@
extern "C" {
#endif
uint32_t crc32c(uint32_t crc, const void *buf, size_t len);
uint32_t crc32c_pad(uint32_t prev_crc, const void *buf, size_t len, size_t left_pad, size_t right_pad);
uint32_t crc32c_nopad(uint32_t prev_crc, const void *buf, size_t len, size_t left_pad, size_t right_pad);
#ifdef __cplusplus
};
#endif