]>
Commit | Line | Data |
---|---|---|
9f95a23c TL |
1 | /********************************************************************** |
2 | Copyright(c) 2011-2016 Intel Corporation All rights reserved. | |
3 | ||
4 | Redistribution and use in source and binary forms, with or without | |
5 | modification, are permitted provided that the following conditions | |
6 | are met: | |
7 | * Redistributions of source code must retain the above copyright | |
8 | notice, this list of conditions and the following disclaimer. | |
9 | * Redistributions in binary form must reproduce the above copyright | |
10 | notice, this list of conditions and the following disclaimer in | |
11 | the documentation and/or other materials provided with the | |
12 | distribution. | |
13 | * Neither the name of Intel Corporation nor the names of its | |
14 | contributors may be used to endorse or promote products derived | |
15 | from this software without specific prior written permission. | |
16 | ||
17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
21 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
28 | **********************************************************************/ | |
29 | ||
30 | #include <stdio.h> | |
31 | #include <stdlib.h> | |
32 | #include <string.h> | |
33 | #include <stdint.h> | |
34 | #include <sys/time.h> | |
35 | #include "crc64.h" | |
36 | #include "test.h" | |
37 | ||
38 | //#define CACHED_TEST | |
39 | #ifdef CACHED_TEST | |
40 | // Cached test, loop many times over small dataset | |
41 | # define TEST_LEN 8*1024 | |
9f95a23c TL |
42 | # define TEST_TYPE_STR "_warm" |
43 | #else | |
44 | // Uncached test. Pull from large mem base. | |
45 | # define GT_L3_CACHE 32*1024*1024 /* some number > last level cache */ | |
46 | # define TEST_LEN (2 * GT_L3_CACHE) | |
9f95a23c TL |
47 | # define TEST_TYPE_STR "_cold" |
48 | #endif | |
49 | ||
50 | #ifndef TEST_SEED | |
51 | # define TEST_SEED 0x1234 | |
52 | #endif | |
53 | ||
54 | #define TEST_MEM TEST_LEN | |
55 | ||
56 | typedef uint64_t(*crc64_func_t) (uint64_t, const uint8_t *, uint64_t); | |
57 | ||
58 | typedef struct func_case { | |
59 | char *note; | |
60 | crc64_func_t crc64_func_call; | |
61 | crc64_func_t crc64_ref_call; | |
62 | } func_case_t; | |
63 | ||
64 | func_case_t test_funcs[] = { | |
65 | {"crc64_ecma_norm", crc64_ecma_norm, crc64_ecma_norm_base}, | |
66 | {"crc64_ecma_refl", crc64_ecma_refl, crc64_ecma_refl_base}, | |
67 | {"crc64_iso_norm", crc64_iso_norm, crc64_iso_norm_base}, | |
68 | {"crc64_iso_refl", crc64_iso_refl, crc64_iso_refl_base}, | |
69 | {"crc64_jones_norm", crc64_jones_norm, crc64_jones_norm_base}, | |
70 | {"crc64_jones_refl", crc64_jones_refl, crc64_jones_refl_base} | |
71 | }; | |
72 | ||
73 | int main(int argc, char *argv[]) | |
74 | { | |
f67539c2 | 75 | int j; |
9f95a23c TL |
76 | void *buf; |
77 | uint64_t crc; | |
f67539c2 | 78 | struct perf start; |
9f95a23c TL |
79 | func_case_t *test_func; |
80 | ||
81 | if (posix_memalign(&buf, 1024, TEST_LEN)) { | |
82 | printf("alloc error: Fail"); | |
83 | return -1; | |
84 | } | |
85 | memset(buf, (char)TEST_SEED, TEST_LEN); | |
86 | ||
87 | for (j = 0; j < sizeof(test_funcs) / sizeof(test_funcs[0]); j++) { | |
88 | test_func = &test_funcs[j]; | |
89 | printf("%s_perf:\n", test_func->note); | |
90 | ||
91 | printf("Start timed tests\n"); | |
92 | fflush(0); | |
93 | ||
f67539c2 TL |
94 | BENCHMARK(&start, BENCHMARK_TIME, crc = |
95 | test_func->crc64_func_call(TEST_SEED, buf, TEST_LEN)); | |
9f95a23c | 96 | printf("%s" TEST_TYPE_STR ": ", test_func->note); |
f67539c2 | 97 | perf_print(start, (long long)TEST_LEN); |
9f95a23c TL |
98 | |
99 | printf("finish 0x%lx\n", crc); | |
100 | } | |
101 | ||
102 | return 0; | |
103 | } |