Mercurial > crc32
annotate crc32-test.c @ 3:6483683ac857 default tip
*: add profiling code too; expand x86 to use all eight XMM registers
basically ported verbatim from the assembly
| author | Paper <paper@tflc.us> |
|---|---|
| date | Mon, 09 Feb 2026 21:30:30 -0500 |
| parents | ead9f84d11db |
| children |
| rev | line source |
|---|---|
| 0 | 1 #include "crc32i.h" |
| 2 #include <stdio.h> | |
|
3
6483683ac857
*: add profiling code too; expand x86 to use all eight XMM registers
Paper <paper@tflc.us>
parents:
2
diff
changeset
|
3 #include <inttypes.h> |
|
6483683ac857
*: add profiling code too; expand x86 to use all eight XMM registers
Paper <paper@tflc.us>
parents:
2
diff
changeset
|
4 #include <time.h> |
| 0 | 5 |
| 6 /* Test implementations and make sure they agree with each other */ | |
| 7 int crc32_test(void) | |
| 8 { | |
| 9 /* Force alignment :) */ | |
|
3
6483683ac857
*: add profiling code too; expand x86 to use all eight XMM registers
Paper <paper@tflc.us>
parents:
2
diff
changeset
|
10 static const CRC32_ALIGN(CRC32_MAX_ALIGNMENT) unsigned char testdata[(1ul << 23) + 19] = |
| 0 | 11 #define DOUBLE(x) x x |
|
3
6483683ac857
*: add profiling code too; expand x86 to use all eight XMM registers
Paper <paper@tflc.us>
parents:
2
diff
changeset
|
12 DOUBLE(DOUBLE(DOUBLE(DOUBLE(DOUBLE(DOUBLE(DOUBLE(DOUBLE("\x01\x02\x04\x08\x10\x20\x40\x80")))))))) |
| 0 | 13 #undef DOUBLE |
| 14 ; | |
|
3
6483683ac857
*: add profiling code too; expand x86 to use all eight XMM registers
Paper <paper@tflc.us>
parents:
2
diff
changeset
|
15 static const struct { |
|
6483683ac857
*: add profiling code too; expand x86 to use all eight XMM registers
Paper <paper@tflc.us>
parents:
2
diff
changeset
|
16 crc32_r_spec f; |
|
6483683ac857
*: add profiling code too; expand x86 to use all eight XMM registers
Paper <paper@tflc.us>
parents:
2
diff
changeset
|
17 const char *name; |
|
6483683ac857
*: add profiling code too; expand x86 to use all eight XMM registers
Paper <paper@tflc.us>
parents:
2
diff
changeset
|
18 } crc[] = { |
|
6483683ac857
*: add profiling code too; expand x86 to use all eight XMM registers
Paper <paper@tflc.us>
parents:
2
diff
changeset
|
19 #define CRC32_IMPL(name) {crc32##name##_r, #name}, |
|
1
90cb48b87dcc
*: don't hardcode the list of impls in multiple places
Paper <paper@tflc.us>
parents:
0
diff
changeset
|
20 #include "crc32-impls.h" |
| 0 | 21 }; |
| 22 size_t i; | |
| 23 | |
| 24 uint32_t crcc = crc32(testdata, sizeof(testdata)); | |
| 25 | |
| 26 for (i = 0; i < ARRAY_SIZE(crc); i++) { | |
|
3
6483683ac857
*: add profiling code too; expand x86 to use all eight XMM registers
Paper <paper@tflc.us>
parents:
2
diff
changeset
|
27 clock_t start, end; |
|
6483683ac857
*: add profiling code too; expand x86 to use all eight XMM registers
Paper <paper@tflc.us>
parents:
2
diff
changeset
|
28 |
|
6483683ac857
*: add profiling code too; expand x86 to use all eight XMM registers
Paper <paper@tflc.us>
parents:
2
diff
changeset
|
29 start = clock(); |
|
6483683ac857
*: add profiling code too; expand x86 to use all eight XMM registers
Paper <paper@tflc.us>
parents:
2
diff
changeset
|
30 uint32_t thiscrc = crc[i].f(0xFFFFFFFF, testdata, sizeof(testdata)); |
|
6483683ac857
*: add profiling code too; expand x86 to use all eight XMM registers
Paper <paper@tflc.us>
parents:
2
diff
changeset
|
31 end = clock(); |
|
6483683ac857
*: add profiling code too; expand x86 to use all eight XMM registers
Paper <paper@tflc.us>
parents:
2
diff
changeset
|
32 |
|
6483683ac857
*: add profiling code too; expand x86 to use all eight XMM registers
Paper <paper@tflc.us>
parents:
2
diff
changeset
|
33 printf("%s: took %f secs\n", crc[i].name, (double)(end - start) / CLOCKS_PER_SEC); |
|
6483683ac857
*: add profiling code too; expand x86 to use all eight XMM registers
Paper <paper@tflc.us>
parents:
2
diff
changeset
|
34 |
|
6483683ac857
*: add profiling code too; expand x86 to use all eight XMM registers
Paper <paper@tflc.us>
parents:
2
diff
changeset
|
35 thiscrc = ~thiscrc; |
| 0 | 36 |
| 37 if (thiscrc != crcc) { | |
|
3
6483683ac857
*: add profiling code too; expand x86 to use all eight XMM registers
Paper <paper@tflc.us>
parents:
2
diff
changeset
|
38 fprintf(stderr, "%s: mismatch: %08" PRIX32 ", %08" PRIx32 "\n", crc[i].name, crcc, thiscrc); |
| 0 | 39 return -1; |
| 40 } | |
| 41 } | |
| 42 | |
| 43 return 0; | |
| 44 } | |
| 45 | |
| 46 int main(void) | |
| 47 { | |
| 48 return -crc32_test(); | |
| 49 } |
