|
0
|
1 #include "crc32i.h"
|
|
|
2 #include <stdio.h>
|
|
|
3
|
|
|
4 /* Test implementations and make sure they agree with each other */
|
|
|
5 int crc32_test(void)
|
|
|
6 {
|
|
|
7 /* Force alignment :) */
|
|
|
8 static const __attribute__((__aligned__(CRC32_MAX_ALIGNMENT))) unsigned char testdata[1024] =
|
|
|
9 #define DOUBLE(x) x x
|
|
|
10 DOUBLE(DOUBLE(DOUBLE(DOUBLE(DOUBLE(DOUBLE(DOUBLE("\x01\x02\x04\x08\x10\x20\x40\x80")))))))
|
|
|
11 #undef DOUBLE
|
|
|
12 ;
|
|
|
13 static const crc32_r_spec crc[] = {
|
|
|
14 crc32c_r,
|
|
|
15 crc32qw_r,
|
|
|
16 crc32x86_vpclmulqdq_r
|
|
|
17 };
|
|
|
18 size_t i;
|
|
|
19
|
|
|
20 uint32_t crcc = crc32(testdata, sizeof(testdata));
|
|
|
21
|
|
|
22 for (i = 0; i < ARRAY_SIZE(crc); i++) {
|
|
|
23 uint32_t thiscrc = ~crc[i](0xFFFFFFFF, testdata, sizeof(testdata));
|
|
|
24
|
|
|
25 if (thiscrc != crcc) {
|
|
|
26 fprintf(stderr, "%zu, mismatch: %08x, %08x\n", i, crcc, thiscrc);
|
|
|
27 return -1;
|
|
|
28 }
|
|
|
29 }
|
|
|
30
|
|
|
31 return 0;
|
|
|
32 }
|
|
|
33
|
|
|
34 int main(void)
|
|
|
35 {
|
|
|
36 return -crc32_test();
|
|
|
37 }
|