From 357a8b7f3548a6e8438bece3881e4c47e9f1b7e5 Mon Sep 17 00:00:00 2001 From: Keno Fischer Date: Tue, 2 Aug 2022 20:33:16 +0000 Subject: [PATCH] Fix checksumming in the presence of large, mostly-zero buffers. Tools like asan allocate large regions of memory (multi-TB) that are generally sparsely allocated using demand-paging. Currently, when checksumming a process that has such regions, we attempt to read the entire multi-TB region into a std::vector. This obviously does not work. Switch our checksum method to crc32c for performance and further improve performance by: 1. Reading the pagemap to detect pages that were allocated, but are currently still 0 and waiting to demand-paged in. These can be fast-forwarded using a precomputed crc operator. 2. Capping the amount of memory to be read at once at a reasonable max buffer size to avoid thrashing. The crc32c implementation here is copied from Julia, which itself is cobbled together from various places around the web - it's not the prettiest, but keeping it aligned with the Julia version will make it easier to port any future hardware acceleration improvements over, if necessary. --- CMakeLists.txt | 3 + src/test/checksum_huge_mmap.c | 34 ++ src/test/checksum_huge_mmap.run | 25 ++ src/util.cc | 140 +++++-- third-party/crc32c/crc32c-tables.c | 52 +++ third-party/crc32c/crc32c.c | 597 +++++++++++++++++++++++++++++ third-party/crc32c/crc32c.h | 25 ++ 7 files changed, 850 insertions(+), 26 deletions(-) create mode 100644 src/test/checksum_huge_mmap.c create mode 100644 src/test/checksum_huge_mmap.run create mode 100644 third-party/crc32c/crc32c-tables.c create mode 100644 third-party/crc32c/crc32c.c create mode 100644 third-party/crc32c/crc32c.h diff --git a/CMakeLists.txt b/CMakeLists.txt index edc12149885..58561940b99 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -384,6 +384,7 @@ endif() include_directories("${PROJECT_SOURCE_DIR}/include") include_directories("${PROJECT_SOURCE_DIR}/third-party/proc-service") include_directories("${PROJECT_SOURCE_DIR}/third-party/brotli/include") +include_directories("${PROJECT_SOURCE_DIR}/third-party/crc32c") # We need to know where our generated files are. include_directories("${CMAKE_CURRENT_BINARY_DIR}") @@ -588,6 +589,7 @@ set(RR_SOURCES src/WaitStatus.cc ${CMAKE_CURRENT_BINARY_DIR}/rr_trace.capnp.c++ ${BLAKE_ARCH_DIR}/blake2b.c + third-party/crc32c/crc32c.c ) if(PROC_SERVICE_H) @@ -1343,6 +1345,7 @@ set(TESTS_WITH_PROGRAM checkpoint_dying_threads checkpoint_mixed_mode checksum_sanity + checksum_huge_mmap check_lost_interrupts clone_interruption # Disabled because it fails diff --git a/src/test/checksum_huge_mmap.c b/src/test/checksum_huge_mmap.c new file mode 100644 index 00000000000..fa78ca87a98 --- /dev/null +++ b/src/test/checksum_huge_mmap.c @@ -0,0 +1,34 @@ +/* -*- Mode: C; tab-width: 8; c-basic-offset: 2; indent-tabs-mode: nil; -*- */ + +#include "util.h" + +#if defined(__aarch64__) || defined(__x86_64__) +#define HUGE_MMAP_SIZE 1ULL*1024ULL*1024ULL*1024ULL*1024ULL // 1 TiB +#else +#define HUGE_MMAP_SIZE 2ULL*1024ULL*1024ULL*1024ULL // 2 GiB +#endif + +int main(__attribute__((unused)) int argc, __attribute__((unused)) char** argv) { + pid_t pid = getpid(); + char *huge_map = mmap(NULL, HUGE_MMAP_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE, -1, 0); + if (!huge_map) { + atomic_printf("The kernel refused our huge allocation. A ulimit over memory overcommit restriction may be in place. Skipping test."); + atomic_puts("EXIT-SUCCESS"); + return 77; + } + + atomic_printf("Info: %d %p\n", pid, huge_map); + + // Touch the first and the last page and print in between to make sure that a checksum happens. + *(int*)huge_map = 1; + *(int*)(huge_map + HUGE_MMAP_SIZE - 1024) = 1; + atomic_puts("Test 1"); + + // Reset to zero, but the page no longer is a paged-out, demand page. + *(int*)huge_map = 0; + *(int*)(huge_map + HUGE_MMAP_SIZE - 1024) = 0; + atomic_puts("Test 2"); + + atomic_puts("EXIT-SUCCESS"); + return 0; +} \ No newline at end of file diff --git a/src/test/checksum_huge_mmap.run b/src/test/checksum_huge_mmap.run new file mode 100644 index 00000000000..115c7e0993f --- /dev/null +++ b/src/test/checksum_huge_mmap.run @@ -0,0 +1,25 @@ +source `dirname $0`/util.sh +GLOBAL_OPTIONS="$GLOBAL_OPTIONS --checksum=on-all-events -M" + +record $TESTNAME + +TARGET_PID=$(grep 'Info: ' record.out | awk '{print $4}') +TARGET_MAP=$(grep 'Info: ' record.out | awk '{print $5}') +TARGET_EVENT1=$(grep 'Info: ' record.out | tr ']' ' ' | awk '{print $3}') +TARGET_EVENT2=$(grep 'Test 1' record.out | tr ']' ' ' | awk '{print $3}') +TARGET_EVENT3=$(grep 'Test 2' record.out | tr ']' ' ' | awk '{print $3}') + +CHKSUM1=$(grep $TARGET_MAP $workdir/latest-trace/$(($TARGET_EVENT1+1))_$TARGET_PID | cut -d ' ' -f1) +CHKSUM2=$(grep $TARGET_MAP $workdir/latest-trace/$(($TARGET_EVENT2+1))_$TARGET_PID | cut -d ' ' -f1) +CHKSUM3=$(grep $TARGET_MAP $workdir/latest-trace/$(($TARGET_EVENT3+1))_$TARGET_PID | cut -d ' ' -f1) + +if [[ $CHKSUM1 == $CHKSUM2 ]]; then + failed "Expected modification to affect checksum" +fi + +if [[ $CHKSUM1 != $CHKSUM3 ]]; then + failed "Expected checksums to match" +fi + +replay +check EXIT-SUCCESS \ No newline at end of file diff --git a/src/util.cc b/src/util.cc index 307953bdc2a..e8acf1c2759 100644 --- a/src/util.cc +++ b/src/util.cc @@ -49,6 +49,8 @@ #include "log.h" #include "seccomp-bpf.h" +#include "crc32c.h" + void good_random(uint8_t* out, size_t out_len); using namespace std; @@ -391,14 +393,111 @@ static bool checksum_segment_filter(const AddressSpace::Mapping& m) { return may_diverge; } -static uint32_t compute_checksum(void* data, size_t len) { - uint32_t checksum = len; - size_t words = len / sizeof(uint32_t); - uint32_t* buf = static_cast(data); - for (size_t i = 0; i < words; ++i) { - checksum = (checksum << 4) + checksum + buf[i]; +static void read_bytes_for_crc(std::vector &buf, Task *t, uintptr_t addr, size_t len) +{ + if (buf.size() < len) { + buf.resize(len); + } + memset(buf.data(), 0, len); + /* Areas not read are left as zero. We have to do this because + mappings not backed by valid file data are not readable during + recording but are read as 0 during replay */ + ssize_t valid_mem_len = + t->read_bytes_fallible(addr, len, buf.data()); + if (valid_mem_len < 0) { + /* It is possible for whole mappings to be beyond the extent of the + * backing file, in which case read_bytes_fallible will return -1. + */ + ASSERT(t, valid_mem_len == -1 && errno == EIO); + } +} + +#define NBYTES1M 1024ULL*1024ULL +#define NBYTES1G NBYTES1M*1024ULL +#define NBYTES1T NBYTES1G*1024ULL +static inline uint32_t accum_zero_bytes(uint32_t crc, size_t nbytes) { + if (nbytes == 0) return crc; + crc = crc ^ 0xffffffff; + while (nbytes >= NBYTES1T) { + crc = crc32c_shift(crc32c_1T, crc); + nbytes -= NBYTES1T; + } + while (nbytes >= NBYTES1G) { + crc = crc32c_shift(crc32c_1G, crc); + nbytes -= NBYTES1G; + } + while (nbytes >= NBYTES1M) { + crc = crc32c_shift(crc32c_1M, crc); + nbytes -= NBYTES1M; + } + while (nbytes && nbytes > 0) { + crc = crc32c_shift(crc32c_4k, crc); + nbytes -= 4096; + } + assert(nbytes == 0); + return crc ^ 0xffffffff; +} + +#define MAXBUF 256*1024*1024 // 256MiB +#define NPAGES ((uint32_t)1) << 17 // The number of 4k pages in 256MiB +static uint32_t compute_checksum_streaming(Task *t, ScopedFd &pagemap_fd, + uintptr_t pg_start, size_t len) +{ + uint64_t pagemap[NPAGES]; + ssize_t pagesize = sysconf(_SC_PAGESIZE); + size_t maxbufpages = MAXBUF / pagesize; + uint32_t crc = len; + uintptr_t off = 0; + std::vector buf; + size_t non_zero_pages = 0; + size_t zero_pages = 0; + while (off < len) { + size_t pages_to_read = std::min((len - off) / pagesize, (size_t)NPAGES); + if (!pages_to_read) + break; + size_t pagemap_size = pages_to_read * sizeof(pagemap[0]); + size_t npagemap_read = pread64(pagemap_fd, pagemap, pagemap_size, + ((pg_start + off) / pagesize) * sizeof(pagemap[0])); + ASSERT(t, pagemap_size == npagemap_read); + size_t i = 0; + while (i < pages_to_read) { + while (i < pages_to_read && non_zero_pages < maxbufpages) { + uint64_t pm = pagemap[i]; + bool is_zero_page = pm == 0x80000000000000; + if (!is_zero_page) { + crc = accum_zero_bytes(crc, zero_pages * pagesize); + zero_pages = 0; + non_zero_pages++; + i += 1; + continue; + } + break; + } + if (non_zero_pages > 0) { + size_t non_zero_size = non_zero_pages * pagesize; + if (non_zero_size > buf.size()) { + buf.resize(non_zero_size); + } + read_bytes_for_crc(buf, t, pg_start + off, non_zero_size); + crc = crc32c(crc, (uint8_t*)buf.data(), non_zero_size); + non_zero_pages = 0; + off += non_zero_size; + } + if (i < pages_to_read) { + zero_pages += 1; + off += pagesize; + i += 1; + } + } } - return checksum; + crc = accum_zero_bytes(crc, zero_pages * pagesize); + if (len > off) { + // Read any trailing non-page-aligned bytes. + size_t bytes_to_read = len - off; + read_bytes_for_crc(buf, t, pg_start + off, bytes_to_read); + crc = crc32c(crc, buf.data(), bytes_to_read); + } + return crc; } static const uint32_t ignored_checksum = 0x98765432; @@ -477,6 +576,9 @@ static void iterate_checksums(Task* t, ChecksumMode mode, } auto checksum_iter = checksums.begin(); + char pagemap_path[PATH_MAX]; + sprintf(pagemap_path, "/proc/%d/pagemap", t->tid); + ScopedFd pagemap_fd(pagemap_path, O_RDONLY); for (auto it = as.maps().begin(); it != as.maps().end(); ++it) { AddressSpace::Mapping m = *it; string raw_map_line = m.map.str(); @@ -511,7 +613,7 @@ static void iterate_checksums(Task* t, ChecksumMode mode, continue; } if (parsed.checksum == ignored_checksum) { - LOG(debug) << "Checksum not computed during recording"; + LOG(debug) << "Checksum not computed during recording at " << parsed.start; continue; } else if (parsed.checksum == sigbus_checksum) { continue; @@ -526,21 +628,7 @@ static void iterate_checksums(Task* t, ChecksumMode mode, } } - vector mem; - mem.resize(m.map.size()); - memset(mem.data(), 0, mem.size()); - ssize_t valid_mem_len = - t->read_bytes_fallible(m.map.start(), mem.size(), mem.data()); - /* Areas not read are treated as zero. We have to do this because - mappings not backed by valid file data are not readable during - recording but are read as 0 during replay. */ - if (valid_mem_len < 0) { - /* It is possible for whole mappings to be beyond the extent of the - * backing file, in which case read_bytes_fallible will return -1. - */ - ASSERT(t, valid_mem_len == -1 && errno == EIO); - } - + size_t map_size = m.map.size(); if (m.flags & AddressSpace::Mapping::IS_SYSCALLBUF) { /* The syscallbuf consists of a region that's written * deterministically wrt the trace events, and a @@ -556,11 +644,11 @@ static void iterate_checksums(Task* t, ChecksumMode mode, * the deterministic region. */ auto child_hdr = m.map.start().cast(); auto hdr = t->read_mem(child_hdr); - mem.resize(sizeof(hdr) + hdr.num_rec_bytes + - sizeof(struct syscallbuf_record)); + map_size = sizeof(hdr) + hdr.num_rec_bytes + + sizeof(struct syscallbuf_record); } - uint32_t checksum = compute_checksum(mem.data(), mem.size()); + uint32_t checksum = compute_checksum_streaming(t, pagemap_fd, m.map.start().as_int(), map_size); if (STORE_CHECKSUMS == mode) { fprintf(c.checksums_file, "(%x) %s\n", checksum, raw_map_line.c_str()); diff --git a/third-party/crc32c/crc32c-tables.c b/third-party/crc32c/crc32c-tables.c new file mode 100644 index 00000000000..91cbe566d7b --- /dev/null +++ b/third-party/crc32c/crc32c-tables.c @@ -0,0 +1,52 @@ +/* Pregenerated tables for crc32c.c, produced by compiling with -DGEN_CRC32C_TABLES. */ +#if POLY != 0x82f63b78 +# error "tables generated for different polynomial" +#endif + +const uint32_t crc32c_table[8][256] = { + { 0,4067132163,3778769143,324072436,3348797215,904991772,648144872,3570033899,2329499855,2024987596,1809983544,2575936315,1296289744,3207089363,2893594407,1578318884,274646895,3795141740,4049975192,51262619,3619967088,632279923,922689671,3298075524,2592579488,1760304291,2075979607,2312596564,1562183871,2943781820,3156637768,1313733451,549293790,3537243613,3246849577,871202090,3878099393,357341890,102525238,4101499445,2858735121,1477399826,1264559846,3107202533,1845379342,2677391885,2361733625,2125378298,820201905,3263744690,3520608582,598981189,4151959214,85089709,373468761,3827903834,3124367742,1213305469,1526817161,2842354314,2107672161,2412447074,2627466902,1861252501,1098587580,3004210879,2688576843,1378610760,2262928035,1955203488,1742404180,2511436119,3416409459,969524848,714683780,3639785095,205050476,4266873199,3976438427,526918040,1361435347,2739821008,2954799652,1114974503,2529119692,1691668175,2005155131,2247081528,3690758684,697762079,986182379,3366744552,476452099,3993867776,4250756596,255256311,1640403810,2477592673,2164122517,1922457750,2791048317,1412925310,1197962378,3037525897,3944729517,427051182,170179418,4165941337,746937522,3740196785,3451792453,1070968646,1905808397,2213795598,2426610938,1657317369,3053634322,1147748369,1463399397,2773627110,4215344322,153784257,444234805,3893493558,1021025245,3467647198,3722505002,797665321,2197175160,1889384571,1674398607,2443626636,1164749927,3070701412,2757221520,1446797203,137323447,4198817972,3910406976,461344835,3484808360,1037989803,781091935,3705997148,2460548119,1623424788,1939049696,2180517859,1429367560,2807687179,3020495871,1180866812,410100952,3927582683,4182430767,186734380,3756733383,763408580,1053836080,3434856499,2722870694,1344288421,1131464017,2971354706,1708204729,2545590714,2229949006,1988219213,680717673,3673779818,3383336350,1002577565,4010310262,493091189,238226049,4233660802,2987750089,1082061258,1395524158,2705686845,1972364758,2279892693,2494862625,1725896226,952904198,3399985413,3656866545,731699698,4283874585,222117402,510512622,3959836397,3280807620,837199303,582374963,3504198960,68661723,4135334616,3844915500,390545967,1230274059,3141532936,2825850620,1510247935,2395924756,2091215383,1878366691,2644384480,3553878443,565732008,854102364,3229815391,340358836,3861050807,4117890627,119113024,1493875044,2875275879,3090270611,1247431312,2660249211,1828433272,2141937292,2378227087,3811616794,291187481,34330861,4032846830,615137029,3603020806,3314634738,939183345,1776939221,2609017814,2295496738,2058945313,2926798794,1545135305,1330124605,3173225534,4084100981,17165430,307568514,3762199681,888469610,3332340585,3587147933,665062302,2042050490,2346497209,2559330125,1793573966,3190661285,1279665062,1595330642,2910671697 }, + { 0,329422967,658845934,887597209,1317691868,1562966443,1775194418,2054015301,2635383736,2394315727,3125932886,2851302177,3550388836,3225172499,4108030602,3883469565,1069937025,744974838,411091311,186800408,1901039709,1659701290,1443537075,1168652484,2731618873,2977147470,2241069783,2520160928,3965408229,4294560658,3407766283,3636263804,2139874050,1814657909,1489949676,1265388443,822182622,581114537,373600816,98970183,3802079418,4047354061,3319402580,3598223395,2887074150,3216496913,2337304968,2566056447,1078858371,1408010996,1728782957,1957280282,247755615,493284136,696337329,975428550,3713716539,3472378188,4196393429,3921508770,2479927527,2154965136,3029696521,2805405822,4279748100,3971309171,3629315818,3421531805,2979899352,2722054063,2530776886,2239369025,1644365244,1906417099,1162229074,1457827109,747201632,1059847191,197940366,409914617,3235002245,3547377650,3885434731,4097154844,2388153945,2650459694,2837276343,3133144768,1573319741,1315204170,2055455955,1763794084,323786209,15601046,873047311,665533816,2157716742,2470362481,2816021992,3027996063,3457565914,3719617709,3914560564,4210158659,495511230,237665993,986568272,695160359,1392674658,1084235541,1950857100,1743073275,3210335367,2902150384,2552030313,2344516638,4057183579,3799067948,3600188853,3308527042,575477567,837783368,84420561,380288934,1825011427,2137386644,1266828813,1478549114,4223924985,3898696334,3699821079,3475264096,3041499941,2800419666,2450303947,2175677372,1725380929,1970643254,1100089775,1378914776,677206173,1006616810,253257843,482013188,3288730488,3617886991,3812834198,4041319393,2324458148,2569990867,2915654218,3194733117,1494403264,1253068983,2119694382,1844797529,395880732,70922603,819829234,595526021,2219317755,2548728204,2735548693,2964304226,3401742375,3647004752,3985066185,4263891134,425515587,184435252,1041885869,767259354,1473690527,1148462056,1888717681,1664160518,3146639482,2821681165,2630408340,2406105315,4110911910,3869577681,3527588168,3252691263,647572418,893105077,31202092,310281051,1746094622,2075251305,1331067632,1559552647,81018109,393651338,596708371,808686692,1247698209,1509737814,1830514127,2126116280,2579562309,2321704754,3196440491,2905036764,3611991705,3303540462,4027559543,3819779584,991022460,682841355,475331986,267806181,1973136544,1715025111,1390320718,1098646585,2785349316,3047659187,2168471082,2464327261,3901714200,4214093679,3486146550,3697854337,2069880831,1761429384,1545269009,1337489254,903200291,645342804,311463629,20059834,3863682119,4125721648,3238931625,3534533854,2831252891,3143886316,2407812469,2619790594,1150955134,1463334409,1675566736,1887274727,168841122,431151061,760577868,1056433979,3650022854,3391911345,4274773288,3983099231,2533657626,2225476717,2957098228,2749572227 }, + { 0,2772537982,1332695565,3928932467,2665391130,1000289892,3518101015,1961911401,944848581,2635115707,2000579784,3531603638,2794429151,63834273,3923822802,1285642924,1889697162,3588485108,1070411655,2592914937,4001159568,1262308334,2702412701,72489443,1223902031,3987919153,127668546,2732426044,3593332565,1936487723,2571285848,1006839590,3779394324,1141205354,2922096921,191511399,2140823310,3671838064,821366019,2511642493,3642082769,2085902255,2524616668,859506082,1204511179,3800757173,144978886,2917507512,2447804062,883365088,3733574803,2076722925,255337092,2860101882,1079472265,3843482359,2847389787,217459237,3872975446,1134131240,929635393,2452131391,2013679180,3712474162,3345318105,1646531239,2282410708,759906474,1505436867,4244289213,383022798,3012945072,4281646620,1517628514,2958814225,354057839,1642732038,3299575928,780486667,2344934005,3083337043,310800173,4171804510,1575566624,689527113,2354629431,1719012164,3275200826,2409022358,718754280,3237581211,1706558437,289957772,3020551666,1579627905,4217808895,639728589,2204166579,1766730176,3423583166,3103776727,499010985,4153445850,1389436836,510674184,3140605814,1360992005,4099835259,2158944530,636449644,3485578015,1786782049,1451427399,4089615417,434918474,3165505076,3361579613,1830563875,2268262480,577987118,1859270786,3415452412,566061711,2231171313,4027358360,1431113446,3210989205,438459627,2334619459,778495293,3293062478,1628026672,368694105,2964865319,1519812948,4292285226,3010873734,372759544,4229503883,1498974709,766045596,2297004002,1657257873,3347459567,4219800265,1589942455,3035257028,296471226,1700507347,3222944941,708115678,2406837920,3285464076,1721083506,2361091585,704312447,1560973334,4165665384,308658715,3072610405,1784908887,3475119657,621600346,2152549412,4106037325,1375517235,3151133248,513009726,1379054226,4151517420,492691615,3088872161,3438024328,1772979446,2206418053,650303227,448917981,3212862371,1437508560,4042207662,2216646087,559859641,3413116874,1848743348,579915544,2278645094,1845468437,3367898987,3159255810,420477308,4079040783,1449175921,1279457178,3909314020,53323159,2792110057,3533460352,2011021822,2649948557,951227379,1947453791,3511835425,998021970,2654800172,3939331397,1334640443,2778873672,14921014,1021348368,2577471598,1938806813,3603843683,2721984010,125811828,3981540359,1209069177,78755029,2716870315,1272899288,4003427494,2590970063,1060012721,3573564098,1883361468,2902854798,138911472,3798556291,1193856253,869836948,2526624490,2092432025,3656804583,2505519691,806789173,3661127750,2138698296,193566289,2932343855,1155974236,3785840162,3718541572,2028331898,2462786313,931836279,1132123422,3862644576,202737427,2840860013,3858059201,1085595071,2862226892,266047410,2066475995,3731519909,876919254,2433035176 }, + { 0,3712330424,3211207553,1646430521,2065838579,2791807819,3292861042,419477706,4131677158,721537374,1227047015,2489772767,2372293141,1344534701,838955412,4014267180,3915690301,874584965,1443074748,2336634884,2454094030,1325607542,757179215,4033087991,522244827,3261429859,2689069402,2097306594,1677910824,3108456848,3680878761,102787601,3609531531,174112307,1749169930,3037175218,2886149496,1900187584,325060345,3458575425,560035693,4230274517,2651215084,1128529492,1514358430,2265377830,3844367647,945934247,1044489654,3808694030,2166785591,1550003343,1164153925,2552643325,4194613188,658578812,3355821648,356543720,2002970065,2854702953,3005740963,1851940123,205575202,3506798234,2879807463,1994650975,348224614,3380926174,3498339860,230802604,1877167509,2997282605,1575107585,2158466745,3800375168,1069593912,650120690,4219840330,2577870451,1155695819,1120071386,2676442210,4255501659,551577571,971038505,3836048785,2257058984,1539462672,3028716860,1774397316,199339709,3601073157,3483679951,316741239,1891868494,2911254006,2088979308,2714165716,3286526189,513917525,128023199,3672428583,3100006686,1703146406,2328307850,1468170802,899681035,3907363251,4058323321,748729281,1317157624,2479329344,2515008081,1218597097,713087440,4156912488,4005940130,864051482,1369630755,2363966107,1671666103,3202757391,3703880246,25235598,411150404,3317957372,2816904133,2057511293,1386268991,2414175111,3989301950,813842438,696449228,4106703476,2531646285,1268806133,2766449369,2040594529,461605208,3334874080,3754335018,42152338,1621211307,3185840659,3150215170,1719784122,77814659,3655790907,3236317681,497279817,2139187824,2730803400,1300241380,2428875100,4075239525,799183581,916597271,3957817519,2311391638,1417716526,2240142772,1489008396,987954741,3886503053,4272417863,602031871,1103155142,2625987966,1942077010,2927891690,3433471443,300103531,149131169,3584435481,3078925344,1791035032,1826712713,2980365873,3548794632,247719344,398679418,3397842882,2829352699,1977734211,2594508655,1205904855,633482478,4169631318,3783736988,1019384868,1591745821,2208675749,4177958616,608386144,1180808537,2602835937,2183440171,1600195987,1027835050,3758501394,256046398,3523698566,2955269823,1835039751,1952498893,2837802613,3406292812,373444084,274868197,3441921373,2936341604,1916841692,1799362070,3053829294,3559339415,157458223,3861267459,996404923,1497458562,2214907194,2634315248,1078058824,576935537,4280745161,774079059,4083558635,2437194194,1275136874,1426174880,2286164248,3932590113,925055641,3630686645,86133517,1728102964,3125110924,2739261510,2113960702,472052679,3244775807,3343332206,436378070,2015367407,2774907479,3160736413,1629530149,50471196,3729230756,822300808,3964074544,2388947721,1394727345,1243701627,2539965379,4115022586,671344706 }, + { 0,940666796,1881333592,1211347188,3762667184,3629437212,2422694376,2826309188,3311864721,4252394557,3041252553,2371140453,623031585,489937549,1426090617,1829832149,2401395155,3073576575,4278238859,3339833639,1869078371,1467396303,524615739,659845015,1246063170,1918109166,979875098,41343670,2852181234,2450635614,3659664298,3795018758,464041303,599382779,1804233231,1402668451,4226616295,3288097867,2345653439,3017718547,3738156742,3873362282,2934792606,2533101106,1049231478,110850010,1319690030,1991880834,2492126340,2895887144,3836218332,3703137392,1959750196,1289618840,82687340,1023204032,1374543637,1778167993,567214157,434008033,2980602277,2310606345,3247095549,4187738449,928082606,255853826,1198765558,2137184858,3608466462,4010130354,2805336902,2670159082,4063650111,3391557267,2182397543,3120943563,309583759,711110691,1649475799,1514172283,3094547325,2153931985,3360805925,4030774153,1479980493,1613224545,672426645,268764473,2098462956,1157984064,221700020,891793432,2639380060,2772488688,3983761668,3579973288,754573305,350793813,1557856417,1690988301,3434897737,4104982245,3164519953,2224017853,3919500392,3515857860,2579237680,2712495260,165374680,835323252,2046408064,1105779244,2749087274,2613760390,3556335986,3957853918,1134428314,2072997686,868016066,195932270,1723643323,1588451863,379480803,781124943,2264468235,3202901159,4141601875,3469392895,1856165212,1454619376,511707652,647062952,2397531116,3069576256,4274369716,3335838488,2881871565,2480189793,3689349525,3824578105,1266704509,1938886609,1000521509,62115977,3783308431,3650214691,2443340759,2847081595,29690431,970220947,1911018855,1240906443,619167518,485937330,1422221382,1825837034,3298951598,4239617538,3028344566,2358358362,1963614219,1293619111,86556499,1027199231,2505039547,2908664087,3849126371,3715919439,2959960986,2289828918,3226449090,4166966126,1344853290,1748613766,537528946,404448734,4196925912,3258543732,2315968128,2988159276,443400040,578605252,1783586864,1381896092,1062144585,123626981,1332598033,2004662973,3742020857,3877362517,2938661793,2537096205,1509146610,1642254430,701587626,297799430,3115712834,2175233774,3381976602,4052070838,2626991203,2760235983,3971377979,3567715479,2094074579,1153459583,217306507,887274023,3604078113,4005605773,2800943481,2665639637,915693713,243601213,1186381769,2124927077,330749360,732412444,1670646504,1535468868,4092816128,3420587180,2211558488,3149978612,1113262757,2051695881,846845437,174635601,2719921173,2584730553,3527174989,3928818913,2268856628,3207425688,4145995372,3473912256,1736032132,1600704552,391864540,793382768,3447286646,4117234906,3176903726,2236275586,758961606,355318378,1562249886,1695507762,136208615,806293323,2017247167,1076744211,3898334807,3494556155,2558066959,2691198627 }, + { 0,4012927769,3683426499,884788186,3002414967,1573215342,1769576372,2252995757,1611012127,2402710278,3146430684,1421530053,3539152744,1036207217,159354795,3863995570,3222024254,792484647,461410557,4105239524,1928922953,2647223376,2843060106,1178979475,2685020193,1329218360,2072414434,2495013883,318709590,4258231375,3379806101,641979532,2247366285,1791262100,1584969294,2974342487,922821114,3627109091,3968696633,62777888,3857845906,180512139,1048489553,3511600456,1460091365,3090633468,2357958950,1673261631,1173890739,2865253802,2658436720,1900342633,4144828868,406682333,746696967,3283212830,637419180,3402519989,4268924527,289600886,2534083035,2017157826,1283959064,2746728961,235166699,3778294002,3582524200,985174065,3169938588,1405159301,1736297567,2286790470,1845642228,2167548141,3046040375,1522436142,3707204739,868687770,125555776,3897278297,3456658389,557318348,361024278,4206141455,2096979106,2479699899,2809265249,1212258168,2920182730,1094588627,1971507977,2595403792,486229181,4090179492,3346523262,675778407,2347781478,1690314367,1350364581,3209463484,956660241,3593801992,3800685266,230273483,3958789497,80100960,813364666,3746209443,1493393934,3056797975,2190459597,1841277396,1274838360,2764838465,2423315867,2134947458,4178135599,372842806,579201772,3451224565,737830215,3301576286,4034315652,524725917,2567918128,1983854889,1115943667,2914228714,470333398,4080590031,3347322645,682916876,2935849121,1104014264,1970348130,2587970427,2081337289,2470364368,2810318602,1219650579,3472595134,567014311,360134781,4198978404,3691284456,859106545,126363435,3904392242,1861333151,2176965510,3044872284,1515027269,3154288631,1395848430,1737375540,2294174765,251111552,3787965337,3581610051,978019162,2583470427,1993132610,1114636696,2906679937,722048556,3292134709,4035262191,531979766,4193958212,382390877,578165127,3443946142,1259310643,2755650858,2424516336,2142455273,1508938085,3066100348,2189177254,1833720511,3943015954,70634763,814286545,3753471432,972458362,3603358307,3799656889,222970528,2332278285,1681118484,1351556814,3216995799,302836797,4248602404,3380628734,649078759,2700729162,1338617939,2071296905,2487554192,1913320482,2637864763,2844153057,1186349048,3237987157,802138188,460546966,4098033807,3523271683,1026602778,160201920,3871086553,1626729332,2412085357,3145288631,1414078638,2986787868,1563864837,1770677471,2260340678,15987563,4022573170,3682554792,877607089,2549676720,2026410409,1282693747,2739155306,621661639,3393038046,4269894916,296814109,4160676527,416188854,745685612,3275893109,1158403544,2856042177,2659677467,1907826178,1475660430,3099894167,2356701773,1665663316,3842113017,171022048,1049451834,3518838307,938660497,3636640136,3967709778,55449931,2231887334,1782025983,1586185509,2981834300 }, + { 0,1745038536,3490077072,3087365464,2782971345,3454265625,1978047553,501592201,1311636819,640602523,2653660355,4129851403,3956095106,2211320906,1003184402,1405636058,2623273638,4099462766,1281205046,610177022,968572791,1371018175,3921503975,2176731695,3530950645,3128240957,40918629,1785950893,2006368804,529919724,2811272116,3482564476,1029407677,1431875445,3982350893,2237593317,2562410092,4038617764,1220354044,549335860,1937145582,460673574,2742036350,3413314486,3600202559,3197474807,110158511,1855180391,2701162779,3372438995,1896226955,419761219,81837258,1826852866,3571901786,3169175954,4012737608,2267981952,1059839448,1462300944,1254965657,583953745,2597001225,4073206977,2058815354,313797554,2863750890,3266474530,3747070635,3075796579,257006395,1733474291,882571817,1553585889,3835470777,2359267185,2440708088,4185461552,1098671720,696208032,3874291164,2398081300,921347148,1592363140,1124874253,722408645,2466931101,4211690837,2831220879,3233950791,2026330399,281310679,220317022,1696786838,3710360782,3039080454,1206682823,804235279,2548751703,4293521823,3792453910,2316266974,839522438,1510552654,163674516,1640125788,3653705732,2982415564,2887892037,3290599565,2082989525,337955101,3686235745,3014939305,196159473,1672612665,2119678896,374642552,2924601888,3327315688,2509931314,4254707706,1167907490,765458026,813319907,1484352043,3766230899,2290037691,4117630708,2641175100,627595108,1298889644,1351535397,948824045,2156434101,3901472381,3141792679,3544244079,1799727671,54953727,514012790,1990204094,3466948582,2795914030,1765143634,20371610,3107171778,3509616906,3436523907,2765495627,483616787,1959806171,655886593,1327179209,4145959057,2669509721,2197343440,3942375448,1392416064,989706632,3358952777,2687934849,406050009,1882257425,1842694296,97936464,3184726280,3587194304,2249748506,3994770642,1444817290,1042089282,603502027,1274779907,4093570139,2617098387,1416525807,1013799719,2221420159,3966436023,4052660798,2576195318,562621358,1233897318,440634044,1916839540,3393573676,2722562020,3215150957,3617612709,1873090301,128334389,2413365646,3889833286,1608470558,937196758,708430943,1111154839,4198471119,2453453063,3254056157,2851592213,301116749,2045870469,1679044876,202841540,3021105308,3692119124,327349032,2072109024,3280251576,2877785712,3059889913,3730905649,1717858153,241648545,1571753595,900473523,2376685547,3853155107,4165979050,2420959074,675910202,1078640370,2994899507,3665929979,1652872099,176684907,392318946,2137088810,3345225330,2942778042,4239357792,2494323624,749285104,1151992376,1498395313,827104889,2303322913,3779774441,786002069,1188715613,4276037893,2531001805,2335814980,3812268428,1530916052,859619356,1626639814,150446350,2968704086,3639736478,3306440727,2903991519,353505671,2098281807 }, + { 0,1228700967,2457401934,3678701417,555582061,1747058506,3009771555,4200137988,1111164122,185039357,3494117012,2575270835,1663469239,706411408,4049501433,3093430750,2222328244,3444208787,370078714,1597148893,2775288793,3965187838,924021143,2117012656,3326938478,2406576201,1412822816,487164423,3880816387,2926375460,1965585741,1007945834,218129817,1144789182,2675482583,3594838768,740157428,1696701139,3194297786,4149829789,1329291587,101129316,3712195341,2491409962,1848042286,656055817,4234025312,3043124295,2306239533,3226079498,453940835,1379068740,2825645632,3780612967,974328846,1932486953,3410847991,2188449232,1496683193,269086622,3931171482,2741802941,2015891668,823422451,436259634,1396487701,2289578364,3242478683,991775071,1914778744,2842014481,3763981878,1480314856,285717199,3393402278,2206156929,2032553349,807022754,3948853195,2724383468,2658583174,3612000161,202258632,1160922607,3211477227,4132912588,756267685,1680852866,3696084572,2507258747,1312111634,118047029,4249895985,3026991382,1864941183,638894936,385920683,1581044620,2239255781,3427019202,907881670,2132890081,2758137480,3982076847,1429973617,470275926,3343077439,2390699288,1948657692,1025135931,3864973906,2942480245,2474026783,3662338616,17718609,1211244662,2993366386,4216805461,538173244,1764729371,3511526341,2557599458,1127569803,168371372,4031783336,3110886543,1646844902,722773697,872519268,2101209923,2792975402,4014280973,354161673,1545627950,2271538759,3461911392,1983550142,1057419161,3829557488,2910721495,1462178003,505114100,3311397533,2355337146,2960629712,4182500087,571434398,1798510777,2439650749,3629539482,51570675,1244568276,4065106698,3144738349,1614045508,688397411,3545307495,2590860352,1093264169,135634446,956429309,1883082458,2876836275,3796202644,404517264,1361054903,2321845214,3277387513,2067461927,839289344,3913420137,2692640846,1512535370,320538733,3361705732,2170810915,3178756681,4098590574,789512199,1714650400,2624223268,3579184387,236094058,1194262349,4283235987,3060827060,1832125661,604535290,3729882366,2540503513,1277789872,85326743,771841366,1732059249,3162089240,4114995775,253550395,1176543772,2640586101,3562559570,1815763340,621159595,4265780162,3078545125,1294457825,68921030,3747553711,2523094152,2859947234,3813353925,940551852,1899221899,2339034767,3260459944,420621505,1345212902,3897315384,2708483359,2050271862,856217425,3377582677,2154671986,1529423899,303387964,587282639,1782400488,2977546881,4165320614,35437218,1260439429,2422489324,3646438859,1631206421,671498546,4081239643,3128867708,1076346488,152814431,3529458742,2606971153,2809606523,3997912156,890227509,2083763730,2255139606,3478572593,336742744,1563309183,3846976929,2893039750,1999949807,1040757448,3293689804,2372782827,1445547394,521482405 } +}; + +const uint32_t crc32c_long[4][256] = { + { 0,3762348204,3312301993,623728389,2402752931,1870133519,1247456778,2853850790,461522359,4223837467,3740267038,1051660978,2494913556,1962261688,1373170621,2979531537,923044718,3611585474,4066983111,304733291,3090387661,1483960929,2103321956,2636039624,747032281,3435540085,3924523376,162240988,2746341242,1139881942,1725718739,2258403455,1846089436,2387211888,2875498869,1260667353,3778940799,25096147,609466582,3289602170,1972065131,2513155015,2967921858,1353057390,4206643912,452766308,1070726497,3750829517,1494064562,3108863262,2623547931,2082523831,3594159121,913990845,324481976,4078424852,1116723205,2731489449,2279763884,1738706688,3451437478,771236106,148207119,3902117539,3692178872,1012059412,427792913,4181686973,1394947099,3009795255,2521334706,1980261150,3348129807,667977891,50192294,3804053258,1218933164,2833748224,2378876421,1837770409,3944130262,190203514,779817343,3460035027,1679933301,2220974041,2706114780,1091364976,4036289377,282330061,905532616,3585717348,2141452994,2682460782,3134082411,1519300039,2988129124,1381751752,2004257997,2536926305,1026302663,3714892395,4165047662,402748866,2845408979,1238998655,1827981690,2360617430,648963952,3337521116,3821261017,58929269,2233446410,1700745382,1081214883,2687690511,170437033,3932702981,3477413376,788922028,2661152189,2128418065,1542472212,3148915384,296414238,4058647730,3569834935,881310491,3184012673,1569246509,2024118824,2565175940,855585826,3535787150,4153574283,399663911,2789894198,1175095450,1663557535,2204581683,696086933,3376255289,3960522300,206579344,2328667887,1787577923,1335955782,2950820330,100384588,3854262240,3231058149,550955081,2437866328,1896743924,1411601649,3026433117,511310587,4265155159,3675540818,995405310,3552656221,864148465,380407028,4142689368,1559634686,3166093906,2577110359,2044425723,3359866602,671325766,221169987,3983419887,1198810953,2805237733,2182729952,1650012236,3838160947,75845791,564660122,3253266230,1811065232,2343717180,2929663545,1323302549,4282905988,520557864,975847981,3664421505,1886448679,2419068043,3038600078,1432206114,1641676857,2174410901,2763503504,1157060412,4008515994,246282550,729853491,3418377887,2052605326,2585306402,3207983655,1601507979,4117716013,355449985,805497732,3493989160,1457425239,3063835643,2477997310,1945361490,3655963380,967406168,478422365,4240754161,1297927904,2904305228,2284943689,1752275429,3261847363,573257711,117858538,3880157254,265492197,4019451465,3401490764,721306080,2162429766,1621422058,1166653679,2781435971,340874066,4094800894,3510428923,830211159,2607172337,2066131549,1577844056,3192593908,953654667,3633806631,4256836130,502975118,3084944424,1470129284,1921856385,2462962477,592828476,3272947856,3862458261,108564281,2892153247,1277305139,1762620982,2303694490 }, + { 0,2122067443,4244134886,2189719061,4229742909,2187390158,14981851,2123937576,4258657419,2208946552,19771245,2136048286,29963702,2142574661,4247875152,2202878883,4266106855,2151395860,46121985,2093214194,39542490,2082960169,4272096572,2162108623,59927404,2112767647,4285149322,2165710201,4287539793,2180155298,58126775,2097863748,4184033599,2266981580,94048985,2078752554,92243970,2063836657,4186428388,2281438743,79084980,2060095559,4165920338,2251475873,4171922569,2262192506,72492911,2049837724,119854808,2035874603,4225535294,2241896653,4214757349,2235841046,130042883,2042388976,4210106963,2223837088,101284277,2020955206,116253550,2022821533,4195727496,2221512059,4146783375,2304166268,198360937,1974375066,188097970,1967786049,4157505108,2310165415,184487940,1954758135,4127673314,2289788433,4142125369,2292186314,169577183,1952950060,158169960,1997624987,4120191118,2347306365,4117871189,2332923814,160031155,2012597312,4105736163,2328142352,138466309,1983707638,144985822,1993892653,4099675448,2317367499,239709616,1882554435,4071749206,2362301349,4065684621,2351513982,246232939,1892752024,4087109947,2380297416,258212573,1897410350,260085766,1912387061,4084777952,2365910547,4027462231,2389843876,217475505,1921664066,202568554,1919868569,4041910412,2392229247,232507100,1940384559,4045643066,2405413065,4056352737,2411407890,222256135,1933799924,3954819055,2512753180,390194185,1765657082,396721874,1775850273,3948750132,2501970119,376195940,1745905303,3935572098,2498248049,3933243993,2483857322,378065343,1760885836,368975880,1803685371,3909516270,2541377053,3923960117,2543766726,354073299,1801885472,3895186563,2522347888,349409125,1789895318,339154366,1783314509,3905900120,2528338859,316339920,1822874403,3995249974,2422112453,4005967853,2428115486,306080779,1816281592,4010738267,2440245160,334977469,1837855822,320062310,1836052117,4025194624,2442638707,3969739063,2464236740,275067601,1847140130,276932618,1862108665,3967415276,2449858079,289971644,1865723983,3987785306,2479680425,3981728897,2468901234,296486759,1875913364,479419232,1659860627,3765108870,2652319093,3767507549,2666772398,477610427,1644948552,3779506155,2671411736,499053581,1673714174,492465878,1663451941,3785504048,2682132675,3805594759,2628315508,506240865,1615901330,516425146,1622419529,3794820700,2622256047,520171532,1635589631,3824774122,2642757145,3810390321,2640436418,535145175,1637451556,3857715807,2609659820,419973561,1735681098,434951010,1737555601,3843328132,2607326583,405137108,1717160743,3839737138,2594279617,3828951017,2588215834,415333391,1723683324,465014200,1707843659,3880769118,2570320813,3886763141,2581029238,458430307,1697594000,3865213235,2552124608,446309077,1692798758,444512270,1677891069,3867599848,2566573595 }, + { 0,3533637935,2698142895,1917676928,1145618351,2530719360,3835353856,906351151,2291236702,1510897265,675486705,4208726750,3436822769,507955678,1812702302,3197414769,349079629,3327230306,3021794530,1719920077,1350973410,2182692557,4032058189,583752290,2623534867,1321270844,1015911356,3994196627,3625404604,176701843,2026187795,2858034492,698159258,4211218869,2303685685,1540390170,1842720565,3209340442,3439840154,530105013,2701946820,1939039979,31329131,3544252996,3846492267,937154884,1167504580,2533998059,1028888791,4023161336,2642541688,1327428951,2031822712,2877566551,3653845975,190204664,3049449353,1734209190,353403686,3348072969,4052375590,588599561,1364737161,2210870694,1396318516,2175084571,4092085659,561466548,393387675,3320682420,3080780340,1698689819,3685441130,154425157,2071542469,2850436074,2682511813,1300031722,1060210026,3987639365,1207216505,2506858582,3878079958,901367033,62658262,3508740089,2741924473,1911651158,3479557671,502980360,1874309768,3173563303,2335009160,1504862375,738135335,4183819272,2057777582,2822256769,3665122561,149576750,1055886849,3966797614,2654857902,1285743489,4063645424,547964895,1390684767,2155553648,3061772639,1692530800,380409328,3291716831,1852422627,3170283724,3468418380,472175715,706807372,4173205347,2331206371,1483500492,3875063485,879218578,1177199122,2494933821,2729474322,1882157117,39984573,3506246802,2792637032,1961577287,111552199,3560517608,3795647943,816051432,1122933096,2423361607,786775350,4235867161,2385992089,1554534582,1789756057,3090320310,3397379638,417394457,2998585893,1613087498,308850314,3237455781,4143084938,611155109,1444942117,2227116042,975943035,3904158804,2600063444,1214699771,2120420052,2902197243,3736170107,204367700,2414433010,1568037853,792409693,4255399794,3416386909,423552114,1802734066,3119284445,125316524,3588695171,2812954883,1966424108,1127256579,2444204844,3823302316,830340995,2603080383,1236849552,1005960720,3916085055,3748619536,233860159,2143093183,2904688784,330737121,3240733902,3009724750,1643890785,1476270670,2237731681,4146888417,632518606,4115555164,668035699,1436289011,2265124572,2970017011,1671026140,299153500,3276517747,2111773698,2940212525,3708647597,261255554,966239149,3943213698,2571486978,1272630829,3783322385,857727550,1095929790,2479720081,2781369534,2002214289,85602321,3615832382,1762759759,3146685792,3385061600,459078095,760818656,4291175119,2374717263,1595164256,3704845254,239893225,2080446313,2929598022,2560347241,1241826630,944351430,3939934697,1413614744,2262631863,4103104567,638542104,269136695,3264592408,2967000984,1648877239,3357408139,444789412,1758437156,3125843467,2354398244,1590316299,747053195,4262996388,1082950869,2450755066,3764314234,851568981,79969146,3596300885,2752929749,1988712186 }, + { 0,1225060897,2450121794,3675068003,570408565,1761299540,3019266615,4210206742,1140817130,184258251,3522599080,2566023817,1644216991,721694910,4027131613,3104691452,2281634260,3472493557,368516502,1559490487,2785101729,4010128768,872981475,2097959362,3288433982,2365945631,1443389820,520917853,3858643787,2902116714,2012733193,1056124200,168920409,1125480312,2551734555,3508310842,737033004,1659554061,3118980974,4041420111,1240398259,15338386,3689356785,2464411600,1745962950,555070951,4195918724,3004977573,2381282445,3303771820,535206095,1457679086,2886779640,3843305689,1041835706,1998443675,3457155175,2266296902,1545200677,354227716,4025466386,2800438323,2112248400,887269489,337840818,1562900627,2250960624,3475905745,903656647,2094548710,2815774853,4006716068,1474066008,517506169,3319108122,2362531899,1982056493,1059535372,3827969135,2905529934,2480796518,3671654727,30676772,1221649669,2988592403,4213620530,539732305,1764711280,3491925900,2569436589,1110141902,187668975,4057805305,3101279192,1674892731,718284698,506630123,1463188938,2352704425,3309279624,1070412190,1992934335,2915358172,3837798397,1573778177,348717344,3485734723,2260788578,2083671412,892780373,3996887350,2805947159,2580313663,3502801950,197497469,1119969372,3090401354,4046928491,708455432,1665064489,3660778197,2469918964,1211821719,20847798,4224496800,2999469697,1774538978,549561027,675681636,1631774533,3125801254,4081779463,163162897,1086150960,2612023123,3535060338,1807313294,582851503,4189097420,2964619245,1246156795,54666714,3629069241,2437661080,2948132016,3871088273,1035012338,1958083283,2387038917,3343098084,474920583,1430930598,3964112986,2772656763,2119070744,927630905,3451399727,2226969614,1605487213,380975180,576163901,1800626716,2958980223,4183459422,61353544,1252842601,2443299338,3634706475,1638460631,682368758,4087416981,3131439796,1079464610,156475523,3529422560,2606384321,2779343337,3970800584,933268907,2124709770,2220283804,3444712893,375337950,1599848959,3864401155,2941445922,1952444737,1029374816,3349785462,2393725271,1436569396,480558357,1013260246,1969352183,2926377876,3882355125,496673187,1419662210,2408793569,3331831744,2140824380,916361501,3985868670,2761389407,1583734089,392245096,3429644555,2238237482,3147556354,4070511651,697434688,1620504673,2590267511,3546327638,141409333,1097420308,4167342824,2975885513,1785560746,594119819,3650823325,2426394300,1267908831,43397886,913611407,2138073262,2759687885,3984166124,394994938,1586484955,2239938744,3431346841,1972102757,1016009796,3884057127,2928078854,1416910864,493922865,3330128978,2407091827,2978636635,4170092922,595822361,1787262264,2423643438,3648073487,41695596,1266207565,4067762097,3144805776,1618803699,695732690,3549077956,2593018853,1099122054,143112103 } +}; +const uint32_t crc32c_short[4][256] = { + { 0,3702618788,3163456441,1614805277,2096198019,2688551719,3229610554,483297438,4192396038,626235810,1164730559,2581404187,2232652421,1503848481,966594876,3844893592,4129927421,714656345,1252471620,2518043104,2329461118,1449769946,911622855,3941021795,264983547,3547998559,3007696962,1878305510,1933189752,2945145052,3484721601,319150949,3921614603,890138031,1429312690,2306928150,2504943240,1241455660,700507441,4117864341,274592781,3438055081,2899539892,1885474064,1823245710,2954755882,3491890743,210992275,529967094,3274169682,2736268367,2141806315,1667749493,3218517201,3756611020,56110952,3866379504,986005076,1526384457,2253110765,2592421235,1177833431,638301898,4206546030,3599915239,170074691,1780276062,3064832506,2858625380,1993495488,384674525,3395080313,795917281,4089561413,2482911320,1330594556,1401014882,2402332870,4010756571,868103039,549185562,4228551358,2620746659,1082396935,1548392857,2163991357,3770948128,1014325380,3646491420,99119544,1708624037,3110531585,2779282079,2031681595,421984550,3315041154,1059934188,3818665288,2208549973,1595062001,1138507375,2674738379,4283612630,602130290,3335498986,444520014,2051092307,2800768503,3124682089,1720690637,112221904,3657507956,3372547857,364217781,1972010152,2839217676,3052768914,1766126646,159059243,3586815887,820386839,3965150899,2355666862,1356457226,1276603796,2426804016,4036619821,740856969,2831730495,1954135451,340149382,3371646498,3560552124,143182872,1756837125,3020312481,1361716281,2375769757,3986990976,823516452,769349050,4050267934,2438321667,1306832039,1591834562,2186284390,3798987899,1054772959,571475521,4271996133,2661189112,1110441820,2802029764,2075324000,462231421,3342626265,3690128711,121872355,1736206078,3150781530,1098371124,2647042704,4260975501,558377257,1032233399,3778534163,2164793870,1572427946,3096785714,1680099734,68923531,3635071535,3294905009,416626709,2028650760,2757475244,3076415689,1810831981,198239088,3613497812,3417248074,387869678,1998689011,2878400599,1320977359,2450389355,4063363190,780368594,843969100,4009527528,2395173365,1383205713,2119868376,2733368700,3268680801,509961925,44822107,3726284031,3190124002,1653872454,2277014750,1527318138,993460071,3884418499,4215868765,670595065,1204260580,2608264256,2289250085,1422022017,889040028,3897349688,4102184614,674440194,1208802591,2495457211,1905380387,2904602247,3441381274,296629566,224443808,3520186116,2985180697,1834960061,2548402387,1263858295,728435562,4158288334,3944020304,933594100,1469741801,2334851149,1845980117,2998276465,3532253292,238588616,318118486,3460784370,2927139311,1925833547,1640773678,3179102858,3712138135,32751923,490555821,3247190793,2712914452,2097328304,2553207592,1151312268,614488209,4161872437,3839863467,946786319,1481713938,2229294006 }, + { 0,1417541775,2835083550,4236642705,1411093709,6712386,4242564563,2828901724,2822187418,4232761621,13424772,1420894219,4230790487,2823898584,1423395913,11187398,1434592709,33545546,4252619995,2835622996,26849544,1441024391,2841788438,4246714521,4256500831,2848519376,1431240001,20121038,2846791826,4258488349,22374796,1428721923,2869185418,4286165765,67091092,1468154395,4280278855,2875336648,1474571865,60413654,53699088,1464769183,2882048782,4290079617,1462302429,55905874,4292020163,2880372556,4270222927,2868614848,1451073361,33581022,2862480002,4276093453,40242076,1444672275,1454458837,46972762,4266309323,2855751236,44749592,1456941975,2857443846,4264352393,1407508965,127474026,4213117179,2942494836,134182184,1401064871,2936308790,4219043001,4224960639,2947428592,1395145057,123060718,2949143730,4222985277,120827308,1397642531,107398176,1377516719,2929538366,4209036721,1383944429,100706402,4203127283,2935708028,2924604858,4197193013,111811748,1389880363,4199184759,2922873336,1387366505,114061542,4175473263,2895991520,1343970161,73835518,2902146722,4169582125,67162044,1350383411,1356301301,78281594,4163662571,2891024996,80484152,1353838519,2889344550,4165607081,2908917674,4179588901,93945524,1373931067,4185463655,2902778856,1367534201,100602614,89499184,1361600191,2913883950,4191399841,1364079357,87280242,4189438947,2915580780,2815017930,4088675141,254948052,1531955803,4090648327,2813308808,1529456153,257187478,268364368,1535316703,2802129742,4084786113,1541766813,261654034,4078866307,2808313612,4065060367,2788564608,1521489681,248377246,2790290114,4063070797,246121436,1524005715,1518129045,234960666,4068949643,2801452548,241654616,1511695319,2795285062,4074853065,214796352,1487958223,2755033438,4031480273,1490427021,212591618,4029541779,2756711708,2767888858,4035402069,201412804,1484564555,4041291031,2761739672,1478149129,208092294,1498393989,221402378,4055129243,2781455380,223623496,1495908807,2779760726,4057084121,4051207199,2768600208,1501787393,234786190,2774733010,4045334621,228123084,1508186435,4096598575,2689653408,1557582641,145435582,2687940322,4098575981,147671036,1555087219,1545210805,141030202,4108450475,2694578724,134324088,1551656951,2700766822,4102526697,2712602602,4124245861,156563188,1562971771,4122252071,2714332072,1565483577,154311350,160968304,1575343871,2707677038,4112394209,1568914109,167658034,4118301603,2701505324,1596549541,190091562,4157774011,2746179636,187891048,1599014375,2747862134,4155831545,4145954879,2741221552,1608888609,194529710,2735068402,4151848061,201205228,1602477411,178998368,1591129327,2723200382,4130162161,1588648109,181215266,4132121011,2721501500,2728158714,4141981045,174560484,1578789995,4136104247,2734295480,1585184809,167901350 }, + { 0,1249898853,2499797706,3732935599,739488613,1718370816,3102495151,4069761226,1478977226,307795887,3436741632,2259121509,1949619631,1045112010,3771414373,2863973888,2957954452,4197530865,615591774,1859051067,2623373041,3592589204,144874555,1121807710,3899239262,2719373883,2090224020,921286897,3296335931,2382752094,1350957809,452594580,1701965273,789454012,4052619027,3153198710,1231183548,52277209,3718102134,2548190483,1029081875,1999207030,2846452185,3822491836,289749110,1530579219,2243615420,3485805529,3577684045,2671825192,1103151751,197080034,4180448040,3008586317,1842573794,665616519,2367178375,3345463266,434611277,1402492200,2701915618,3950249095,905189160,2139874893,3403930546,2157718231,1578908024,342083613,3874515159,2895092146,1913621021,946895736,2462367096,3636153373,104554418,1279569623,3201764893,4104716152,707325143,1616321970,2058163750,819128131,3998414060,2754413961,1455334723,482432038,3259058057,2285811436,579498220,1760919945,3061158438,4228539203,244958089,1155937004,2590384451,3491352614,2945594987,3857565454,997053601,1897014724,2206303502,3388896363,394160068,1560385185,4155855009,3184173508,1665839723,691356430,3685147588,2446922401,1331233038,86437995,534576127,1436748442,2334333237,3244091472,869222554,2041625087,2804984400,3981400885,1207672117,226782288,3540287487,2575011482,1810378320,563601205,4279749786,3043507711,2418786709,3662950640,81011551,1319883322,3157816048,4131881877,684167226,1656250719,3356272479,2188596794,1559446933,378320112,3827242042,2925585759,1893791472,983500693,543493121,1780153700,3030052555,4276428718,209108836,1175014913,2559139246,3539381451,2017618635,842898350,3971844097,2797762916,1414650286,506341579,3232643940,2329004545,4116327500,3206929705,1638256262,735723491,3645480745,2469817932,1303805411,130649222,2910669446,3875716067,964864076,1945983273,2171533795,3406891142,361831209,1609493068,1158996440,258674877,3521839890,2610229879,1762087613,595108824,4260933751,3079094546,489916178,1464628855,2311874008,3283326141,824194167,2069873938,2782910141,4020250584,1523063335,280488770,3459774701,2219313544,1994107202,1017403431,3794029448,2824583917,49249517,1217432968,2517671463,3698290498,788320136,1686322925,3120770370,4034714663,3934705587,2700682966,2121872761,872858652,3331679446,2364183987,1382712860,404060025,2996941177,4175314972,643716019,1814143702,2662466076,3570267001,172875990,1077023155,1069152254,1975912091,2873496884,3778667601,329925787,1507177982,2270537297,3442104116,1738445108,769744977,4083250174,3105784475,1267540561,32690996,3748839579,2500669950,2415344234,3314076431,453564576,1366763973,2749663503,3919280234,924543941,2103745184,3620756640,2645536197,1127202410,156258063,4223922117,2981895840,1866206479,625212522 }, + { 0,633075163,1266150326,1858870893,2532300652,3008635575,3717741786,4163094785,674486313,227028466,1665414047,1191167556,3202092869,2607282846,4121683187,3490713896,1348972626,1977369993,454056932,1051438655,3330828094,3811807973,2382335112,2823059795,2018797691,1575984544,857965517,379090454,4005281559,3405793996,2781631649,2155323770,2697945252,2239010175,3954739986,3456335561,908113864,328942099,2102877310,1491904933,2298263693,2907131222,3280687931,3861948128,504590305,1000905274,1432650839,1893691788,4037595382,3574801709,3151969088,2657406619,1715931034,1140650561,758180908,143333879,3634039007,4246797572,2481775465,3059160754,1316282291,1808738920,84096005,548979166,1148368825,1640579682,252009487,717138388,3533529301,4146500878,2582285155,3159457464,1816227728,1241160267,657884198,42824189,4205754620,3742715175,2983809866,2489493137,336922603,833548848,1600318557,2061048198,2197475463,2806064476,3381476145,3963014890,1009180610,429730329,2001810548,1391116719,2865301678,2406677877,3787383576,3288667843,3837646621,3238404806,2949266603,2322712944,1917976689,1474950570,958786503,480124444,3431862068,3912628975,2281301122,2722238809,1516361816,2145004931,286667758,883803701,3034212175,2439090836,4289563897,3658905890,573943843,126764536,1765956501,1291431502,2632564582,3109178045,3617477840,4062552331,168192010,800955857,1097958332,1690990183,2296737650,2908658345,3281159364,3861475615,504018974,1001475525,1434276776,1892066931,2698426203,2238530176,3953220845,3457853750,909729847,327325164,2102299521,1492483674,3632455456,4248382203,2482320534,3058614605,1315768396,1809251735,85648378,547427873,4038133513,3574264530,3150376127,2658998628,1717489765,1139090878,757677011,143838728,673845206,227670541,1667097696,1189482939,3200637114,2608737633,4122096396,3490301655,1693695,631382564,1265515593,1859504530,2532704403,3008230728,3716279077,4164558590,2018361220,1576421983,859460658,377594345,4003621096,3407453491,2782233438,2154722949,1350461357,1975882358,453610523,1051883968,3331436737,3811198234,2380684151,2824711852,3432503499,3911986448,2279617405,2723923622,1517817767,2143550076,286254097,884216266,3835953378,3240097081,2949901140,2322079375,1917573006,1475355221,960248888,478661091,2633001113,3108740418,3615982383,4064048884,169852917,799296046,1097356355,1691591064,3032723632,2440578411,4290009862,3658460893,573335516,127373831,1767607402,1289779633,1817753711,1239633332,657413081,43296258,4206325507,3742145240,2982184117,2491117934,1147887686,1641059741,253529072,715619883,3531913002,4148118257,2582863004,3158878535,1010763837,428146150,2001265547,1391662672,2865815377,2406165130,3785831655,3290218812,336384020,834086351,1601911714,2059456121,2195916664,2807624355,3381980366,3962509589 } +}; +const uint32_t crc32c_4k[4][256] = { + { 0,3265640030,2158434893,1107471379,77742699,3322410037,2214942758,1184951928,155485398,3420533384,2313395867,1262889157,233227965,3477303523,2369903856,1340369582,310970796,3492593650,2452493281,1351329215,371936199,3566140825,2525778314,1412032468,466455930,3647486756,2607454007,1506746729,527421201,3721034063,2680739164,1567449858,621941592,3887572230,2780104981,1729150795,565203251,3809863533,2702658430,1672674592,743872398,4008911312,2901511619,1851014045,687134181,3931202491,2824064936,1794537974,932911860,4114525354,3074162873,1973008103,859396255,4053593793,3013493458,1899754636,1054842402,4235864188,3195569263,2094871089,981326921,4174932503,3134899716,2021617754,1243883184,2290192622,3397598461,136743587,1317430491,2351157893,3458301590,210028744,1130406502,2177176632,3284645931,23203445,1203953677,2238142035,3345349184,96488478,1487744796,2584254786,3624547665,447709967,1544514935,2661997353,3702028090,504217956,1374268362,2471239060,3511595399,334170073,1431038369,2548981759,3589075948,390677938,1865823720,2912125878,4019269541,758422011,1804892035,2838610397,3946016206,697752464,1718792510,2765555552,3872762739,611327277,1657860949,2692039947,3799509272,550657862,2109684804,3206187546,4246218249,1069387863,2031975983,3149449329,4189742178,991941180,1962653842,3059617484,4099711711,922293377,1884945145,3002879143,4043235508,844846826,2487766368,1458436926,351229741,3595231603,2431258379,1380956501,273487174,3538461464,2634860982,1604943848,497800187,3742262693,2578353117,1527463299,420057488,3685492686,2260813004,1147466386,107372161,3301173471,2187527847,1086763257,46406890,3227626164,2407907354,1293973060,253942359,3448204297,2334622321,1233269807,192976956,3374657122,2975489592,1946151014,838681717,4082692651,3052936275,2002627085,895419934,4160401472,3089029870,2059103408,951697571,4196169469,3166476421,2115579611,1008435912,4273878166,2748536724,1635181002,594824665,3788635015,2809206271,1708434337,668340146,3849566700,2862076738,1748133148,707840271,3902111569,2922746153,1821386615,781355876,3963043130,3731647440,482991502,1590391197,2624505795,3670944187,409706469,1516844022,2563540392,3609784070,361584984,1469052235,2502574869,3549080941,288299827,1395504928,2441609598,3437585020,239129634,1279424561,2397556335,3360104471,182621769,1222654554,2319813636,3315721898,117723380,1158085863,2275625657,3238241473,61215391,1101315724,2197883090,4219369608,970706646,2077844165,3111965851,4292623075,1031376061,2138775726,3185481456,4063951966,815745536,1922950675,2956480589,4137205301,876415083,1983882360,3029996070,3925307684,726845306,1766878057,2885016887,3981783887,804291857,1844586754,2941755228,3769890290,571884460,1611984831,2729531873,3826366361,649331143,1689693652,2786270090 }, + { 0,763161649,1526323298,2005218387,3052646596,2559532277,4010436774,3262547095,1846220665,1131936584,888327963,428745514,3690506173,4135865228,2164359135,2893911022,3692441330,4050305731,2263873168,2878544545,1776655926,1150906887,857491028,509651557,2988259723,2673989050,3907314153,3315076568,133073231,714237310,1561809197,1886108956,3183487765,2428290852,3879334775,3393527622,137599953,625965024,1388987315,2142678914,3553311852,4273459293,2301813774,2756577343,1714982056,1262772377,1019303114,297646331,1641416167,1286269398,992992645,374550964,3559240995,4183382290,2396810561,2745205104,266146462,581041839,1428474620,2019043021,3123618394,2538753643,3772217912,3450574345,2121015515,1393609962,613808313,166270088,3416231967,3873668142,2439399549,3155862604,275199906,1025235859,1251930048,1742865393,2777974630,2296933207,4285357828,3524375349,2725908009,2399592984,4169389643,3590273658,394903277,989156060,1299211919,1611434686,3429964112,3775788385,2525544754,3153341699,2038606228,1425950117,595292662,235380167,3282832334,4006668287,2572538796,3022602141,1985985290,1529042747,749101928,31100761,2913410231,2161897606,4150183125,3659671780,408202355,891830338,1118663697,1876006944,532292924,851888397,1162083678,1748963695,2856949240,2268428745,4038086042,3721175467,1907438149,1556995700,726198823,104072726,3292693121,3913182896,2663078627,3016210130,4242031030,3517230471,2787219924,2338158053,1227616626,1683430723,332540176,1051641121,2463323855,3215964926,3358232237,3847643804,656467467,173804090,2111389289,1353044568,550399812,229802869,2050471718,1464556311,2503860096,3091280817,3485730786,3803769811,1321564221,1673106444,339517535,960515182,4214671609,3595183304,2714701979,2360605866,1092119203,1818527378,467776193,916283120,4109097575,3650565718,2920415749,2205085236,789806554,40866283,1978312120,1486244233,2598423838,3080462639,3222869372,3982883149,2634957905,2960304224,3354893363,3935006722,687731861,92346532,1912876279,1601749190,4077212456,3732520729,2851900234,2223007611,1190585324,1804210141,470760334,829675455,2192859501,2949156188,3628972303,4113651006,927453609,440090008,1841170891,1086514682,3971970580,3250821669,3058085494,2604286535,1498203856,1949313761,62201522,784986755,1587695519,1943970734,73111549,690453452,3948019547,3324842858,2980587321,2631191304,816404710,500544727,1783660676,1194093749,2237327394,2821063699,3752013888,4074757233,1064585848,302556745,1703776794,1223786027,2324167356,2818250381,3497927390,4244819695,1367301377,2080616752,193365347,653945170,3834441157,3387949556,3195352487,2466896278,3814876298,3458107579,3113991400,2498187481,1452397646,2079144063,208145452,555016221,2372498419,2685771714,3616582545,4209788832,949666615,367406854,1650662229,1327495012 }, + { 0,4233950621,4250246603,17393750,4282862951,52148474,34787500,4266534193,4217564223,121510306,104296948,4201350249,69575000,4168701125,4184882323,86821134,4079595151,259349266,243020612,4062234329,208593896,4029814389,4047207971,224889790,139150000,4095194925,4112441211,155331302,4144762839,189856330,173642268,4127549313,3820956655,535027314,518698532,3803595705,486041224,3768881941,3786275651,502337246,417187792,3833672269,3850918427,433368966,3885664951,465993514,449779580,3868451553,278300000,3972690173,3988986027,295693622,4023502855,328023450,310662604,4007174225,3958663519,396926146,379712660,3942449417,347284536,3908030885,3924212211,364530798,3264356655,1053742258,1070054628,3281734009,1037397064,3247020501,3229675907,1021051934,972082448,3316398221,3299168475,955884870,3333914743,988509674,1004674492,3351177249,834375584,3454499389,3438154347,817031158,3472671431,849360730,866737932,3488983697,3403244447,914724354,931987028,3419409353,899559160,3384990565,3368792883,882329262,556600000,3715235677,3698890507,539255446,3731507111,574009914,591387244,3747819505,3662669567,638784354,656046900,3678834345,621325208,3646184965,3629987411,604095438,3523519567,777540050,793852292,3540896793,759425320,3508477109,3491132643,743080318,694569072,3577396717,3560166843,678371366,3592488215,712896650,729061596,3609750849,2160604335,2090123570,2107484516,2176933113,2140109256,2211679317,2195383299,2122715550,2074794128,2281057549,2264876379,2057547974,2230162935,2024890474,2042103868,2246376865,1944164896,2411556797,2394163179,1927869046,2359744327,1895441114,1911769740,2377105169,2290316831,1960805250,1977019348,2307530313,2009348984,2342047461,2324801203,1993167662,1668751168,2670455517,2653061771,1652455190,2620412455,1617733562,1634062316,2637773425,2551575423,1682507490,1698721460,2568788777,1733475864,2601405317,2584159187,1717294670,2422125007,1812087890,1829448708,2438453657,1863974056,2470775093,2454479203,1846580478,1799118320,2539694189,2523512891,1781872038,2491093143,1747445002,1764658524,2507307201,1113200000,3188121629,3205466187,1129545174,3172817127,1094823290,1078510892,3155439793,3107518911,1164184610,1148019828,3090256361,1182774488,3122872645,3140102419,1198972046,2977151759,1294945938,1277568708,2960839513,1312093800,2993161205,3009506211,1329438270,1242650416,3058541229,3074738939,1259880294,3042318935,1225453514,1208190876,3026153985,2716155503,1572457458,1555080100,2699843129,1587704584,2734589589,2750934723,1605049182,1518850640,2799380429,2815578011,1536080390,2780864311,1503423146,1486160636,2764699489,1389138144,2928698749,2946043179,1405483190,2911624583,1373055002,1356742732,2894247377,2846784735,1441958210,1425793300,2829522057,1458123192,2864038949,2881268851,1474320878 }, + { 0,75243439,150486878,209985777,300973756,361521427,419971554,494165581,601947512,664593111,723042854,795139465,839943108,913087595,988331162,1049928501,1203895024,1136518495,1329186222,1262868993,1446085708,1380817891,1590278930,1521853629,1679886216,1616713767,1826175190,1755654009,1976662324,1907189403,2099857002,2035636677,2407790048,2348804687,2273036990,2198328593,2658372444,2584712435,2525737986,2465704877,2892171416,2820609847,2761635782,2699503721,3180557860,3119475083,3043707258,2971096789,3359772432,3426619583,3233427534,3301322721,3652350380,3721293315,3511308018,3577106781,3953324648,4024364487,3814378806,3878081177,4199714004,4264465275,4071273354,4141263909,451648817,513245854,303276655,376421824,186377101,258472994,65264851,127910780,957046857,1031241702,838033175,898580664,687546101,747045210,537076139,612318724,1563060161,1498839150,1439848607,1370375984,1289361789,1218840274,1143088675,1079916940,2127207097,2058781974,1983030759,1917762120,1866130437,1799814058,1740823387,1673446644,2506647761,2434037630,2643482511,2582399008,2224559725,2162428354,2355112243,2283550364,3062404521,3002370566,3195054839,3121395032,2809719573,2735011002,2944455755,2885471204,3534328353,3604319630,3662785919,3727536848,3277450397,3341153074,3416380355,3487419500,4048121689,4113920246,4189147143,4258090920,3770225125,3838119498,3896585915,3963433236,903297634,833299917,1026491708,961747603,606553310,542858097,752843648,681796655,372754202,306960565,516945988,447997931,130529702,62629385,255821560,188979543,1914093714,1986715453,2062483404,2123554915,1676066350,1738187137,1797161328,1868734175,1375092202,1435116101,1494090420,1567759643,1074152278,1148869881,1224637448,1283613607,3126120322,3190345773,2997678300,3067146099,2879697214,2950213265,2740751968,2803929551,2578723578,2647141717,2437680548,2502955531,2286177350,2352501737,2159833880,2227203255,4254414194,4192807645,4117563948,4044428675,3966061518,3893974113,3835524240,3772869439,3732260874,3658078117,3599628116,3539069179,3481646774,3422136601,3346893288,3271661127,792504147,725661948,667195405,599295906,1053612527,984663616,909436593,843643166,215767595,144721284,69494133,5798618,489432215,424688440,366222281,296223846,1761435043,1820410380,1610965757,1685683538,2030904095,2104573104,1911888961,1971913710,1260232923,1331806068,1139122053,1201242154,1525538407,1586610632,1377165625,1449787030,2696893107,2764262684,2823253485,2889577026,2974755855,3040031648,3115782993,3184200958,2204086219,2267263076,2343014549,2413530938,2460995959,2530463448,2589453865,2653680006,3883837507,3808606188,4018575133,3959064754,4136556287,4075997520,4269205921,4195022350,3298710843,3236055700,3429263973,3357177290,3580767111,3507631144,3717600473,3655994230 } +}; +const uint32_t crc32c_1M[4][256] = { + { 0,2339516652,319297321,2558142405,638594642,2908888766,890780027,3194620311,1277189284,3344067656,1596476301,3562699617,1781560054,3779215898,2033739231,4064957747,2554378568,322079140,2336796257,3841677,3192952602,891463670,2908258355,640331999,3563120108,1595069696,3345543877,1276822057,4067478462,2030238546,3782794391,1779100795,896336993,3189716109,644158280,2903974820,326969907,2551126751,7683354,2332495350,2035112133,4064241705,1782927340,3778510592,1599960727,3559868027,1280663998,3341242706,2905455913,643796421,3190139392,894933740,2336068475,5219223,2553644114,323466430,3775783309,1786761569,4060477092,2037892680,3340619743,1282408243,3558201590,1600645146,1792673986,3785898030,2043813867,4070584071,1288316560,3350730364,1606562233,3568304469,653939814,2911397002,905069391,3196089251,15366708,2342013656,333606173,2559598065,4070224266,2045280614,3784484515,1793103439,3565854680,1610133300,3347220721,1290844189,3199921454,902356418,2914187783,650169067,2561327996,332985232,2342704213,13690041,1605831843,3569695823,1287592842,3352111974,2040996593,4074050077,1789867480,3789358388,328683527,2565169387,10438446,2347595714,898072149,3203747513,646932860,2919061904,3354899947,1283818759,3573523138,1603113518,3790052281,1788193621,4075785360,2040380540,2346182991,10869155,2564816486,330157706,2915551005,649459697,3201290292,901636312,3585347972,1590042984,3334211245,1305359937,4087627734,2027294522,3769379071,1809717267,2576633120,317095372,2325502473,32402149,3213124466,888558494,2894885979,670975159,1307879628,3330709536,1593622501,3582889737,1810138782,3767973490,2028769719,4087259483,30733416,2326185092,316465985,2578371501,667212346,2897668822,885837075,3216965119,3772323301,1806378249,4090561228,2023961120,3335076791,1304103771,3586206878,1588796530,2902018369,663452077,3220266600,881028740,2330552083,26957823,2581688378,311640278,2023337133,4092304449,1804712836,3773008744,1586070271,3590042131,1300338134,3337856314,884600841,3217801445,665970464,2898515916,313122395,2581327543,27380082,2329147806,3211663686,874260906,2892369519,655638147,2575185684,302778360,2322997309,17043665,4081993186,2017228046,3762705099,1798595111,3579734960,1579965276,3327556761,1294224501,657367054,2891747554,874952487,3209988043,20876892,2320285360,305568117,2571413913,1796144298,3766275142,2013719427,4084521839,1293865720,3329024532,1578550737,3580163389,2315459879,24194507,2567637518,309934818,2886939509,660669337,3206227036,879301808,3324199299,1297183087,3576387242,1582917190,3761467345,1799446333,4080761080,2018068500,306422895,2570163331,21738310,2319025066,877890109,3206658769,660315412,2888412664,1583610059,3574712359,1298919394,3323584270,2020857497,4076988021,1803272624,3758747996 }, + { 0,2927908345,1491393795,4133521658,2982787590,525201407,3912066821,1202270972,1719599869,3371915012,1050402814,2417986055,3619076347,2033380610,2404541944,567685121,3439199738,1652183043,2484787449,983469312,2100805628,3551783429,634610431,2337748742,2860582663,67457790,4066761220,1558286333,457751809,3050105080,1135370242,3978835451,2618326277,848570620,3304366086,1785787903,769246979,2203947770,1966938624,3686354937,4201611256,1424697857,2727060219,202372866,1269220862,3844247559,323098877,3183889668,1357805823,4268371206,134915580,2794385413,3777479417,1336121088,3116572666,390547971,915503618,2551525371,1853204225,3237081848,2270740484,702322173,3753647367,1899514110,1036815611,2471024898,1697141240,3417048065,2349151997,578904836,3571575806,2053488135,1538493958,4114078719,56054533,2916288252,3933877248,1157521913,2996758787,471514362,4046620929,1605819640,2849395714,122814971,1090204423,4001326846,404745732,3063659517,2538441724,969530885,3483981567,1630339846,646197754,2281726979,2120281337,3504650496,2715611646,257467399,4181208317,1471969540,269831160,3197181441,1223792379,3866477314,3349410563,1764206330,2672242176,834894841,1986676997,3639483644,781095942,2148188671,1831007236,3282477565,902179079,2604825854,3706408450,1919884283,2215613185,713803512,190707449,2782503680,1404644346,4248665603,3130281215,336599302,3799028220,1291109381,2073631222,3575467023,595444981,2381943052,3394282480,1691678217,2461302515,1009789706,501619467,3009564402,1157809672,3951465457,2888802573,44823796,4106976270,1515137527,3076987916,434326005,4018389263,1091015926,112109066,2821387251,1581939465,4040044272,3508018929,2140949256,2315043826,662214155,1624351991,3461738766,943028724,2528193549,3884541171,1225601290,3211639280,300542985,1447091957,4173630220,245629942,2686473743,2180408846,796013559,3641883405,2006380276,809491464,2663090673,1759183115,3328136434,729243913,2247308528,1939061770,3709331955,2596199183,876252918,3260679692,1826509813,1292395508,3817616909,367836919,3144215310,4240562674,1380289547,2753889521,178344200,1180013837,3906060532,514934798,2956271095,4154208011,1494776562,2943939080,33335281,539662320,2393817609,2026785523,3595181834,2447584758,1063745551,3372740853,1736680716,2326499575,607110414,3528412660,2093684749,996289265,2514910984,1669789682,3439501835,3973353994,1112590323,3023064841,448010992,1562191884,4086922741,100267279,2877137142,3662014472,1958854129,2191602955,740647154,1804358158,3305637879,862490381,2649545460,3157977845,314490636,3839768566,1247437327,234049779,2742486282,1427607024,4220770313,381414898,3091183627,1314861297,3772474632,2809288692,167117325,4288056055,1360191246,1891954447,3728784118,673198604,2258921461,3238876425,1871249648,2582218762,929947123 }, + { 0,4147262444,3951563049,481960645,3539752099,634283855,963921290,3460724326,2685722551,1462168667,1268567710,3165584754,1927842580,2245703928,2573244989,1850911185,1170590111,3002595955,2924337334,1501555546,2537135420,1611378384,2092010517,2340667385,3855685160,316876228,240715521,4184552685,925713035,3223286119,3701822370,731340878,2341180222,2092540114,1610842647,2536616443,1501022109,2923820145,3003111092,1171121496,731860105,3702357861,3222756768,925199948,4184021034,240200646,317393155,3856218863,3461241505,964454733,633752456,3539236964,481431042,3951050222,4147781419,535751,1851426070,2573776634,2245170239,1927325651,3165049269,1268048473,1462681756,2686251888,318460045,3855180641,4185080228,239170120,3221685294,926234562,730797319,3703383787,3002044218,1172159702,1499962899,2924850687,1611914137,2535581813,2342242992,2091514204,1463720210,2685184766,3166079035,1266990039,2244136369,1928396381,1850399896,2574839668,4146742949,1602889,480401292,3952108640,634786310,3538166250,3462267695,963391683,2574304179,1849880671,1928909466,2244665718,1267504912,3166610684,2684651065,1463203285,962862084,3461754856,3538685229,635322049,3952625831,480934731,1071502,4146227810,3702852140,730282432,926751493,3222218985,239689359,4185615715,3854651302,317946954,2090980763,2341725815,2536096946,1612445534,2925363512,1500492500,1171623953,3001525245,636920090,3536098038,3464409139,961315807,4144690617,3720789,478340240,3954235260,2246213293,1926253889,1852469124,2572704872,1461594638,2687244770,3163962151,1269041355,1613981829,2533448553,2344319404,2089372224,2999925798,1174212554,1497836815,2926911203,3223828274,924157150,732931611,3701315063,316400529,3857305725,4183028408,241287508,2927440420,1498350024,1173693197,2999390433,2088855175,2343785835,2533980078,1614496834,241823123,4183547519,3856792762,315871062,3700799792,732400348,924690457,3224345589,3954768827,478857303,3205778,4144159102,960802584,3463879924,3536633393,637439453,1269572620,3164477408,2686727461,1461061321,2572185775,1851933507,1926783366,2246726250,923660695,3225404027,3699761342,733467474,3857818932,314808024,242856989,4182476785,2535009824,1613438412,2089893641,2342718693,1172667011,3000453487,2926406570,1499420742,1925724168,2247756772,2571118881,1852971725,2687790251,1460035399,1270644098,3163442798,3537692607,636408915,961869462,3462841722,2143004,4145185008,3953697333,479891929,3162923689,1270108485,1460564864,2688303212,1853502986,2571634150,2247239459,1925190863,479378718,3953168114,4145720375,2662363,3463375293,962386513,635893908,3537161080,4181961526,242325722,315341343,3858336243,734003093,3700280441,3224891068,923131216,1498903681,2925873005,3000985000,1173182020,2343247906,2090406862,1612919051,2534474471 }, + { 0,1273840180,2547680360,3694642780,710508065,1639201813,3179543113,4134451325,1421016130,526368374,3278403626,2290432542,2129363555,889634903,3912304139,2732344383,2842032260,3800611504,1052736748,1968324312,2201781925,3369190545,350618317,1594573049,4258727110,3057272562,1779269806,568378010,3616439015,2623748307,1079312015,196721851,1462208505,483050957,3237806993,2333098405,2105473496,915651564,3936648624,2705932164,60128187,1215838607,2488270803,3751984615,701236634,1646348206,3189146098,4126917574,4265770877,3048160585,1771633429,578140449,3558539612,2683716456,1136756020,137152256,2867888959,3776823563,1026164567,1992770915,2158624030,3410280234,393443702,1553873730,2924417010,3852619206,966101914,1920518574,2216063443,3489346535,332199355,1478604687,4210946992,2970661252,1831303128,650786284,3500445073,2605305765,1199442425,210979789,120256374,1288156482,2431677214,3676123434,762546519,1721682787,3131641151,4047785739,1402473268,410339584,3292696412,2410663272,2042721557,841758497,3994808701,2784408393,4184377355,2995112511,1857162339,627002967,3543266858,2564600862,1156280898,252063862,2916774985,3862378109,973140001,1911403029,2273512040,3429779548,274304512,1538575412,1343058063,467677883,3352818919,2352658131,2052329134,834227354,3985541830,2791557362,79662285,1330827001,2472872101,3632810641,786887404,1695264984,3107747460,4073796784,1500670229,312421153,3467177341,2235936585,1932203828,952521984,3841037148,2937901416,230724951,1177409379,2585399615,3522646795,664398710,1819584834,2957209374,4222496042,4028076433,3153777573,1741493753,740317133,3662606256,2443423108,1301572568,108603884,2762304979,4014485479,864020923,2022878095,2398884850,3306246598,421959578,1389090222,240512748,1169730776,2576312964,3529648304,604803277,1877070585,3017151653,4164638353,1525093038,285888666,3443365574,2261832946,1891527823,995307195,3882150119,2894703315,2804946536,3973928028,820679168,2064109620,2372495433,3330550397,447999009,1365159445,4085443114,3094325278,1683516994,800402550,3655046155,2453067327,1308692579,99373655,4147996391,3167757523,1625809551,722116795,3714324678,2525584114,1254005934,22273690,2744097445,3898792081,877993677,2142788857,2312561796,3258689200,504127724,1440817880,1582866019,364239959,3380746763,2188335167,1946280002,1072472694,3822806058,2822120990,183132705,1090986005,2637227593,3604849789,548609024,1801346612,3077150824,4236565084,2686116126,3958874922,935355766,2083333954,2319687487,3249462539,496573271,1450465635,4104658268,3208994664,1668454708,681564928,3740361597,2501648713,1227613973,46572833,159324570,1116887982,2661654002,3578322886,589719483,1758143887,3036472275,4279345639,1573774808,371238892,3390529968,2180653956,2006227961,1014618573,3763216273,2879610277 } +}; +const uint32_t crc32c_1G[4][256] = { + { 0,274646895,549293790,820201905,1098587580,1361435347,1640403810,1905808397,2197175160,2460548119,2722870694,2987750089,3280807620,3553878443,3811616794,4084100981,1,274646894,549293791,820201904,1098587581,1361435346,1640403811,1905808396,2197175161,2460548118,2722870695,2987750088,3280807621,3553878442,3811616795,4084100980,2,274646893,549293788,820201907,1098587582,1361435345,1640403808,1905808399,2197175162,2460548117,2722870692,2987750091,3280807622,3553878441,3811616792,4084100983,3,274646892,549293789,820201906,1098587583,1361435344,1640403809,1905808398,2197175163,2460548116,2722870693,2987750090,3280807623,3553878440,3811616793,4084100982,4,274646891,549293786,820201909,1098587576,1361435351,1640403814,1905808393,2197175164,2460548115,2722870690,2987750093,3280807616,3553878447,3811616798,4084100977,5,274646890,549293787,820201908,1098587577,1361435350,1640403815,1905808392,2197175165,2460548114,2722870691,2987750092,3280807617,3553878446,3811616799,4084100976,6,274646889,549293784,820201911,1098587578,1361435349,1640403812,1905808395,2197175166,2460548113,2722870688,2987750095,3280807618,3553878445,3811616796,4084100979,7,274646888,549293785,820201910,1098587579,1361435348,1640403813,1905808394,2197175167,2460548112,2722870689,2987750094,3280807619,3553878444,3811616797,4084100978,8,274646887,549293782,820201913,1098587572,1361435355,1640403818,1905808389,2197175152,2460548127,2722870702,2987750081,3280807628,3553878435,3811616786,4084100989,9,274646886,549293783,820201912,1098587573,1361435354,1640403819,1905808388,2197175153,2460548126,2722870703,2987750080,3280807629,3553878434,3811616787,4084100988,10,274646885,549293780,820201915,1098587574,1361435353,1640403816,1905808391,2197175154,2460548125,2722870700,2987750083,3280807630,3553878433,3811616784,4084100991,11,274646884,549293781,820201914,1098587575,1361435352,1640403817,1905808390,2197175155,2460548124,2722870701,2987750082,3280807631,3553878432,3811616785,4084100990,12,274646883,549293778,820201917,1098587568,1361435359,1640403822,1905808385,2197175156,2460548123,2722870698,2987750085,3280807624,3553878439,3811616790,4084100985,13,274646882,549293779,820201916,1098587569,1361435358,1640403823,1905808384,2197175157,2460548122,2722870699,2987750084,3280807625,3553878438,3811616791,4084100984,14,274646881,549293776,820201919,1098587570,1361435357,1640403820,1905808387,2197175158,2460548121,2722870696,2987750087,3280807626,3553878437,3811616788,4084100987,15,274646880,549293777,820201918,1098587571,1361435356,1640403821,1905808386,2197175159,2460548120,2722870697,2987750086,3280807627,3553878436,3811616789,4084100986 }, + { 0,16,32,48,64,80,96,112,128,144,160,176,192,208,224,240,256,272,288,304,320,336,352,368,384,400,416,432,448,464,480,496,512,528,544,560,576,592,608,624,640,656,672,688,704,720,736,752,768,784,800,816,832,848,864,880,896,912,928,944,960,976,992,1008,1024,1040,1056,1072,1088,1104,1120,1136,1152,1168,1184,1200,1216,1232,1248,1264,1280,1296,1312,1328,1344,1360,1376,1392,1408,1424,1440,1456,1472,1488,1504,1520,1536,1552,1568,1584,1600,1616,1632,1648,1664,1680,1696,1712,1728,1744,1760,1776,1792,1808,1824,1840,1856,1872,1888,1904,1920,1936,1952,1968,1984,2000,2016,2032,2048,2064,2080,2096,2112,2128,2144,2160,2176,2192,2208,2224,2240,2256,2272,2288,2304,2320,2336,2352,2368,2384,2400,2416,2432,2448,2464,2480,2496,2512,2528,2544,2560,2576,2592,2608,2624,2640,2656,2672,2688,2704,2720,2736,2752,2768,2784,2800,2816,2832,2848,2864,2880,2896,2912,2928,2944,2960,2976,2992,3008,3024,3040,3056,3072,3088,3104,3120,3136,3152,3168,3184,3200,3216,3232,3248,3264,3280,3296,3312,3328,3344,3360,3376,3392,3408,3424,3440,3456,3472,3488,3504,3520,3536,3552,3568,3584,3600,3616,3632,3648,3664,3680,3696,3712,3728,3744,3760,3776,3792,3808,3824,3840,3856,3872,3888,3904,3920,3936,3952,3968,3984,4000,4016,4032,4048,4064,4080 }, + { 0,4096,8192,12288,16384,20480,24576,28672,32768,36864,40960,45056,49152,53248,57344,61440,65536,69632,73728,77824,81920,86016,90112,94208,98304,102400,106496,110592,114688,118784,122880,126976,131072,135168,139264,143360,147456,151552,155648,159744,163840,167936,172032,176128,180224,184320,188416,192512,196608,200704,204800,208896,212992,217088,221184,225280,229376,233472,237568,241664,245760,249856,253952,258048,262144,266240,270336,274432,278528,282624,286720,290816,294912,299008,303104,307200,311296,315392,319488,323584,327680,331776,335872,339968,344064,348160,352256,356352,360448,364544,368640,372736,376832,380928,385024,389120,393216,397312,401408,405504,409600,413696,417792,421888,425984,430080,434176,438272,442368,446464,450560,454656,458752,462848,466944,471040,475136,479232,483328,487424,491520,495616,499712,503808,507904,512000,516096,520192,524288,528384,532480,536576,540672,544768,548864,552960,557056,561152,565248,569344,573440,577536,581632,585728,589824,593920,598016,602112,606208,610304,614400,618496,622592,626688,630784,634880,638976,643072,647168,651264,655360,659456,663552,667648,671744,675840,679936,684032,688128,692224,696320,700416,704512,708608,712704,716800,720896,724992,729088,733184,737280,741376,745472,749568,753664,757760,761856,765952,770048,774144,778240,782336,786432,790528,794624,798720,802816,806912,811008,815104,819200,823296,827392,831488,835584,839680,843776,847872,851968,856064,860160,864256,868352,872448,876544,880640,884736,888832,892928,897024,901120,905216,909312,913408,917504,921600,925696,929792,933888,937984,942080,946176,950272,954368,958464,962560,966656,970752,974848,978944,983040,987136,991232,995328,999424,1003520,1007616,1011712,1015808,1019904,1024000,1028096,1032192,1036288,1040384,1044480 }, + { 0,1048576,2097152,3145728,4194304,5242880,6291456,7340032,8388608,9437184,10485760,11534336,12582912,13631488,14680064,15728640,16777216,17825792,18874368,19922944,20971520,22020096,23068672,24117248,25165824,26214400,27262976,28311552,29360128,30408704,31457280,32505856,33554432,34603008,35651584,36700160,37748736,38797312,39845888,40894464,41943040,42991616,44040192,45088768,46137344,47185920,48234496,49283072,50331648,51380224,52428800,53477376,54525952,55574528,56623104,57671680,58720256,59768832,60817408,61865984,62914560,63963136,65011712,66060288,67108864,68157440,69206016,70254592,71303168,72351744,73400320,74448896,75497472,76546048,77594624,78643200,79691776,80740352,81788928,82837504,83886080,84934656,85983232,87031808,88080384,89128960,90177536,91226112,92274688,93323264,94371840,95420416,96468992,97517568,98566144,99614720,100663296,101711872,102760448,103809024,104857600,105906176,106954752,108003328,109051904,110100480,111149056,112197632,113246208,114294784,115343360,116391936,117440512,118489088,119537664,120586240,121634816,122683392,123731968,124780544,125829120,126877696,127926272,128974848,130023424,131072000,132120576,133169152,134217728,135266304,136314880,137363456,138412032,139460608,140509184,141557760,142606336,143654912,144703488,145752064,146800640,147849216,148897792,149946368,150994944,152043520,153092096,154140672,155189248,156237824,157286400,158334976,159383552,160432128,161480704,162529280,163577856,164626432,165675008,166723584,167772160,168820736,169869312,170917888,171966464,173015040,174063616,175112192,176160768,177209344,178257920,179306496,180355072,181403648,182452224,183500800,184549376,185597952,186646528,187695104,188743680,189792256,190840832,191889408,192937984,193986560,195035136,196083712,197132288,198180864,199229440,200278016,201326592,202375168,203423744,204472320,205520896,206569472,207618048,208666624,209715200,210763776,211812352,212860928,213909504,214958080,216006656,217055232,218103808,219152384,220200960,221249536,222298112,223346688,224395264,225443840,226492416,227540992,228589568,229638144,230686720,231735296,232783872,233832448,234881024,235929600,236978176,238026752,239075328,240123904,241172480,242221056,243269632,244318208,245366784,246415360,247463936,248512512,249561088,250609664,251658240,252706816,253755392,254803968,255852544,256901120,257949696,258998272,260046848,261095424,262144000,263192576,264241152,265289728,266338304,267386880 } +}; +const uint32_t crc32c_1T[4][256] = { + { 0,3178201592,2134078721,3260871929,4268157442,1124690938,2169872131,1010441979,4179731189,1145971469,2249381876,998069772,122112247,3123235087,2020883958,3306929166,4155454235,1254142691,2291942938,905168866,164223257,3030800609,1996139544,3415551456,244224494,3017871382,1908270319,3436340503,4041767916,1300757012,2413498093,850693909,3937538247,1474138431,2508285382,686744638,349502149,2847636285,1810337732,3599240764,328446514,2935763914,1822476083,3520022219,3992279088,1352325576,2462461233,799648969,488448988,2691867172,1647204061,3745634085,3816540638,1578387494,2622012639,556219687,3829170473,1498611921,2601514024,643855824,442133291,2805328595,1701387818,3624312786,3498596223,1843910279,2948276862,315925382,787398013,2474720389,1373489276,3971107204,699004298,2496033906,1452966027,3958702451,3620675464,1788911216,2835114633,362015601,656893028,2588468636,1477710181,3850080413,3644952166,1680740254,2792553319,454916767,3724986001,1667843945,2704651152,475673192,543173779,2635050347,1599297938,3795638378,976897976,2270545472,1158230713,4167480129,3294408122,2033396802,3144669371,100686147,3273385293,2121557173,3156774988,21434804,1031606095,2148699831,1112439374,4280417206,3449124003,1895495003,2997223842,264863834,871603873,2392596313,1287711648,4054805080,884266582,2312853422,1267180375,4142408367,3402775636,2008923564,3051440469,143575213,2768033807,429087223,3687820558,1721773302,1520054797,3891639285,631850764,2563163892,1574796026,3769826050,586027003,2676067843,2746978552,517214464,3699959289,1642554369,1398008596,3996936940,744529429,2433687533,2905932054,274366702,3523638295,1869215215,2859616737,387827737,3577822432,1747893528,1410638819,3917160987,724031202,2521323290,1313786056,4079044912,830324169,2350005297,2955420362,222798642,3474675659,1920259635,3077532221,167832517,3361480508,1966317252,1225359423,4100325831,909833534,2337633478,3118595027,76446251,3335687890,2075987754,1200034257,4209545257,951346384,2245780776,1086347558,4256159966,1072901159,2191306207,3198595876,63517404,3247818277,2096777181,1953795952,3373993608,189266545,3056106377,2316461426,930997386,4112584819,1213108619,2371169669,809151613,4066793604,1326045564,1932773255,3462153855,201372294,2976854910,2212215915,1051999635,4243114346,1099384978,2109560425,3235043217,42869608,3219235472,2063212190,3348471654,97086367,3097946727,2224878748,972256612,4222583197,1186988133,2663817143,598285903,3790990006,1553623886,1621128629,3721393229,529727668,2734457164,1743207746,3666394298,416565315,2780547515,2575423296,619599544,3870466625,1541219257,1768533164,3557174612,375052717,2872399957,2534360750,710985558,3896259503,1431548503,2420641369,757567393,4017847128,1377106592,1848566875,3544278435,287150426,2893156514 }, + { 0,1276495599,2552991198,3560852273,901475661,2041490338,2911953043,3783599740,1802951322,660806773,4082980676,3209204139,1590540247,316174648,3336976905,2331245798,3605902644,2599973851,1321613546,47447557,3814119545,2940411542,2071811495,929600328,3181080494,4052658497,632349296,1772430495,2283799267,3291857932,269193021,1545488850,2822184089,3827489398,807178567,2080987048,2643227092,3516512059,94895114,1236417253,3275867651,2404647148,1533692893,394235186,4143622990,3136253345,1859200656,583327871,2128259501,852455234,3874563187,2867126940,1264698592,125043215,3544860990,2673840081,363623223,1505342936,2374500073,3247585286,538386042,1812125845,3090977700,4096349515,1434603459,429361452,3450454557,2176582898,1614357134,741139553,4161974096,3020384703,1056216409,1927369654,2799638663,3939163752,189790228,1197096699,2472834506,3748770597,2205154039,3480894488,457471785,1464971718,3067385786,4206973269,788470372,1659559051,3893960813,2752308866,1882369459,1009216348,3718401312,2444725199,1166655742,161220113,4256519002,2980091317,1704910468,696981611,3356376599,2216425720,1344648137,472937766,2529397184,3671478063,250086430,1123926769,2742609037,4016906850,995322195,2001121212,727246446,1733107841,3010685872,4284919135,518228771,1391873484,2261255933,3403530258,1076772084,205257243,3624251690,2484107205,1972720057,964728662,3988708455,2712345224,2869206918,3876673897,858722904,2134561975,2663379659,3534369828,110395157,1250015738,3228714268,2355594227,1482279106,340528685,4123600977,3118263998,1843570063,569860960,2112432818,838659165,3854739308,2849464707,1213351935,71794960,3497642529,2624326862,379580456,1519007431,2394193398,3265379097,589602149,1865505674,3138326715,4145731156,53707551,1327908336,2602045121,3608004654,914943570,2057119933,2929943436,3803620707,1749375365,609263466,4033795163,3162182324,1576940744,300675623,3319118102,2311094265,3588109867,2580279492,1307950069,31489306,3764738918,2893061513,2018432696,878383191,3198741681,4072483422,646144367,1788258176,2333311484,3339077395,322440226,1596836557,4270248005,2995984042,1722637723,716741492,3409820936,2267577319,1393963222,520353337,2515536607,3655715888,232490753,1104036334,2689296274,3965624701,945875532,1953836195,678126961,1686021022,2957043887,4233440832,500172860,1371918035,2247853538,3387835149,1126023147,252213508,3677762101,2535716058,1990644390,984814665,4002242424,2727909783,1454492892,446958131,3466215682,2190444525,1661641105,790587262,4213255247,3073698464,1036457542,1909641385,2783746968,3925433719,142375691,1147780580,2421683925,3695325242,2153544168,3427385095,410514486,1415721689,3051820197,4193440330,768383355,1641635732,3945440114,2805949853,1929457324,1058334787,3734097471,2458126544,1186612193,179275022 }, + { 0,1407535613,2815071226,4096776711,1249464581,429660408,3987981055,3193342722,2498929162,3340233719,859320816,1625126925,3733713679,2372844274,2034327797,715401480,738800357,2146204440,2344853791,3626428642,1718641632,898968093,3250253850,2455747047,3103494383,3944667410,523305749,1288981224,4068655594,2707916823,1430802960,112008173,1477600714,200748087,4292408880,2889727949,309015759,1099857202,3047270197,3863277256,3437283264,2667941437,1797936186,953097671,2258212549,3581730616,559088959,1924549826,1947948847,670965458,3553739989,2150927656,1046611498,1837584343,2577962448,3394100269,3773429029,3003956440,1193502431,348532514,2861605920,4185255389,224016346,1589607975,2955201428,3821109865,401496174,1141576083,4200438417,2847462252,1570179435,242368662,618031518,1999839331,2199714404,3506025369,1856977051,1028288870,3378883425,2592137884,2620258673,3486036108,1005021835,1744970614,3595872372,2243027337,1906195342,578515571,148855675,1530532486,2937440385,4243620220,1118177918,289620867,3849099652,3062485113,3895897694,3151226787,1341930916,471430233,2723151707,4054496934,92630177,1449141596,2093222996,790709673,3675168686,2297157203,918379857,1700271276,2440548011,3264382806,3292503227,2547701062,1677004609,806373052,2387004862,3718480963,697065028,2053707705,1355628209,52983628,4144475467,2766333110,448032692,1230054985,3179215950,4003182003,1705370073,910207012,3262083619,2441755614,802992348,2084174113,2283152166,3690162907,4049028051,2729577006,1453183017,91789780,3140358870,3905641259,484737324,1325517009,1236063036,441031361,3999678662,3179481403,64324153,1345375172,2753499587,4160378942,3713954102,2394634443,2056577740,695315249,2535923763,3301075406,820884425,1661532724,1035437075,1850920430,2591889385,3382205972,2010043670,606837995,3489941228,2212564753,2839881241,4204818404,244299235,1567292446,3812390684,2967027425,1157031142,387165467,297711350,1113325323,3061064972,3851513073,1539827699,136490510,4228740105,2951233012,2236355836,3601423617,579241734,1902366459,3476375033,2630880260,1761596931,991600638,3582011981,2254726064,1917565367,565112906,2683861832,3424465589,942860466,1809293647,1098090567,311869882,3870890941,3042726464,185260354,1492095167,2898283192,4280615749,4186445992,2859290965,1581419346,229098159,3018934701,3759407184,339466839,1205769130,1836759714,1050669919,3400542552,2572509349,654568359,1961271898,2160687197,3542888864,2375241607,3732276858,710532221,2042402176,3354009218,2484033407,1612746104,868598917,425848205,1250206832,3198910071,3981326218,1394130056,16643445,4107415410,2805425807,2711256418,4068422815,105967256,1437968229,3957533799,3087426970,1277804445,533526112,896065384,1720555157,2460109970,3242657135,2131857005,754239376,3638238615,2336117866 }, + { 0,3410740146,2474373525,1479553575,589010395,3897579113,2959107150,2066458620,1178020790,2373773316,3578583587,503781777,1697431149,2926018015,4132917240,1025281098,2356041580,1193645278,521512697,3562956107,2943730359,1681785093,1007563554,4148555920,3394862298,18005864,1495436623,2456375037,3913476353,571026099,2050562196,2977094438,489740329,3598392219,2387290556,1157687822,1043025394,4116745792,2907749479,1713078229,1527247775,2420912173,3363570186,53985720,2015127108,3008865782,3949434833,539776099,2438893381,1511345399,36011728,3379477858,2990873246,2031016236,557771531,3933546681,3614024947,472016705,1142052198,2405013204,4101124392,1060762266,1728692413,2890007311,979480658,4046091232,2837070279,1649508981,427435401,3526485563,2315375644,1095374766,2086050788,3072153686,4012730993,610707907,1598885439,2483473805,3426156458,125647896,3054495550,2101617804,628364971,3997160729,2501145317,1583329623,107971440,3441705154,4030254216,997396282,1665350941,2819161775,3542309203,409508577,1079552198,2333305716,659646587,3961170889,3022690798,2137086556,72023456,3472965138,2536574005,1551552391,1634091981,2855108735,4062032472,961966570,1115543062,2302023076,3506841475,441312305,2873048855,1618279589,944033410,4077849904,2284104396,1131374974,459234137,3491010795,3976729761,641980179,2121524532,3040355974,3457384826,89670344,1567125743,2518922077,1958961316,3213402902,3887632689,754143875,1473836415,2626893517,3299017962,266913624,854870802,4190079136,2710551175,1791260981,300932809,3668188539,2190749532,1239411950,4172101576,870773882,1809237597,2694645231,3686179347,285041057,1221415814,2206634036,3197770878,1976688588,769781227,3869912665,2642512293,1456097815,251295792,3316759426,1777580173,2729999167,4203235608,834898602,1256729942,2175004388,3650346179,316153713,801411899,3834597513,3166659246,2012520732,215942880,3348415826,2678388597,1424962759,3852333025,785787987,1994792564,3182288326,3330701882,231586184,1442679727,2662746141,2745877591,1759578085,819017154,4221236848,2159104396,1274712638,332046361,3632358315,1319293174,2246644548,3721994595,378725073,1840858413,2800912031,4274173112,898201354,144046912,3286120690,2616068821,1353042279,730754715,3771051305,3103104782,1941855420,3268183962,159859752,1370977807,2600252861,3788968513,714920435,1923933140,3118932070,2231086124,1336962974,394288569,3704331787,2816489975,1823210053,882624610,4291824592,1402079455,2564410221,3236559178,195181304,1888066820,3150077622,3824315537,683257635,363144041,3740197083,2262749948,1301614926,918468274,4260721920,2781169447,1854833813,3757858739,347577345,1283960358,2278321556,4243049064,934021594,1872509949,2765617231,2580247557,1384167351,179340688,3254470178,3134251486,1905992300,699076683,3806385145 } +}; diff --git a/third-party/crc32c/crc32c.c b/third-party/crc32c/crc32c.c new file mode 100644 index 00000000000..00d6c887fc3 --- /dev/null +++ b/third-party/crc32c/crc32c.c @@ -0,0 +1,597 @@ +/* crc32c.c -- compute CRC-32C using software table or available hardware instructions + * Copyright (C) 2013 Mark Adler + * Version 1.1 1 Aug 2013 Mark Adler + * + * Code retrieved in August 2016 from August 2013 post by Mark Adler on + * http://stackoverflow.com/questions/17645167/implementing-sse-4-2s-crc32c-in-software + * Modified for use in libjulia (and then copied to rr): + * - removed main() function + * - architecture and compiler detection + * - precompute crc32c tables and store in a generated .c file + * - ARMv8 support + */ + +/* + This software is provided 'as-is', without any express or implied + warranty. In no event will the author be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. + + Mark Adler + madler@alumni.caltech.edu +*/ + +/* This computes a CRC-32C, *not* the CRC-32 used by Ethernet and zip, gzip, etc. + * A software version is provided as a fall-back, as well as for speed comparisons. */ + +/* Version history: + 1.0 10 Feb 2013 First version + 1.1 1 Aug 2013 Correct comments on why three crc instructions in parallel +*/ + +#include +#include +#include + +#if defined(__aarch64__) +# include +#endif + +/* CRC-32C (iSCSI) polynomial in reversed bit order. */ +#define POLY 0x82f63b78 + +/* Block sizes for three-way parallel crc computation. LONG and SHORT must + both be powers of two. The associated string constants must be set + accordingly, for use in constructing the assembler instructions. */ +#define LONG 8192 +#define LONGx1 "8192" +#define LONGx2 "16384" +#define SHORT 256 +#define SHORTx1 "256" +#define SHORTx2 "512" + +#ifndef GEN_CRC32C_TABLES +#include "crc32c.h" +#include "crc32c-tables.c" + +#define CRC32C_USE_IFUNC + +uint32_t crc32c_sw(uint32_t crci, const uint8_t *buf, size_t len); +typedef uint32_t (*crc32c_func_t)(uint32_t crc, const uint8_t *buf, size_t len); + +uint64_t load_unaligned_i64(const void *ptr) +{ + uint64_t val; + memcpy(&val, ptr, sizeof(uint64_t)); + return val; +} + +# if defined(__x86_64__) || defined(__i386__) +# if defined(__x86_64__) +# define CRC32_PTR "crc32q" +# else +# define CRC32_PTR "crc32l" +# endif + +/* Compute CRC-32C using the SSE4.2 hardware instruction. */ +static uint32_t crc32c_sse42(uint32_t crc, const uint8_t *buf, size_t len) +{ + /* need to be 64 bits for crc32q */ + /* pre-process the crc */ + uintptr_t crc0 = crc ^ 0xffffffff; + + /* compute the crc for up to seven leading bytes to bring the data pointer + to an eight-byte boundary */ + while (len && ((uintptr_t)buf & 7) != 0) { + __asm__("crc32b\t" "(%1), %0" + : "=r"(crc0) + : "r"(buf), "0"(crc0)); + buf++; + len--; + } + + /* compute the crc on sets of LONG*3 bytes, executing three independent crc + instructions, each on LONG bytes -- this is optimized for the Nehalem, + Westmere, Sandy Bridge, and Ivy Bridge architectures, which have a + throughput of one crc per cycle, but a latency of three cycles */ + while (len >= LONG * 3) { + uintptr_t crc1 = 0; + uintptr_t crc2 = 0; + const uint8_t *end = buf + LONG; + do { + __asm__(CRC32_PTR "\t" "(%3), %0\n\t" + CRC32_PTR "\t" LONGx1 "(%3), %1\n\t" + CRC32_PTR "\t" LONGx2 "(%3), %2" + : "=r"(crc0), "=r"(crc1), "=r"(crc2) + : "r"(buf), "0"(crc0), "1"(crc1), "2"(crc2)); + buf += sizeof(void*); + } while (buf < end); + crc0 = crc32c_shift(crc32c_long, crc0) ^ crc1; + crc0 = crc32c_shift(crc32c_long, crc0) ^ crc2; + buf += LONG * 2; + len -= LONG * 3; + } + + /* do the same thing, but now on SHORT*3 blocks for the remaining data less + than a LONG*3 block */ + while (len >= SHORT * 3) { + uintptr_t crc1 = 0; + uintptr_t crc2 = 0; + const uint8_t *end = buf + SHORT; + do { + __asm__(CRC32_PTR "\t" "(%3), %0\n\t" + CRC32_PTR "\t" SHORTx1 "(%3), %1\n\t" + CRC32_PTR "\t" SHORTx2 "(%3), %2" + : "=r"(crc0), "=r"(crc1), "=r"(crc2) + : "r"(buf), "0"(crc0), "1"(crc1), "2"(crc2)); + buf += sizeof(void*); + } while (buf < end); + crc0 = crc32c_shift(crc32c_short, crc0) ^ crc1; + crc0 = crc32c_shift(crc32c_short, crc0) ^ crc2; + buf += SHORT * 2; + len -= SHORT * 3; + } + + /* compute the crc on the remaining eight-byte units less than a SHORT*3 + block */ + const uint8_t *end = buf + (len - (len & 7)); + while (buf < end) { + __asm__(CRC32_PTR "\t" "(%1), %0" + : "=r"(crc0) + : "r"(buf), "0"(crc0)); + buf += sizeof(void*); + } + len &= 7; + + /* compute the crc for up to seven trailing bytes */ + while (len) { + __asm__("crc32b\t" "(%1), %0" + : "=r"(crc0) + : "r"(buf), "0"(crc0)); + buf++; + len--; + } + + /* return a post-processed crc */ + return (uint32_t)crc0 ^ 0xffffffff; +} + +// HW feature detection +# ifdef __SSE4_2__ +// The C code is compiled with SSE42 being required. Skip runtime dispatch. +uint32_t crc32c(uint32_t crc, uint8_t *buf, size_t len) +{ + return crc32c_sse42(crc, buf, len); +} +# else +static crc32c_func_t crc32c_dispatch(void) +{ + // When used in ifunc, we cannot call external functions + uint32_t eax = 1, ebx, ecx, edx; + asm ( +#if defined(__i386__) && defined(__PIC__) + "xchg %%ebx, %%esi;" + "cpuid;" + "xchg %%esi, %%ebx;": + "=S" (ebx) , +#else + "cpuid": + "=b" (ebx), +#endif + "+a" (eax), + "=c" (ecx), + "=d" (edx)); + if ((ecx >> 20) & 1) + return crc32c_sse42; + return crc32c_sw; +} +// For ifdef detection below +# define crc32c_dispatch crc32c_dispatch +# define crc32c_dispatch_ifunc "crc32c_dispatch" +# endif +# elif defined(__aarch64__) +# ifdef __clang__ +# define CRC_TARGET __attribute__((target("crc"))) +# else +# define CRC_TARGET __attribute__((target("+crc"))) +# endif +/* Compute CRC-32C using the ARMv8 CRC32 extension. */ +CRC_TARGET static inline uint32_t crc32cx(uint32_t crc, uint64_t val) +{ + uint32_t res; + asm("crc32cx %w0, %w1, %2" : "=r"(res) : "r"(crc), "r"(val)); + return res; +} +CRC_TARGET static inline uint32_t crc32cw(uint32_t crc, uint32_t val) +{ + uint32_t res; + asm("crc32cw %w0, %w1, %w2" : "=r"(res) : "r"(crc), "r"(val)); + return res; +} +CRC_TARGET static inline uint32_t crc32ch(uint32_t crc, uint32_t val) +{ + uint32_t res; + asm("crc32ch %w0, %w1, %w2" : "=r"(res) : "r"(crc), "r"(val)); + return res; +} +CRC_TARGET static inline uint32_t crc32cb(uint32_t crc, uint32_t val) +{ + uint32_t res; + asm("crc32cb %w0, %w1, %w2" : "=r"(res) : "r"(crc), "r"(val)); + return res; +} + +// Modified from the SSE4.2 version. +CRC_TARGET static uint32_t crc32c_armv8(uint32_t crc, const char *buf, size_t len) +{ + /* pre-process the crc */ + crc = ~crc; + + // Misaligned access doesn't seem to have any measurable performance overhead + // on Cortex-A57 + + // crc32c has a latency of 3 and throughput of 1 on Cortex-A57 + // The latency and throughput are 2 and 1 on Cortex-A72 + // In either case, the 3 wide parallel processing shouldn't hurt since the block size + // should be big enough. + /* compute the crc on sets of LONG*3 bytes, executing three independent crc + * instructions, each on LONG bytes. */ + while (len >= LONG * 3) { + uint32_t crc1 = 0; + uint32_t crc2 = 0; + const char *end = buf + LONG; + const char *buf2 = end; + const char *buf3 = end + LONG; + do { + crc = crc32cx(crc, load_unaligned_i64(buf)); + buf += 8; + crc1 = crc32cx(crc1, load_unaligned_i64(buf2)); + buf2 += 8; + crc2 = crc32cx(crc2, load_unaligned_i64(buf3)); + buf3 += 8; + } while (buf < end); + crc = crc32c_shift(crc32c_long, crc) ^ crc1; + crc = crc32c_shift(crc32c_long, crc) ^ crc2; + buf += LONG * 2; + len -= LONG * 3; + } + + /* do the same thing, but now on SHORT*3 blocks for the remaining data less + * than a LONG*3 block */ + while (len >= SHORT * 3) { + uint32_t crc1 = 0; + uint32_t crc2 = 0; + const char *end = buf + SHORT; + const char *buf2 = end; + const char *buf3 = end + SHORT; + do { + crc = crc32cx(crc, load_unaligned_i64(buf)); + buf += 8; + crc1 = crc32cx(crc1, load_unaligned_i64(buf2)); + buf2 += 8; + crc2 = crc32cx(crc2, load_unaligned_i64(buf3)); + buf3 += 8; + } while (buf < end); + crc = crc32c_shift(crc32c_short, crc) ^ crc1; + crc = crc32c_shift(crc32c_short, crc) ^ crc2; + buf += SHORT * 2; + len -= SHORT * 3; + } + // The same shift table can be used to compute two SHORT blocks simultaneously + if (len >= SHORT * 2) { + uint32_t crc1 = 0; + const char *end = buf + SHORT; + const char *buf2 = end; + do { + crc = crc32cx(crc, load_unaligned_i64(buf)); + buf += 8; + crc1 = crc32cx(crc1, load_unaligned_i64(buf2)); + buf2 += 8; + } while (buf < end); + crc = crc32c_shift(crc32c_short, crc) ^ crc1; + buf += SHORT; + len -= SHORT * 2; + } + + /* compute the crc on the remaining eight-byte units less than a SHORT*2 + block */ + const char *end = buf + len - 8; + while (buf <= end) { + crc = crc32cx(crc, load_unaligned_i64(buf)); + buf += 8; + } + if (len & 4) { + crc = crc32cw(crc, load_unaligned_i32(buf)); + buf += 4; + } + if (len & 2) { + crc = crc32ch(crc, load_unaligned_i16(buf)); + buf += 2; + } + if (len & 1) + crc = crc32cb(crc, *buf); + /* return a post-processed crc */ + return ~crc; +} + +// HW feature detection +# ifdef __ARM_FEATURE_CRC32 +// The C code is compiled with CRC32 being required. Skip runtime dispatch. +uint32_t crc32c(uint32_t crc, const uint8_t *buf, size_t len) +{ + return crc32c_armv8(crc, buf, len); +} +# else +# define AArch64_crc 7 +static crc32c_func_t crc32c_dispatch(unsigned long hwcap) +{ + if (hwcap & (1 << AArch64_crc)) + return crc32c_armv8; + return crc32c_sw; +} +// For ifdef detection below +# define crc32c_dispatch() crc32c_dispatch(getauxval(AT_HWCAP)) +# define crc32c_dispatch_ifunc "crc32c_dispatch" +# endif +# endif + +# ifdef crc32c_dispatch +# ifdef CRC32C_USE_IFUNC +// ifunc dispatch +uint32_t crc32c(uint32_t crc, const uint8_t *buf, size_t len) + __attribute__((ifunc (crc32c_dispatch_ifunc))); +# else +// lazy wrapper dispatch +static uint32_t crc32c_lazy(uint32_t crc, const uint8_t *buf, size_t len); +static crc32c_func_t crc32c_func = crc32c_lazy; + +static uint32_t crc32c_lazy(uint32_t crc, uint8_t *buf, size_t len) +{ + crc32c_func = crc32c_dispatch(); + return crc32c_func(crc, buf, len); +} + +/* Compute a CRC-32C. Do a lazy dispatch based on hardware features */ +uint32_t crc32c(uint32_t crc, const uint8_t *buf, size_t len) +{ + return crc32c_func(crc, buf, len); +} +# endif +# endif + +/* Table-driven software version as a fall-back. This is about 15 times slower + than using the hardware instructions. This computes a little-endian + CRC32c, equivalent to the little-endian CRC of the SSE4.2 or ARMv8 instructions, + regardless of the endianness of the machine this is running on. */ +uint32_t crc32c_sw(uint32_t crci, const uint8_t *buf, size_t len) +{ + uintptr_t crc = crci ^ 0xffffffff; + while (len && ((uintptr_t)buf & 7) != 0) { + crc = crc32c_table[0][(crc ^ *buf++) & 0xff] ^ (crc >> 8); + len--; + } + while (len >= 8) { +#if defined(__x86_64__) || defined(__aarch64__) + crc ^= *(uint64_t*)buf; + crc = crc32c_table[7][crc & 0xff] ^ + crc32c_table[6][(crc >> 8) & 0xff] ^ + crc32c_table[5][(crc >> 16) & 0xff] ^ + crc32c_table[4][(crc >> 24) & 0xff] ^ + crc32c_table[3][(crc >> 32) & 0xff] ^ + crc32c_table[2][(crc >> 40) & 0xff] ^ + crc32c_table[1][(crc >> 48) & 0xff] ^ + crc32c_table[0][crc >> 56]; +#else + uint32_t *p = (uint32_t*)buf; + crc ^= p[0]; + uint32_t hi = p[1]; + crc = crc32c_table[7][crc & 0xff] ^ + crc32c_table[6][(crc >> 8) & 0xff] ^ + crc32c_table[5][(crc >> 16) & 0xff] ^ + crc32c_table[4][(crc >> 24) & 0xff] ^ + crc32c_table[3][hi & 0xff] ^ + crc32c_table[2][(hi >> 8) & 0xff] ^ + crc32c_table[1][(hi >> 16) & 0xff] ^ + crc32c_table[0][hi >> 24]; +#endif + buf += 8; + len -= 8; + } + while (len) { + crc = crc32c_table[0][(crc ^ *buf++) & 0xff] ^ (crc >> 8); + len--; + } + return (uint32_t)crc ^ 0xffffffff; +} + +/*****************************************************************************/ +/*****************************************************************************/ +/*****************************************************************************/ + +/* Compile with -DGEN_CRC32C_TABLES to generate header file containing + precomputed hardware and software tables */ +// Example command line, run from top level directory: +// $ gcc src/crc32c.c -o main -DGEN_CRC32C_TABLES -I src -I src/support +// $ ./main > src/crc32c-tables.c + +#else /* ifdef GEN_CRC32C_TABLES */ + +/* Table for a quadword-at-a-time software crc. */ +static uint32_t crc32c_table[8][256]; + +/* Construct table for software CRC-32C calculation. */ +static void crc32c_init_sw(void) +{ + uint32_t n, crc, k; + + for (n = 0; n < 256; n++) { + crc = n; + crc = crc & 1 ? (crc >> 1) ^ POLY : crc >> 1; + crc = crc & 1 ? (crc >> 1) ^ POLY : crc >> 1; + crc = crc & 1 ? (crc >> 1) ^ POLY : crc >> 1; + crc = crc & 1 ? (crc >> 1) ^ POLY : crc >> 1; + crc = crc & 1 ? (crc >> 1) ^ POLY : crc >> 1; + crc = crc & 1 ? (crc >> 1) ^ POLY : crc >> 1; + crc = crc & 1 ? (crc >> 1) ^ POLY : crc >> 1; + crc = crc & 1 ? (crc >> 1) ^ POLY : crc >> 1; + crc32c_table[0][n] = crc; + } + for (n = 0; n < 256; n++) { + crc = crc32c_table[0][n]; + for (k = 1; k < 8; k++) { + crc = crc32c_table[0][crc & 0xff] ^ (crc >> 8); + crc32c_table[k][n] = crc; + } + } +} + +/* Tables for hardware crc that shift a crc by LONG, SHORT and 4k zeros. */ +static uint32_t crc32c_long[4][256]; +static uint32_t crc32c_short[4][256]; +static uint32_t crc32c_4k[4][256]; +static uint32_t crc32c_1M[4][256]; +static uint32_t crc32c_1G[4][256]; +static uint32_t crc32c_1T[4][256]; + +/* Multiply a matrix times a vector over the Galois field of two elements, + GF(2). Each element is a bit in an unsigned integer. mat must have at + least as many entries as the power of two for most significant one bit in + vec. */ +static inline uint32_t gf2_matrix_times(uint32_t *mat, uint32_t vec) +{ + uint32_t sum; + + sum = 0; + while (vec) { + if (vec & 1) + sum ^= *mat; + vec >>= 1; + mat++; + } + return sum; +} + +/* Multiply a matrix by itself over GF(2). Both mat and square must have 32 + rows. */ +static inline void gf2_matrix_square(uint32_t *square, uint32_t *mat) +{ + int n; + + for (n = 0; n < 32; n++) + square[n] = gf2_matrix_times(mat, mat[n]); +} + +/* Construct an operator to apply len zeros to a crc. len must be a power of + two. If len is not a power of two, then the result is the same as for the + largest power of two less than len. The result for len == 0 is the same as + for len == 1. A version of this routine could be easily written for any + len, but that is not needed for this application. */ +static void crc32c_zeros_op(uint32_t *even, size_t len) +{ + int n; + uint32_t row; + uint32_t odd[32]; /* odd-power-of-two zeros operator */ + + /* put operator for one zero bit in odd */ + odd[0] = POLY; /* CRC-32C polynomial */ + row = 1; + for (n = 1; n < 32; n++) { + odd[n] = row; + row <<= 1; + } + + /* put operator for two zero bits in even */ + gf2_matrix_square(even, odd); + + /* put operator for four zero bits in odd */ + gf2_matrix_square(odd, even); + + /* first square will put the operator for one zero byte (eight zero bits), + in even -- next square puts operator for two zero bytes in odd, and so + on, until len has been rotated down to zero */ + do { + gf2_matrix_square(even, odd); + len >>= 1; + if (len == 0) + return; + gf2_matrix_square(odd, even); + len >>= 1; + } while (len); + + /* answer ended up in odd -- copy to even */ + for (n = 0; n < 32; n++) + even[n] = odd[n]; +} + +/* Take a length and build four lookup tables for applying the zeros operator + for that length, byte-by-byte on the operand. */ +static void crc32c_zeros(uint32_t zeros[][256], size_t len) +{ + uint32_t n; + uint32_t op[32]; + + crc32c_zeros_op(op, len); + for (n = 0; n < 256; n++) { + zeros[0][n] = gf2_matrix_times(op, n); + zeros[1][n] = gf2_matrix_times(op, n << 8); + zeros[2][n] = gf2_matrix_times(op, n << 16); + zeros[3][n] = gf2_matrix_times(op, n << 24); + } +} + +/* Initialize tables for shifting crcs. */ +static void crc32c_init_hw(void) +{ + crc32c_zeros(crc32c_long, LONG); + crc32c_zeros(crc32c_short, SHORT); + crc32c_zeros(crc32c_4k, 4096); + crc32c_zeros(crc32c_1M, 1024ULL * 1024ULL); + crc32c_zeros(crc32c_1G, 1024ULL * 1024ULL * 1024ULL); + crc32c_zeros(crc32c_1T, 1024ULL * 1024ULL * 1024ULL * 1024ULL); +} + +#include + +static void print_array(const char *name, int m, int n, const uint32_t *a) +{ + int i, j; + printf("const uint32_t %s[%d][%d] = {\n", name, m, n); + for (i = 0; i < m; ++i) { + printf(" { %u", a[i*n+0]); + for (j = 1; j < n; ++j) printf(",%u", a[i*n+j]); + printf(" }%s", i == m-1 ? "\n" : ",\n"); + } + printf("};\n"); +} + +int main(void) +{ + printf("/* Pregenerated tables for crc32c.c, produced by compiling with -DGEN_CRC32C_TABLES. */\n" + "#if POLY != 0x%x\n# error \"tables generated for different polynomial\"\n#endif\n\n", POLY); + crc32c_init_sw(); + print_array("crc32c_table", 8, 256, &crc32c_table[0][0]); + crc32c_init_hw(); + printf("\n"); + print_array("crc32c_long", 4, 256, &crc32c_long[0][0]); + print_array("crc32c_short", 4, 256, &crc32c_short[0][0]); + print_array("crc32c_4k", 4, 256, &crc32c_4k[0][0]); + print_array("crc32c_1M", 4, 256, &crc32c_1M[0][0]); + print_array("crc32c_1G", 4, 256, &crc32c_1G[0][0]); + print_array("crc32c_1T", 4, 256, &crc32c_1T[0][0]); + return 0; +} + +#endif /* GEN_CRC32C_TABLES */ + +/*****************************************************************************/ diff --git a/third-party/crc32c/crc32c.h b/third-party/crc32c/crc32c.h new file mode 100644 index 00000000000..11efe705246 --- /dev/null +++ b/third-party/crc32c/crc32c.h @@ -0,0 +1,25 @@ +/* -*- Mode: C++; tab-width: 8; c-basic-offset: 2; indent-tabs-mode: nil; -*- */ +/* Header file for crc32.c - see copyright/license information in that file */ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +extern uint32_t crc32c(uint32_t crc, const uint8_t *buf, size_t len); + +/* Apply the zeros operator table to crc. */ +extern const uint32_t crc32c_4k[4][256]; +extern const uint32_t crc32c_1M[4][256]; +extern const uint32_t crc32c_1G[4][256]; +extern const uint32_t crc32c_1T[4][256]; +static inline uint32_t crc32c_shift(const uint32_t zeros[][256], uint32_t crc) +{ + return zeros[0][crc & 0xff] ^ zeros[1][(crc >> 8) & 0xff] ^ + zeros[2][(crc >> 16) & 0xff] ^ zeros[3][crc >> 24]; +} + +#ifdef __cplusplus +} +#endif \ No newline at end of file