2 * Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
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.
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}, \
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), \
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, \
30 /* Define a config for each level we want to test with. */
32 param_value_t const level_##x##_param_values[] = { \
33 {.param = ZSTD_c_compressionLevel, .value = x}, \
35 config_t const level_##x = { \
36 .name = "level " #x, \
38 .param_values = PARAM_VALUES(level_##x##_param_values), \
40 config_t const level_##x##_dict = { \
41 .name = "level " #x " with dict", \
43 .param_values = PARAM_VALUES(level_##x##_param_values), \
44 .use_dictionary = 1, \
47 #define PARAM_VALUES(pv) \
48 { .data = pv, .size = sizeof(pv) / sizeof((pv)[0]) }
55 static config_t no_pledged_src_size = {
56 .name = "no source size",
58 .param_values = PARAM_VALUES(level_0_param_values),
59 .no_pledged_src_size = 1,
62 static param_value_t const ldm_param_values[] = {
63 {.param = ZSTD_c_enableLongDistanceMatching, .value = 1},
66 static config_t ldm = {
67 .name = "long distance mode",
69 .param_values = PARAM_VALUES(ldm_param_values),
72 static param_value_t const mt_param_values[] = {
73 {.param = ZSTD_c_nbWorkers, .value = 2},
76 static config_t mt = {
77 .name = "multithreaded",
79 .param_values = PARAM_VALUES(mt_param_values),
82 static param_value_t const mt_ldm_param_values[] = {
83 {.param = ZSTD_c_nbWorkers, .value = 2},
84 {.param = ZSTD_c_enableLongDistanceMatching, .value = 1},
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),
93 static param_value_t const small_wlog_param_values[] = {
94 {.param = ZSTD_c_windowLog, .value = 10},
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),
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},
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),
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},
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),
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},
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),
142 static config_t const* g_configs[] = {
144 #define FAST_LEVEL(x) &level_fast##x, &level_fast##x##_dict,
145 #define LEVEL(x) &level_##x, &level_##x##_dict,
150 &no_pledged_src_size,
161 config_t const* const* configs = g_configs;
163 int config_skip_data(config_t const* config, data_t const* data) {
164 return config->use_dictionary && !data_has_dict(data);
167 int config_get_level(config_t const* config)
169 param_values_t const params = config->param_values;
171 for (i = 0; i < params.size; ++i) {
172 if (params.data[i].param == ZSTD_c_compressionLevel)
173 return (int)params.data[i].value;
175 return CONFIG_NO_LEVEL;
178 ZSTD_parameters config_get_zstd_params(
179 config_t const* config,
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)
188 zparams = ZSTD_getParams(
190 config->no_pledged_src_size ? ZSTD_CONTENTSIZE_UNKNOWN : srcSize,
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;
198 case ZSTD_c_checksumFlag:
199 zparams.fParams.checksumFlag = value;
201 case ZSTD_c_dictIDFlag:
202 zparams.fParams.noDictIDFlag = !value;
204 case ZSTD_c_windowLog:
205 zparams.cParams.windowLog = value;
207 case ZSTD_c_chainLog:
208 zparams.cParams.chainLog = value;
211 zparams.cParams.hashLog = value;
213 case ZSTD_c_searchLog:
214 zparams.cParams.searchLog = value;
216 case ZSTD_c_minMatch:
217 zparams.cParams.minMatch = value;
219 case ZSTD_c_targetLength:
220 zparams.cParams.targetLength = value;
222 case ZSTD_c_strategy:
223 zparams.cParams.strategy = (ZSTD_strategy)value;