Line | Branch | Exec | Source |
---|---|---|---|
1 | /* | ||
2 | * (c) 2001 Fabrice Bellard | ||
3 | * 2007 Marc Hoffman <marc.hoffman@analog.com> | ||
4 | * | ||
5 | * This file is part of FFmpeg. | ||
6 | * | ||
7 | * FFmpeg is free software; you can redistribute it and/or | ||
8 | * modify it under the terms of the GNU Lesser General Public | ||
9 | * License as published by the Free Software Foundation; either | ||
10 | * version 2.1 of the License, or (at your option) any later version. | ||
11 | * | ||
12 | * FFmpeg is distributed in the hope that it will be useful, | ||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
15 | * Lesser General Public License for more details. | ||
16 | * | ||
17 | * You should have received a copy of the GNU Lesser General Public | ||
18 | * License along with FFmpeg; if not, write to the Free Software | ||
19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
20 | */ | ||
21 | |||
22 | /** | ||
23 | * @file | ||
24 | * DCT test (c) 2001 Fabrice Bellard | ||
25 | * Started from sample code by Juan J. Sierralta P. | ||
26 | */ | ||
27 | |||
28 | #include "config.h" | ||
29 | #include "config_components.h" | ||
30 | #include <stdlib.h> | ||
31 | #include <stdio.h> | ||
32 | #include <string.h> | ||
33 | #if HAVE_UNISTD_H | ||
34 | #include <unistd.h> | ||
35 | #endif | ||
36 | #include <math.h> | ||
37 | |||
38 | #include "libavutil/cpu.h" | ||
39 | #include "libavutil/common.h" | ||
40 | #include "libavutil/emms.h" | ||
41 | #include "libavutil/internal.h" | ||
42 | #include "libavutil/lfg.h" | ||
43 | #include "libavutil/mem_internal.h" | ||
44 | #include "libavutil/time.h" | ||
45 | |||
46 | #include "libavcodec/dct.h" | ||
47 | #include "libavcodec/fdctdsp.h" | ||
48 | #include "libavcodec/idctdsp.h" | ||
49 | #include "libavcodec/simple_idct.h" | ||
50 | #include "libavcodec/xvididct.h" | ||
51 | #include "libavcodec/aandcttab.h" | ||
52 | #include "libavcodec/faandct.h" | ||
53 | #include "libavcodec/faanidct.h" | ||
54 | #include "libavcodec/dctref.h" | ||
55 | #include "libavcodec/proresdsp.c" | ||
56 | |||
57 | struct algo { | ||
58 | const char *name; | ||
59 | void (*func)(int16_t *block); | ||
60 | enum idct_permutation_type perm_type; | ||
61 | int cpu_flag; | ||
62 | int nonspec; | ||
63 | }; | ||
64 | |||
65 | static const struct algo fdct_tab[] = { | ||
66 | { "REF-DBL", ff_ref_fdct, FF_IDCT_PERM_NONE }, | ||
67 | { "IJG-AAN-INT", ff_fdct_ifast, FF_IDCT_PERM_NONE }, | ||
68 | { "IJG-LLM-INT", ff_jpeg_fdct_islow_8, FF_IDCT_PERM_NONE }, | ||
69 | #if CONFIG_FAANDCT | ||
70 | { "FAAN", ff_faandct, FF_IDCT_PERM_NONE }, | ||
71 | #endif /* CONFIG_FAANDCT */ | ||
72 | }; | ||
73 | |||
74 | 60000 | static void ff_prores_idct_wrap(int16_t *dst){ | |
75 | 60000 | LOCAL_ALIGNED(16, int16_t, qmat, [64]); | |
76 | int i; | ||
77 | |||
78 |
2/2✓ Branch 0 taken 3840000 times.
✓ Branch 1 taken 60000 times.
|
3900000 | for(i=0; i<64; i++){ |
79 | 3840000 | qmat[i]=4; | |
80 | } | ||
81 | 60000 | prores_idct_10(dst, qmat); | |
82 |
2/2✓ Branch 0 taken 3840000 times.
✓ Branch 1 taken 60000 times.
|
3900000 | for(i=0; i<64; i++) { |
83 | 3840000 | dst[i] -= 512; | |
84 | } | ||
85 | 60000 | } | |
86 | |||
87 | static const struct algo idct_tab[] = { | ||
88 | { "REF-DBL", ff_ref_idct, FF_IDCT_PERM_NONE }, | ||
89 | { "INT", ff_j_rev_dct, FF_IDCT_PERM_LIBMPEG2 }, | ||
90 | { "SIMPLE-C", ff_simple_idct_int16_8bit, FF_IDCT_PERM_NONE }, | ||
91 | { "SIMPLE-C10", ff_simple_idct_int16_10bit, FF_IDCT_PERM_NONE }, | ||
92 | { "SIMPLE-C12", ff_simple_idct_int16_12bit, FF_IDCT_PERM_NONE, 0, 1 }, | ||
93 | { "PR-C", ff_prores_idct_wrap, FF_IDCT_PERM_NONE, 0, 1 }, | ||
94 | #if CONFIG_FAANIDCT | ||
95 | { "FAANI", ff_faanidct, FF_IDCT_PERM_NONE }, | ||
96 | #endif /* CONFIG_FAANIDCT */ | ||
97 | #if CONFIG_MPEG4_DECODER | ||
98 | { "XVID", ff_xvid_idct, FF_IDCT_PERM_NONE, 0, 1 }, | ||
99 | #endif /* CONFIG_MPEG4_DECODER */ | ||
100 | }; | ||
101 | |||
102 | #if ARCH_AARCH64 | ||
103 | #include "aarch64/dct.c" | ||
104 | #elif ARCH_ARM | ||
105 | #include "arm/dct.c" | ||
106 | #elif ARCH_PPC | ||
107 | #include "ppc/dct.c" | ||
108 | #elif ARCH_X86 | ||
109 | #include "x86/dct.c" | ||
110 | #else | ||
111 | static const struct algo fdct_tab_arch[] = { { 0 } }; | ||
112 | static const struct algo idct_tab_arch[] = { { 0 } }; | ||
113 | #endif | ||
114 | |||
115 | #define AANSCALE_BITS 12 | ||
116 | |||
117 | #define NB_ITS 20000 | ||
118 | #define NB_ITS_SPEED 50000 | ||
119 | |||
120 | DECLARE_ALIGNED(16, static int16_t, block)[64]; | ||
121 | DECLARE_ALIGNED(8, static int16_t, block1)[64]; | ||
122 | |||
123 | 1120000 | static void init_block(int16_t block[64], int test, int is_idct, AVLFG *prng, int vals) | |
124 | { | ||
125 | int i, j; | ||
126 | |||
127 | 1120000 | memset(block, 0, 64 * sizeof(*block)); | |
128 | |||
129 |
3/4✓ Branch 0 taken 340000 times.
✓ Branch 1 taken 440000 times.
✓ Branch 2 taken 340000 times.
✗ Branch 3 not taken.
|
1120000 | switch (test) { |
130 | 340000 | case 0: | |
131 |
2/2✓ Branch 0 taken 21760000 times.
✓ Branch 1 taken 340000 times.
|
22100000 | for (i = 0; i < 64; i++) |
132 | 21760000 | block[i] = (av_lfg_get(prng) % (2*vals)) -vals; | |
133 |
1/2✓ Branch 0 taken 340000 times.
✗ Branch 1 not taken.
|
340000 | if (is_idct) { |
134 | 340000 | ff_ref_fdct(block); | |
135 |
2/2✓ Branch 0 taken 21760000 times.
✓ Branch 1 taken 340000 times.
|
22100000 | for (i = 0; i < 64; i++) |
136 | 21760000 | block[i] >>= 3; | |
137 | } | ||
138 | 340000 | break; | |
139 | 440000 | case 1: | |
140 | 440000 | j = av_lfg_get(prng) % 10 + 1; | |
141 |
2/2✓ Branch 0 taken 2413686 times.
✓ Branch 1 taken 440000 times.
|
2853686 | for (i = 0; i < j; i++) { |
142 | 2413686 | int idx = av_lfg_get(prng) % 64; | |
143 | 2413686 | block[idx] = av_lfg_get(prng) % (2*vals) -vals; | |
144 | } | ||
145 | 440000 | break; | |
146 | 340000 | case 2: | |
147 | 340000 | block[ 0] = av_lfg_get(prng) % (16*vals) - (8*vals); | |
148 | 340000 | block[63] = (block[0] & 1) ^ 1; | |
149 | 340000 | break; | |
150 | } | ||
151 | 1120000 | } | |
152 | |||
153 | 1120000 | static void permute(int16_t dst[64], const int16_t src[64], | |
154 | enum idct_permutation_type perm_type) | ||
155 | { | ||
156 | int i; | ||
157 | |||
158 | #if ARCH_X86 | ||
159 |
2/2✓ Branch 1 taken 60000 times.
✓ Branch 2 taken 1060000 times.
|
1120000 | if (permute_x86(dst, src, perm_type)) |
160 | 60000 | return; | |
161 | #endif | ||
162 | |||
163 |
3/4✓ Branch 0 taken 60000 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 480000 times.
✓ Branch 3 taken 520000 times.
|
1060000 | switch (perm_type) { |
164 | 60000 | case FF_IDCT_PERM_LIBMPEG2: | |
165 |
2/2✓ Branch 0 taken 3840000 times.
✓ Branch 1 taken 60000 times.
|
3900000 | for (i = 0; i < 64; i++) |
166 | 3840000 | dst[(i & 0x38) | ((i & 6) >> 1) | ((i & 1) << 2)] = src[i]; | |
167 | 60000 | break; | |
168 | ✗ | case FF_IDCT_PERM_PARTTRANS: | |
169 | ✗ | for (i = 0; i < 64; i++) | |
170 | ✗ | dst[(i & 0x24) | ((i & 3) << 3) | ((i >> 3) & 3)] = src[i]; | |
171 | ✗ | break; | |
172 | 480000 | case FF_IDCT_PERM_TRANSPOSE: | |
173 |
2/2✓ Branch 0 taken 30720000 times.
✓ Branch 1 taken 480000 times.
|
31200000 | for (i = 0; i < 64; i++) |
174 | 30720000 | dst[(i>>3) | ((i<<3)&0x38)] = src[i]; | |
175 | 480000 | break; | |
176 | 520000 | default: | |
177 |
2/2✓ Branch 0 taken 33280000 times.
✓ Branch 1 taken 520000 times.
|
33800000 | for (i = 0; i < 64; i++) |
178 | 33280000 | dst[i] = src[i]; | |
179 | 520000 | break; | |
180 | } | ||
181 | } | ||
182 | |||
183 | 56 | static int dct_error(const struct algo *dct, int test, int is_idct, int speed, const int bits) | |
184 | { | ||
185 |
2/2✓ Branch 0 taken 51 times.
✓ Branch 1 taken 5 times.
|
56 | void (*ref)(int16_t *block) = is_idct ? ff_ref_idct : ff_ref_fdct; |
186 | int it, i, scale; | ||
187 | int err_inf, v; | ||
188 | 56 | int64_t err2, ti, ti1, it1, err_sum = 0; | |
189 | 56 | int64_t sysErr[64], sysErrMax = 0; | |
190 | 56 | int64_t err2_matrix[64], err2_max = 0; | |
191 | 56 | int maxout = 0; | |
192 | 56 | int blockSumErrMax = 0, blockSumErr; | |
193 | AVLFG prng; | ||
194 | 56 | const int vals=1<<bits; | |
195 | double omse, ome; | ||
196 | int spec_err; | ||
197 | |||
198 | 56 | av_lfg_init(&prng, 1); | |
199 | |||
200 | 56 | err_inf = 0; | |
201 | 56 | err2 = 0; | |
202 |
2/2✓ Branch 0 taken 3584 times.
✓ Branch 1 taken 56 times.
|
3640 | for (i = 0; i < 64; i++) |
203 | 3584 | err2_matrix[i] = sysErr[i] = 0; | |
204 |
2/2✓ Branch 0 taken 1120000 times.
✓ Branch 1 taken 56 times.
|
1120056 | for (it = 0; it < NB_ITS; it++) { |
205 | 1120000 | init_block(block1, test, is_idct, &prng, vals); | |
206 | 1120000 | permute(block, block1, dct->perm_type); | |
207 | |||
208 | 1120000 | dct->func(block); | |
209 | 1120000 | emms_c(); | |
210 | |||
211 |
2/2✓ Branch 0 taken 20000 times.
✓ Branch 1 taken 1100000 times.
|
1120000 | if (!strcmp(dct->name, "IJG-AAN-INT")) { |
212 |
2/2✓ Branch 0 taken 1280000 times.
✓ Branch 1 taken 20000 times.
|
1300000 | for (i = 0; i < 64; i++) { |
213 | 1280000 | scale = 8 * (1 << (AANSCALE_BITS + 11)) / ff_aanscales[i]; | |
214 | 1280000 | block[i] = (block[i] * scale) >> AANSCALE_BITS; | |
215 | } | ||
216 | } | ||
217 | |||
218 | 1120000 | ref(block1); | |
219 |
2/2✓ Branch 0 taken 60000 times.
✓ Branch 1 taken 1060000 times.
|
1120000 | if (!strcmp(dct->name, "PR-SSE2")) |
220 |
2/2✓ Branch 0 taken 3840000 times.
✓ Branch 1 taken 60000 times.
|
3900000 | for (i = 0; i < 64; i++) |
221 | 3840000 | block1[i] = av_clip(block1[i], 4-512, 1019-512); | |
222 | |||
223 | 1120000 | blockSumErr = 0; | |
224 |
2/2✓ Branch 0 taken 71680000 times.
✓ Branch 1 taken 1120000 times.
|
72800000 | for (i = 0; i < 64; i++) { |
225 | 71680000 | int err = block[i] - block1[i]; | |
226 | 71680000 | err_sum += err; | |
227 | 71680000 | v = abs(err); | |
228 |
2/2✓ Branch 0 taken 61 times.
✓ Branch 1 taken 71679939 times.
|
71680000 | if (v > err_inf) |
229 | 61 | err_inf = v; | |
230 | 71680000 | err2_matrix[i] += v * (int64_t)v; | |
231 | 71680000 | err2 += v * (int64_t)v; | |
232 | 71680000 | sysErr[i] += block[i] - block1[i]; | |
233 | 71680000 | blockSumErr += v; | |
234 |
2/2✓ Branch 0 taken 756 times.
✓ Branch 1 taken 71679244 times.
|
71680000 | if (abs(block[i]) > maxout) |
235 | 756 | maxout = abs(block[i]); | |
236 | } | ||
237 |
2/2✓ Branch 0 taken 246 times.
✓ Branch 1 taken 1119754 times.
|
1120000 | if (blockSumErrMax < blockSumErr) |
238 | 246 | blockSumErrMax = blockSumErr; | |
239 | } | ||
240 |
2/2✓ Branch 0 taken 3584 times.
✓ Branch 1 taken 56 times.
|
3640 | for (i = 0; i < 64; i++) { |
241 | 3584 | sysErrMax = FFMAX(sysErrMax, FFABS(sysErr[i])); | |
242 | 3584 | err2_max = FFMAX(err2_max , FFABS(err2_matrix[i])); | |
243 | } | ||
244 | |||
245 |
2/2✓ Branch 0 taken 3584 times.
✓ Branch 1 taken 56 times.
|
3640 | for (i = 0; i < 64; i++) { |
246 |
2/2✓ Branch 0 taken 448 times.
✓ Branch 1 taken 3136 times.
|
3584 | if (i % 8 == 0) |
247 | 448 | printf("\n"); | |
248 | 3584 | printf("%7d ", (int) sysErr[i]); | |
249 | } | ||
250 | 56 | printf("\n"); | |
251 | |||
252 | 56 | omse = (double) err2 / NB_ITS / 64; | |
253 | 56 | ome = (double) err_sum / NB_ITS / 64; | |
254 | |||
255 |
7/8✓ Branch 0 taken 51 times.
✓ Branch 1 taken 5 times.
✓ Branch 2 taken 51 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 36 times.
✓ Branch 5 taken 15 times.
✓ Branch 6 taken 4 times.
✓ Branch 7 taken 32 times.
|
56 | spec_err = is_idct && (err_inf > 1 || omse > 0.02 || fabs(ome) > 0.0015); |
256 |
2/2✓ Branch 0 taken 39 times.
✓ Branch 1 taken 17 times.
|
56 | if (test < 2) |
257 |
6/6✓ Branch 0 taken 34 times.
✓ Branch 1 taken 5 times.
✓ Branch 2 taken 28 times.
✓ Branch 3 taken 6 times.
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 26 times.
|
39 | spec_err = is_idct && ((double) err2_max / NB_ITS > 0.06 || (double) sysErrMax / NB_ITS > 0.015); |
258 | |||
259 | 56 | printf("%s %s: max_err=%d omse=%0.8f ome=%0.8f syserr=%0.8f maxout=%d blockSumErr=%d\n", | |
260 | 56 | is_idct ? "IDCT" : "DCT", dct->name, err_inf, | |
261 |
2/2✓ Branch 0 taken 51 times.
✓ Branch 1 taken 5 times.
|
56 | omse, ome, (double) sysErrMax / NB_ITS, |
262 | maxout, blockSumErrMax); | ||
263 | |||
264 |
3/4✓ Branch 0 taken 13 times.
✓ Branch 1 taken 43 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 13 times.
|
56 | if (spec_err && !dct->nonspec) { |
265 | ✗ | printf("Failed!\n"); | |
266 | ✗ | return 1; | |
267 | } | ||
268 | |||
269 |
1/2✓ Branch 0 taken 56 times.
✗ Branch 1 not taken.
|
56 | if (!speed) |
270 | 56 | return 0; | |
271 | |||
272 | /* speed test */ | ||
273 | |||
274 | ✗ | init_block(block, test, is_idct, &prng, vals); | |
275 | ✗ | permute(block1, block, dct->perm_type); | |
276 | |||
277 | ✗ | ti = av_gettime_relative(); | |
278 | ✗ | it1 = 0; | |
279 | do { | ||
280 | ✗ | for (it = 0; it < NB_ITS_SPEED; it++) { | |
281 | ✗ | memcpy(block, block1, sizeof(block)); | |
282 | ✗ | dct->func(block); | |
283 | } | ||
284 | ✗ | emms_c(); | |
285 | ✗ | it1 += NB_ITS_SPEED; | |
286 | ✗ | ti1 = av_gettime_relative() - ti; | |
287 | ✗ | } while (ti1 < 1000000); | |
288 | |||
289 | ✗ | printf("%s %s: %0.1f kdct/s\n", is_idct ? "IDCT" : "DCT", dct->name, | |
290 | ✗ | (double) it1 * 1000.0 / (double) ti1); | |
291 | |||
292 | ✗ | return 0; | |
293 | } | ||
294 | |||
295 | DECLARE_ALIGNED(8, static uint8_t, img_dest)[64]; | ||
296 | DECLARE_ALIGNED(8, static uint8_t, img_dest1)[64]; | ||
297 | |||
298 | 20000 | static void idct248_ref(uint8_t *dest, ptrdiff_t linesize, int16_t *block) | |
299 | { | ||
300 | static int init; | ||
301 | static double c8[8][8]; | ||
302 | static double c4[4][4]; | ||
303 | double block1[64], block2[64], block3[64]; | ||
304 | double s, sum, v; | ||
305 | int i, j, k; | ||
306 | |||
307 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 19999 times.
|
20000 | if (!init) { |
308 | 1 | init = 1; | |
309 | |||
310 |
2/2✓ Branch 0 taken 8 times.
✓ Branch 1 taken 1 times.
|
9 | for (i = 0; i < 8; i++) { |
311 | 8 | sum = 0; | |
312 |
2/2✓ Branch 0 taken 64 times.
✓ Branch 1 taken 8 times.
|
72 | for (j = 0; j < 8; j++) { |
313 |
2/2✓ Branch 0 taken 8 times.
✓ Branch 1 taken 56 times.
|
64 | s = (i == 0) ? sqrt(1.0 / 8.0) : sqrt(1.0 / 4.0); |
314 | 64 | c8[i][j] = s * cos(M_PI * i * (j + 0.5) / 8.0); | |
315 | 64 | sum += c8[i][j] * c8[i][j]; | |
316 | } | ||
317 | } | ||
318 | |||
319 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1 times.
|
5 | for (i = 0; i < 4; i++) { |
320 | 4 | sum = 0; | |
321 |
2/2✓ Branch 0 taken 16 times.
✓ Branch 1 taken 4 times.
|
20 | for (j = 0; j < 4; j++) { |
322 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 12 times.
|
16 | s = (i == 0) ? sqrt(1.0 / 4.0) : sqrt(1.0 / 2.0); |
323 | 16 | c4[i][j] = s * cos(M_PI * i * (j + 0.5) / 4.0); | |
324 | 16 | sum += c4[i][j] * c4[i][j]; | |
325 | } | ||
326 | } | ||
327 | } | ||
328 | |||
329 | /* butterfly */ | ||
330 | 20000 | s = 0.5 * sqrt(2.0); | |
331 |
2/2✓ Branch 0 taken 80000 times.
✓ Branch 1 taken 20000 times.
|
100000 | for (i = 0; i < 4; i++) { |
332 |
2/2✓ Branch 0 taken 640000 times.
✓ Branch 1 taken 80000 times.
|
720000 | for (j = 0; j < 8; j++) { |
333 | 640000 | block1[8 * (2 * i) + j] = | |
334 | 640000 | (block[8 * (2 * i) + j] + block[8 * (2 * i + 1) + j]) * s; | |
335 | 640000 | block1[8 * (2 * i + 1) + j] = | |
336 | 640000 | (block[8 * (2 * i) + j] - block[8 * (2 * i + 1) + j]) * s; | |
337 | } | ||
338 | } | ||
339 | |||
340 | /* idct8 on lines */ | ||
341 |
2/2✓ Branch 0 taken 160000 times.
✓ Branch 1 taken 20000 times.
|
180000 | for (i = 0; i < 8; i++) { |
342 |
2/2✓ Branch 0 taken 1280000 times.
✓ Branch 1 taken 160000 times.
|
1440000 | for (j = 0; j < 8; j++) { |
343 | 1280000 | sum = 0; | |
344 |
2/2✓ Branch 0 taken 10240000 times.
✓ Branch 1 taken 1280000 times.
|
11520000 | for (k = 0; k < 8; k++) |
345 | 10240000 | sum += c8[k][j] * block1[8 * i + k]; | |
346 | 1280000 | block2[8 * i + j] = sum; | |
347 | } | ||
348 | } | ||
349 | |||
350 | /* idct4 */ | ||
351 |
2/2✓ Branch 0 taken 160000 times.
✓ Branch 1 taken 20000 times.
|
180000 | for (i = 0; i < 8; i++) { |
352 |
2/2✓ Branch 0 taken 640000 times.
✓ Branch 1 taken 160000 times.
|
800000 | for (j = 0; j < 4; j++) { |
353 | /* top */ | ||
354 | 640000 | sum = 0; | |
355 |
2/2✓ Branch 0 taken 2560000 times.
✓ Branch 1 taken 640000 times.
|
3200000 | for (k = 0; k < 4; k++) |
356 | 2560000 | sum += c4[k][j] * block2[8 * (2 * k) + i]; | |
357 | 640000 | block3[8 * (2 * j) + i] = sum; | |
358 | |||
359 | /* bottom */ | ||
360 | 640000 | sum = 0; | |
361 |
2/2✓ Branch 0 taken 2560000 times.
✓ Branch 1 taken 640000 times.
|
3200000 | for (k = 0; k < 4; k++) |
362 | 2560000 | sum += c4[k][j] * block2[8 * (2 * k + 1) + i]; | |
363 | 640000 | block3[8 * (2 * j + 1) + i] = sum; | |
364 | } | ||
365 | } | ||
366 | |||
367 | /* clamp and store the result */ | ||
368 |
2/2✓ Branch 0 taken 160000 times.
✓ Branch 1 taken 20000 times.
|
180000 | for (i = 0; i < 8; i++) { |
369 |
2/2✓ Branch 0 taken 1280000 times.
✓ Branch 1 taken 160000 times.
|
1440000 | for (j = 0; j < 8; j++) { |
370 | 1280000 | v = block3[8 * i + j]; | |
371 |
2/2✓ Branch 0 taken 53473 times.
✓ Branch 1 taken 1226527 times.
|
1280000 | if (v < 0) v = 0; |
372 |
2/2✓ Branch 0 taken 54705 times.
✓ Branch 1 taken 1171822 times.
|
1226527 | else if (v > 255) v = 255; |
373 | 1280000 | dest[i * linesize + j] = (int) rint(v); | |
374 | } | ||
375 | } | ||
376 | 20000 | } | |
377 | |||
378 | 1 | static void idct248_error(const char *name, | |
379 | void (*idct248_put)(uint8_t *dest, | ||
380 | ptrdiff_t line_size, | ||
381 | int16_t *block), | ||
382 | int speed) | ||
383 | { | ||
384 | int it, i, it1, ti, ti1, err_max, v; | ||
385 | AVLFG prng; | ||
386 | |||
387 | 1 | av_lfg_init(&prng, 1); | |
388 | |||
389 | /* just one test to see if code is correct (precision is less | ||
390 | important here) */ | ||
391 | 1 | err_max = 0; | |
392 |
2/2✓ Branch 0 taken 20000 times.
✓ Branch 1 taken 1 times.
|
20001 | for (it = 0; it < NB_ITS; it++) { |
393 | /* XXX: use forward transform to generate values */ | ||
394 |
2/2✓ Branch 0 taken 1280000 times.
✓ Branch 1 taken 20000 times.
|
1300000 | for (i = 0; i < 64; i++) |
395 | 1280000 | block1[i] = av_lfg_get(&prng) % 256 - 128; | |
396 | 20000 | block1[0] += 1024; | |
397 | |||
398 |
2/2✓ Branch 0 taken 1280000 times.
✓ Branch 1 taken 20000 times.
|
1300000 | for (i = 0; i < 64; i++) |
399 | 1280000 | block[i] = block1[i]; | |
400 | 20000 | idct248_ref(img_dest1, 8, block); | |
401 | |||
402 |
2/2✓ Branch 0 taken 1280000 times.
✓ Branch 1 taken 20000 times.
|
1300000 | for (i = 0; i < 64; i++) |
403 | 1280000 | block[i] = block1[i]; | |
404 | 20000 | idct248_put(img_dest, 8, block); | |
405 | |||
406 |
2/2✓ Branch 0 taken 1280000 times.
✓ Branch 1 taken 20000 times.
|
1300000 | for (i = 0; i < 64; i++) { |
407 | 1280000 | v = abs((int) img_dest[i] - (int) img_dest1[i]); | |
408 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1280000 times.
|
1280000 | if (v == 255) |
409 | ✗ | printf("%d %d\n", img_dest[i], img_dest1[i]); | |
410 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1279999 times.
|
1280000 | if (v > err_max) |
411 | 1 | err_max = v; | |
412 | } | ||
413 | #if 0 | ||
414 | printf("ref=\n"); | ||
415 | for(i=0;i<8;i++) { | ||
416 | int j; | ||
417 | for(j=0;j<8;j++) { | ||
418 | printf(" %3d", img_dest1[i*8+j]); | ||
419 | } | ||
420 | printf("\n"); | ||
421 | } | ||
422 | |||
423 | printf("out=\n"); | ||
424 | for(i=0;i<8;i++) { | ||
425 | int j; | ||
426 | for(j=0;j<8;j++) { | ||
427 | printf(" %3d", img_dest[i*8+j]); | ||
428 | } | ||
429 | printf("\n"); | ||
430 | } | ||
431 | #endif | ||
432 | } | ||
433 | 1 | printf("%s %s: err_inf=%d\n", 1 ? "IDCT248" : "DCT248", name, err_max); | |
434 | |||
435 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (!speed) |
436 | 1 | return; | |
437 | |||
438 | ✗ | ti = av_gettime_relative(); | |
439 | ✗ | it1 = 0; | |
440 | do { | ||
441 | ✗ | for (it = 0; it < NB_ITS_SPEED; it++) { | |
442 | ✗ | for (i = 0; i < 64; i++) | |
443 | ✗ | block[i] = block1[i]; | |
444 | ✗ | idct248_put(img_dest, 8, block); | |
445 | } | ||
446 | ✗ | emms_c(); | |
447 | ✗ | it1 += NB_ITS_SPEED; | |
448 | ✗ | ti1 = av_gettime_relative() - ti; | |
449 | ✗ | } while (ti1 < 1000000); | |
450 | |||
451 | ✗ | printf("%s %s: %0.1f kdct/s\n", 1 ? "IDCT248" : "DCT248", name, | |
452 | ✗ | (double) it1 * 1000.0 / (double) ti1); | |
453 | } | ||
454 | |||
455 | ✗ | static void help(void) | |
456 | { | ||
457 | ✗ | printf("dct-test [-i] [<test-number>] [<bits>]\n" | |
458 | "test-number 0 -> test with random matrixes\n" | ||
459 | " 1 -> test with random sparse matrixes\n" | ||
460 | " 2 -> do 3. test from MPEG-4 std\n" | ||
461 | "bits Number of time domain bits to use, 8 is default\n" | ||
462 | "-i test IDCT implementations\n" | ||
463 | "-4 test IDCT248 implementations\n" | ||
464 | "-t speed test\n"); | ||
465 | ✗ | } | |
466 | |||
467 | #if !HAVE_GETOPT | ||
468 | #include "compat/getopt.c" | ||
469 | #endif | ||
470 | |||
471 | 5 | int main(int argc, char **argv) | |
472 | { | ||
473 | 5 | int test_idct = 0, test_248_dct = 0; | |
474 | int c, i; | ||
475 | 5 | int test = 1; | |
476 | 5 | int speed = 0; | |
477 | 5 | int err = 0; | |
478 | 5 | int bits=8; | |
479 | |||
480 | 5 | ff_ref_dct_init(); | |
481 | |||
482 | for (;;) { | ||
483 | 9 | c = getopt(argc, argv, "ih4t"); | |
484 |
2/2✓ Branch 0 taken 5 times.
✓ Branch 1 taken 4 times.
|
9 | if (c == -1) |
485 | 5 | break; | |
486 |
2/4✓ Branch 0 taken 3 times.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
4 | switch (c) { |
487 | 3 | case 'i': | |
488 | 3 | test_idct = 1; | |
489 | 3 | break; | |
490 | 1 | case '4': | |
491 | 1 | test_248_dct = 1; | |
492 | 1 | break; | |
493 | ✗ | case 't': | |
494 | ✗ | speed = 1; | |
495 | ✗ | break; | |
496 | ✗ | default: | |
497 | case 'h': | ||
498 | ✗ | help(); | |
499 | ✗ | return 0; | |
500 | } | ||
501 | } | ||
502 | |||
503 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 2 times.
|
5 | if (optind < argc) |
504 | 3 | test = atoi(argv[optind]); | |
505 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
|
5 | if(optind+1 < argc) bits= atoi(argv[optind+1]); |
506 | |||
507 | 5 | printf("ffmpeg DCT/IDCT test\n"); | |
508 | |||
509 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 4 times.
|
5 | if (test_248_dct) { |
510 | 1 | idct248_error("SIMPLE-C", ff_simple_idct248_put, speed); | |
511 | } else { | ||
512 | 4 | const int cpu_flags = av_get_cpu_flags(); | |
513 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 1 times.
|
4 | if (test_idct) { |
514 |
2/2✓ Branch 0 taken 24 times.
✓ Branch 1 taken 3 times.
|
27 | for (i = 0; i < FF_ARRAY_ELEMS(idct_tab); i++) |
515 | 24 | err |= dct_error(&idct_tab[i], test, test_idct, speed, bits); | |
516 | |||
517 |
2/2✓ Branch 0 taken 27 times.
✓ Branch 1 taken 3 times.
|
30 | for (i = 0; idct_tab_arch[i].name; i++) |
518 |
1/2✓ Branch 0 taken 27 times.
✗ Branch 1 not taken.
|
27 | if (!(~cpu_flags & idct_tab_arch[i].cpu_flag)) |
519 | 27 | err |= dct_error(&idct_tab_arch[i], test, test_idct, speed, bits); | |
520 | } | ||
521 | #if CONFIG_FDCTDSP | ||
522 | else { | ||
523 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1 times.
|
5 | for (i = 0; i < FF_ARRAY_ELEMS(fdct_tab); i++) |
524 | 4 | err |= dct_error(&fdct_tab[i], test, test_idct, speed, bits); | |
525 | |||
526 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
|
2 | for (i = 0; fdct_tab_arch[i].name; i++) |
527 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (!(~cpu_flags & fdct_tab_arch[i].cpu_flag)) |
528 | 1 | err |= dct_error(&fdct_tab_arch[i], test, test_idct, speed, bits); | |
529 | } | ||
530 | #endif /* CONFIG_FDCTDSP */ | ||
531 | } | ||
532 | |||
533 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
|
5 | if (err) |
534 | ✗ | printf("Error: %d.\n", err); | |
535 | |||
536 | 5 | return !!err; | |
537 | } | ||
538 |