]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/contrib/zstd/tests/regression/config.c
Update to Zstandard 1.3.8
[FreeBSD/FreeBSD.git] / sys / contrib / zstd / tests / regression / config.c
1 /*
2  * Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
3  * All rights reserved.
4  *
5  * This source code is licensed under both the BSD-style license (found in the
6  * LICENSE file in the root directory of this source tree) and the GPLv2 (found
7  * in the COPYING file in the root directory of this source tree).
8  * You may select, at your option, one of the above-listed licenses.
9  */
10
11 #include "config.h"
12
13 /* Define a config for each fast level we want to test with. */
14 #define FAST_LEVEL(x)                                               \
15     param_value_t const level_fast##x##_param_values[] = {          \
16         {.param = ZSTD_c_compressionLevel, .value = -x},            \
17     };                                                              \
18     config_t const level_fast##x = {                                \
19         .name = "level -" #x,                                       \
20         .cli_args = "--fast=" #x,                                   \
21         .param_values = PARAM_VALUES(level_fast##x##_param_values), \
22     };                                                              \
23     config_t const level_fast##x##_dict = {                         \
24         .name = "level -" #x " with dict",                          \
25         .cli_args = "--fast=" #x,                                   \
26         .param_values = PARAM_VALUES(level_fast##x##_param_values), \
27         .use_dictionary = 1,                                        \
28     };
29
30 /* Define a config for each level we want to test with. */
31 #define LEVEL(x)                                                \
32     param_value_t const level_##x##_param_values[] = {          \
33         {.param = ZSTD_c_compressionLevel, .value = x},         \
34     };                                                          \
35     config_t const level_##x = {                                \
36         .name = "level " #x,                                    \
37         .cli_args = "-" #x,                                     \
38         .param_values = PARAM_VALUES(level_##x##_param_values), \
39     };                                                          \
40     config_t const level_##x##_dict = {                         \
41         .name = "level " #x " with dict",                       \
42         .cli_args = "-" #x,                                     \
43         .param_values = PARAM_VALUES(level_##x##_param_values), \
44         .use_dictionary = 1,                                    \
45     };
46
47 #define PARAM_VALUES(pv) \
48     { .data = pv, .size = sizeof(pv) / sizeof((pv)[0]) }
49
50 #include "levels.h"
51
52 #undef LEVEL
53 #undef FAST_LEVEL
54
55 static config_t no_pledged_src_size = {
56     .name = "no source size",
57     .cli_args = "",
58     .param_values = PARAM_VALUES(level_0_param_values),
59     .no_pledged_src_size = 1,
60 };
61
62 static param_value_t const ldm_param_values[] = {
63     {.param = ZSTD_c_enableLongDistanceMatching, .value = 1},
64 };
65
66 static config_t ldm = {
67     .name = "long distance mode",
68     .cli_args = "--long",
69     .param_values = PARAM_VALUES(ldm_param_values),
70 };
71
72 static param_value_t const mt_param_values[] = {
73     {.param = ZSTD_c_nbWorkers, .value = 2},
74 };
75
76 static config_t mt = {
77     .name = "multithreaded",
78     .cli_args = "-T2",
79     .param_values = PARAM_VALUES(mt_param_values),
80 };
81
82 static param_value_t const mt_ldm_param_values[] = {
83     {.param = ZSTD_c_nbWorkers, .value = 2},
84     {.param = ZSTD_c_enableLongDistanceMatching, .value = 1},
85 };
86
87 static config_t mt_ldm = {
88     .name = "multithreaded long distance mode",
89     .cli_args = "-T2 --long",
90     .param_values = PARAM_VALUES(mt_ldm_param_values),
91 };
92
93 static param_value_t const small_wlog_param_values[] = {
94     {.param = ZSTD_c_windowLog, .value = 10},
95 };
96
97 static config_t small_wlog = {
98     .name = "small window log",
99     .cli_args = "--zstd=wlog=10",
100     .param_values = PARAM_VALUES(small_wlog_param_values),
101 };
102
103 static param_value_t const small_hlog_param_values[] = {
104     {.param = ZSTD_c_hashLog, .value = 6},
105     {.param = ZSTD_c_strategy, .value = (int)ZSTD_btopt},
106 };
107
108 static config_t small_hlog = {
109     .name = "small hash log",
110     .cli_args = "--zstd=hlog=6,strat=7",
111     .param_values = PARAM_VALUES(small_hlog_param_values),
112 };
113
114 static param_value_t const small_clog_param_values[] = {
115     {.param = ZSTD_c_chainLog, .value = 6},
116     {.param = ZSTD_c_strategy, .value = (int)ZSTD_btopt},
117 };
118
119 static config_t small_clog = {
120     .name = "small chain log",
121     .cli_args = "--zstd=clog=6,strat=7",
122     .param_values = PARAM_VALUES(small_clog_param_values),
123 };
124
125 static param_value_t const explicit_params_param_values[] = {
126     {.param = ZSTD_c_checksumFlag, .value = 1},
127     {.param = ZSTD_c_contentSizeFlag, .value = 0},
128     {.param = ZSTD_c_dictIDFlag, .value = 0},
129     {.param = ZSTD_c_strategy, .value = (int)ZSTD_greedy},
130     {.param = ZSTD_c_windowLog, .value = 18},
131     {.param = ZSTD_c_hashLog, .value = 21},
132     {.param = ZSTD_c_chainLog, .value = 21},
133     {.param = ZSTD_c_targetLength, .value = 100},
134 };
135
136 static config_t explicit_params = {
137     .name = "explicit params",
138     .cli_args = "--no-check --no-dictID --zstd=strategy=3,wlog=18,hlog=21,clog=21,tlen=100",
139     .param_values = PARAM_VALUES(explicit_params_param_values),
140 };
141
142 static config_t const* g_configs[] = {
143
144 #define FAST_LEVEL(x) &level_fast##x, &level_fast##x##_dict,
145 #define LEVEL(x) &level_##x, &level_##x##_dict,
146 #include "levels.h"
147 #undef LEVEL
148 #undef FAST_LEVEL
149
150     &no_pledged_src_size,
151     &ldm,
152     &mt,
153     &mt_ldm,
154     &small_wlog,
155     &small_hlog,
156     &small_clog,
157     &explicit_params,
158     NULL,
159 };
160
161 config_t const* const* configs = g_configs;
162
163 int config_skip_data(config_t const* config, data_t const* data) {
164     return config->use_dictionary && !data_has_dict(data);
165 }
166
167 int config_get_level(config_t const* config)
168 {
169     param_values_t const params = config->param_values;
170     size_t i;
171     for (i = 0; i < params.size; ++i) {
172         if (params.data[i].param == ZSTD_c_compressionLevel)
173             return (int)params.data[i].value;
174     }
175     return CONFIG_NO_LEVEL;
176 }
177
178 ZSTD_parameters config_get_zstd_params(
179     config_t const* config,
180     uint64_t srcSize,
181     size_t dictSize)
182 {
183     ZSTD_parameters zparams = {};
184     param_values_t const params = config->param_values;
185     int level = config_get_level(config);
186     if (level == CONFIG_NO_LEVEL)
187         level = 3;
188     zparams = ZSTD_getParams(
189         level,
190         config->no_pledged_src_size ? ZSTD_CONTENTSIZE_UNKNOWN : srcSize,
191         dictSize);
192     for (size_t i = 0; i < params.size; ++i) {
193         unsigned const value = params.data[i].value;
194         switch (params.data[i].param) {
195             case ZSTD_c_contentSizeFlag:
196                 zparams.fParams.contentSizeFlag = value;
197                 break;
198             case ZSTD_c_checksumFlag:
199                 zparams.fParams.checksumFlag = value;
200                 break;
201             case ZSTD_c_dictIDFlag:
202                 zparams.fParams.noDictIDFlag = !value;
203                 break;
204             case ZSTD_c_windowLog:
205                 zparams.cParams.windowLog = value;
206                 break;
207             case ZSTD_c_chainLog:
208                 zparams.cParams.chainLog = value;
209                 break;
210             case ZSTD_c_hashLog:
211                 zparams.cParams.hashLog = value;
212                 break;
213             case ZSTD_c_searchLog:
214                 zparams.cParams.searchLog = value;
215                 break;
216             case ZSTD_c_minMatch:
217                 zparams.cParams.minMatch = value;
218                 break;
219             case ZSTD_c_targetLength:
220                 zparams.cParams.targetLength = value;
221                 break;
222             case ZSTD_c_strategy:
223                 zparams.cParams.strategy = (ZSTD_strategy)value;
224                 break;
225             default:
226                 break;
227         }
228     }
229     return zparams;
230 }