Line | Branch | Exec | Source |
---|---|---|---|
1 | /* | ||
2 | * | ||
3 | * This file is part of FFmpeg. | ||
4 | * | ||
5 | * FFmpeg is free software; you can redistribute it and/or modify | ||
6 | * it under the terms of the GNU General Public License as published by | ||
7 | * the Free Software Foundation; either version 2 of the License, or | ||
8 | * (at your option) any later version. | ||
9 | * | ||
10 | * FFmpeg is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU General Public License along | ||
16 | * with FFmpeg; if not, write to the Free Software Foundation, Inc., | ||
17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
18 | */ | ||
19 | |||
20 | #include <string.h> | ||
21 | |||
22 | #include "libavutil/common.h" | ||
23 | #include "libavutil/intreadwrite.h" | ||
24 | #include "libavutil/mem.h" | ||
25 | #include "libavutil/mem_internal.h" | ||
26 | |||
27 | #include "libswscale/swscale.h" | ||
28 | #include "libswscale/swscale_internal.h" | ||
29 | |||
30 | #include "checkasm.h" | ||
31 | |||
32 | #define randomize_buffers(buf, size) \ | ||
33 | do { \ | ||
34 | int j; \ | ||
35 | for (j = 0; j < size; j+=4) \ | ||
36 | AV_WN32(buf + j, rnd()); \ | ||
37 | } while (0) | ||
38 | |||
39 | 608 | static void yuv2planeX_8_ref(const int16_t *filter, int filterSize, | |
40 | const int16_t **src, uint8_t *dest, int dstW, | ||
41 | const uint8_t *dither, int offset) | ||
42 | { | ||
43 | // This corresponds to the yuv2planeX_8_c function | ||
44 | int i; | ||
45 |
2/2✓ Branch 0 taken 122112 times.
✓ Branch 1 taken 608 times.
|
122720 | for (i = 0; i < dstW; i++) { |
46 | 122112 | int val = dither[(i + offset) & 7] << 12; | |
47 | int j; | ||
48 |
2/2✓ Branch 0 taken 915840 times.
✓ Branch 1 taken 122112 times.
|
1037952 | for (j = 0; j < filterSize; j++) |
49 | 915840 | val += src[j][i] * filter[j]; | |
50 | |||
51 | 122112 | dest[i]= av_clip_uint8(val >> 19); | |
52 | } | ||
53 | 608 | } | |
54 | |||
55 | 824 | static int cmp_off_by_n(const uint8_t *ref, const uint8_t *test, size_t n, int accuracy) | |
56 | { | ||
57 |
2/2✓ Branch 0 taken 362752 times.
✓ Branch 1 taken 824 times.
|
363576 | for (size_t i = 0; i < n; i++) { |
58 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 362752 times.
|
362752 | if (abs(ref[i] - test[i]) > accuracy) |
59 | ✗ | return 1; | |
60 | } | ||
61 | 824 | return 0; | |
62 | } | ||
63 | |||
64 | ✗ | static void print_data(uint8_t *p, size_t len, size_t offset) | |
65 | { | ||
66 | ✗ | size_t i = 0; | |
67 | ✗ | for (; i < len; i++) { | |
68 | ✗ | if (i % 8 == 0) { | |
69 | ✗ | printf("0x%04zx: ", i+offset); | |
70 | } | ||
71 | ✗ | printf("0x%02x ", (uint32_t) p[i]); | |
72 | ✗ | if (i % 8 == 7) { | |
73 | ✗ | printf("\n"); | |
74 | } | ||
75 | } | ||
76 | ✗ | if (i % 8 != 0) { | |
77 | ✗ | printf("\n"); | |
78 | } | ||
79 | ✗ | } | |
80 | |||
81 | ✗ | static size_t show_differences(uint8_t *a, uint8_t *b, size_t len) | |
82 | { | ||
83 | ✗ | for (size_t i = 0; i < len; i++) { | |
84 | ✗ | if (a[i] != b[i]) { | |
85 | ✗ | size_t offset_of_mismatch = i; | |
86 | size_t offset; | ||
87 | ✗ | if (i >= 8) i-=8; | |
88 | ✗ | offset = i & (~7); | |
89 | ✗ | printf("test a:\n"); | |
90 | ✗ | print_data(&a[offset], 32, offset); | |
91 | ✗ | printf("\ntest b:\n"); | |
92 | ✗ | print_data(&b[offset], 32, offset); | |
93 | ✗ | printf("\n"); | |
94 | ✗ | return offset_of_mismatch; | |
95 | } | ||
96 | } | ||
97 | ✗ | return len; | |
98 | } | ||
99 | |||
100 | 26 | static void check_yuv2yuv1(int accurate) | |
101 | { | ||
102 | SwsContext *sws; | ||
103 | SwsInternal *c; | ||
104 | int osi, isi; | ||
105 | int dstW, offset; | ||
106 | size_t fail_offset; | ||
107 | 26 | const int input_sizes[] = {8, 24, 128, 144, 256, 512}; | |
108 | #define LARGEST_INPUT_SIZE 512 | ||
109 | |||
110 | 26 | const int offsets[] = {0, 3, 8, 11, 16, 19}; | |
111 | 26 | const int OFFSET_SIZES = sizeof(offsets)/sizeof(offsets[0]); | |
112 |
2/2✓ Branch 0 taken 13 times.
✓ Branch 1 taken 13 times.
|
26 | const char *accurate_str = (accurate) ? "accurate" : "approximate"; |
113 | |||
114 | 26 | declare_func(void, | |
115 | const int16_t *src, uint8_t *dest, | ||
116 | int dstW, const uint8_t *dither, int offset); | ||
117 | |||
118 | 26 | LOCAL_ALIGNED_16(int16_t, src_pixels, [LARGEST_INPUT_SIZE]); | |
119 | 26 | LOCAL_ALIGNED_16(uint8_t, dst0, [LARGEST_INPUT_SIZE]); | |
120 | 26 | LOCAL_ALIGNED_16(uint8_t, dst1, [LARGEST_INPUT_SIZE]); | |
121 | 26 | LOCAL_ALIGNED_8(uint8_t, dither, [8]); | |
122 | |||
123 |
2/2✓ Branch 1 taken 52 times.
✓ Branch 2 taken 26 times.
|
78 | randomize_buffers((uint8_t*)dither, 8); |
124 |
2/2✓ Branch 1 taken 6656 times.
✓ Branch 2 taken 26 times.
|
6682 | randomize_buffers((uint8_t*)src_pixels, LARGEST_INPUT_SIZE * sizeof(int16_t)); |
125 | 26 | sws = sws_alloc_context(); | |
126 |
2/2✓ Branch 0 taken 13 times.
✓ Branch 1 taken 13 times.
|
26 | if (accurate) |
127 | 13 | sws->flags |= SWS_ACCURATE_RND; | |
128 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 26 times.
|
26 | if (sws_init_context(sws, NULL, NULL) < 0) |
129 | ✗ | fail(); | |
130 | |||
131 | 26 | c = sws_internal(sws); | |
132 | 26 | ff_sws_init_scale(c); | |
133 |
2/2✓ Branch 0 taken 156 times.
✓ Branch 1 taken 26 times.
|
182 | for (isi = 0; isi < FF_ARRAY_ELEMS(input_sizes); ++isi) { |
134 | 156 | dstW = input_sizes[isi]; | |
135 |
2/2✓ Branch 0 taken 936 times.
✓ Branch 1 taken 156 times.
|
1092 | for (osi = 0; osi < OFFSET_SIZES; osi++) { |
136 | 936 | offset = offsets[osi]; | |
137 |
2/2✓ Branch 3 taken 144 times.
✓ Branch 4 taken 792 times.
|
936 | if (check_func(c->yuv2plane1, "yuv2yuv1_%d_%d_%s", offset, dstW, accurate_str)){ |
138 | 144 | memset(dst0, 0, LARGEST_INPUT_SIZE * sizeof(dst0[0])); | |
139 | 144 | memset(dst1, 0, LARGEST_INPUT_SIZE * sizeof(dst1[0])); | |
140 | |||
141 | 144 | call_ref(src_pixels, dst0, dstW, dither, offset); | |
142 | 144 | call_new(src_pixels, dst1, dstW, dither, offset); | |
143 |
3/4✓ Branch 0 taken 36 times.
✓ Branch 1 taken 108 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 144 times.
|
144 | if (cmp_off_by_n(dst0, dst1, dstW * sizeof(dst0[0]), accurate ? 0 : 2)) { |
144 | ✗ | fail(); | |
145 | ✗ | printf("failed: yuv2yuv1_%d_%di_%s\n", offset, dstW, accurate_str); | |
146 | ✗ | fail_offset = show_differences(dst0, dst1, LARGEST_INPUT_SIZE * sizeof(dst0[0])); | |
147 | ✗ | printf("failing values: src: 0x%04x dither: 0x%02x dst-c: %02x dst-asm: %02x\n", | |
148 | ✗ | (int) src_pixels[fail_offset], | |
149 | ✗ | (int) dither[(fail_offset + fail_offset) & 7], | |
150 | ✗ | (int) dst0[fail_offset], | |
151 | ✗ | (int) dst1[fail_offset]); | |
152 | } | ||
153 |
2/2✓ Branch 0 taken 24 times.
✓ Branch 1 taken 120 times.
|
144 | if(dstW == LARGEST_INPUT_SIZE) |
154 |
1/8✗ Branch 1 not taken.
✓ Branch 2 taken 24 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
|
24 | bench_new(src_pixels, dst1, dstW, dither, offset); |
155 | } | ||
156 | } | ||
157 | } | ||
158 | 26 | sws_freeContext(sws); | |
159 | 26 | } | |
160 | |||
161 | 26 | static void check_yuv2yuvX(int accurate) | |
162 | { | ||
163 | SwsContext *sws; | ||
164 | SwsInternal *c; | ||
165 | int fsi, osi, isi, i, j; | ||
166 | int dstW; | ||
167 | #define LARGEST_FILTER 16 | ||
168 | // ff_yuv2planeX_8_sse2 can't handle odd filter sizes | ||
169 | 26 | const int filter_sizes[] = {2, 4, 8, 16}; | |
170 | 26 | const int FILTER_SIZES = sizeof(filter_sizes)/sizeof(filter_sizes[0]); | |
171 | #define LARGEST_INPUT_SIZE 512 | ||
172 | static const int input_sizes[] = {8, 24, 128, 144, 256, 512}; | ||
173 |
2/2✓ Branch 0 taken 13 times.
✓ Branch 1 taken 13 times.
|
26 | const char *accurate_str = (accurate) ? "accurate" : "approximate"; |
174 | |||
175 |
2/2✓ Branch 1 taken 24 times.
✓ Branch 2 taken 2 times.
|
26 | declare_func_emms(AV_CPU_FLAG_MMX, void, const int16_t *filter, |
176 | int filterSize, const int16_t **src, uint8_t *dest, | ||
177 | int dstW, const uint8_t *dither, int offset); | ||
178 | |||
179 | const int16_t **src; | ||
180 | 26 | LOCAL_ALIGNED_16(int16_t, src_pixels, [LARGEST_FILTER * LARGEST_INPUT_SIZE]); | |
181 | 26 | LOCAL_ALIGNED_16(int16_t, filter_coeff, [LARGEST_FILTER]); | |
182 | 26 | LOCAL_ALIGNED_16(uint8_t, dst0, [LARGEST_INPUT_SIZE]); | |
183 | 26 | LOCAL_ALIGNED_16(uint8_t, dst1, [LARGEST_INPUT_SIZE]); | |
184 | 26 | LOCAL_ALIGNED_16(uint8_t, dither, [LARGEST_INPUT_SIZE]); | |
185 | union VFilterData{ | ||
186 | const int16_t *src; | ||
187 | uint16_t coeff[8]; | ||
188 | } *vFilterData; | ||
189 | 26 | uint8_t d_val = rnd(); | |
190 | 26 | memset(dither, d_val, LARGEST_INPUT_SIZE); | |
191 |
2/2✓ Branch 1 taken 106496 times.
✓ Branch 2 taken 26 times.
|
106522 | randomize_buffers((uint8_t*)src_pixels, LARGEST_FILTER * LARGEST_INPUT_SIZE * sizeof(int16_t)); |
192 | 26 | sws = sws_alloc_context(); | |
193 |
2/2✓ Branch 0 taken 13 times.
✓ Branch 1 taken 13 times.
|
26 | if (accurate) |
194 | 13 | sws->flags |= SWS_ACCURATE_RND; | |
195 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 26 times.
|
26 | if (sws_init_context(sws, NULL, NULL) < 0) |
196 | ✗ | fail(); | |
197 | |||
198 | 26 | c = sws_internal(sws); | |
199 | 26 | ff_sws_init_scale(c); | |
200 |
2/2✓ Branch 0 taken 156 times.
✓ Branch 1 taken 26 times.
|
182 | for(isi = 0; isi < FF_ARRAY_ELEMS(input_sizes); ++isi){ |
201 | 156 | dstW = input_sizes[isi]; | |
202 |
2/2✓ Branch 0 taken 624 times.
✓ Branch 1 taken 156 times.
|
780 | for(osi = 0; osi < 64; osi += 16){ |
203 |
2/2✓ Branch 0 taken 130 times.
✓ Branch 1 taken 494 times.
|
624 | if (dstW <= osi) |
204 | 130 | continue; | |
205 |
2/2✓ Branch 0 taken 1976 times.
✓ Branch 1 taken 494 times.
|
2470 | for (fsi = 0; fsi < FILTER_SIZES; ++fsi) { |
206 | // Generate filter coefficients for the given filter size, | ||
207 | // with some properties: | ||
208 | // - The coefficients add up to the intended sum (4096, 1<<12) | ||
209 | // - The coefficients contain negative values | ||
210 | // - The filter intermediates don't overflow for worst case | ||
211 | // inputs (all positive coefficients are coupled with | ||
212 | // input_max and all negative coefficients with input_min, | ||
213 | // or vice versa). | ||
214 | // Produce a filter with all coefficients set to | ||
215 | // -((1<<12)/(filter_size-1)) except for one (randomly chosen) | ||
216 | // which is set to ((1<<13)-1). | ||
217 |
2/2✓ Branch 0 taken 14820 times.
✓ Branch 1 taken 1976 times.
|
16796 | for (i = 0; i < filter_sizes[fsi]; ++i) |
218 | 14820 | filter_coeff[i] = -((1 << 12) / (filter_sizes[fsi] - 1)); | |
219 | 1976 | filter_coeff[rnd() % filter_sizes[fsi]] = (1 << 13) - 1; | |
220 | |||
221 | 1976 | src = av_malloc(sizeof(int16_t*) * filter_sizes[fsi]); | |
222 | 1976 | vFilterData = av_malloc((filter_sizes[fsi] + 2) * sizeof(union VFilterData)); | |
223 | 1976 | memset(vFilterData, 0, (filter_sizes[fsi] + 2) * sizeof(union VFilterData)); | |
224 |
2/2✓ Branch 0 taken 14820 times.
✓ Branch 1 taken 1976 times.
|
16796 | for (i = 0; i < filter_sizes[fsi]; ++i) { |
225 | 14820 | src[i] = &src_pixels[i * LARGEST_INPUT_SIZE]; | |
226 | 14820 | vFilterData[i].src = src[i] - osi; | |
227 |
2/2✓ Branch 0 taken 59280 times.
✓ Branch 1 taken 14820 times.
|
74100 | for(j = 0; j < 4; ++j) |
228 | 59280 | vFilterData[i].coeff[j + 4] = filter_coeff[i]; | |
229 | } | ||
230 |
2/2✓ Branch 3 taken 608 times.
✓ Branch 4 taken 1368 times.
|
1976 | if (check_func(c->yuv2planeX, "yuv2yuvX_%d_%d_%d_%s", filter_sizes[fsi], osi, dstW, accurate_str)){ |
231 | // use vFilterData for the mmx function | ||
232 |
2/2✓ Branch 0 taken 228 times.
✓ Branch 1 taken 380 times.
|
608 | const int16_t *filter = c->use_mmx_vfilter ? (const int16_t*)vFilterData : &filter_coeff[0]; |
233 | 608 | memset(dst0, 0, LARGEST_INPUT_SIZE * sizeof(dst0[0])); | |
234 | 608 | memset(dst1, 0, LARGEST_INPUT_SIZE * sizeof(dst1[0])); | |
235 | |||
236 | // We can't use call_ref here, because we don't know if use_mmx_vfilter was set for that | ||
237 | // function or not, so we can't pass it the parameters correctly. | ||
238 | 608 | yuv2planeX_8_ref(&filter_coeff[0], filter_sizes[fsi], src, dst0, dstW - osi, dither, osi); | |
239 | |||
240 | 608 | call_new(filter, filter_sizes[fsi], src, dst1, dstW - osi, dither, osi); | |
241 |
3/4✓ Branch 0 taken 304 times.
✓ Branch 1 taken 304 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 608 times.
|
608 | if (cmp_off_by_n(dst0, dst1, LARGEST_INPUT_SIZE * sizeof(dst0[0]), accurate ? 0 : 2)) { |
242 | ✗ | fail(); | |
243 | ✗ | printf("failed: yuv2yuvX_%d_%d_%d_%s\n", filter_sizes[fsi], osi, dstW, accurate_str); | |
244 | ✗ | show_differences(dst0, dst1, LARGEST_INPUT_SIZE * sizeof(dst0[0])); | |
245 | } | ||
246 |
2/2✓ Branch 0 taken 128 times.
✓ Branch 1 taken 480 times.
|
608 | if(dstW == LARGEST_INPUT_SIZE) |
247 |
1/8✗ Branch 1 not taken.
✓ Branch 2 taken 128 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
|
128 | bench_new((const int16_t*)vFilterData, filter_sizes[fsi], src, dst1, dstW - osi, dither, osi); |
248 | |||
249 | } | ||
250 | 1976 | av_freep(&src); | |
251 | 1976 | av_freep(&vFilterData); | |
252 | } | ||
253 | } | ||
254 | } | ||
255 | 26 | sws_freeContext(sws); | |
256 | #undef FILTER_SIZES | ||
257 | 26 | } | |
258 | |||
259 | 26 | static void check_yuv2nv12cX(int accurate) | |
260 | { | ||
261 | SwsContext *sws; | ||
262 | SwsInternal *c; | ||
263 | #define LARGEST_FILTER 16 | ||
264 | 26 | const int filter_sizes[] = {2, 4, 8, 16}; | |
265 | #define LARGEST_INPUT_SIZE 512 | ||
266 | static const int input_sizes[] = {8, 24, 128, 144, 256, 512}; | ||
267 |
2/2✓ Branch 0 taken 13 times.
✓ Branch 1 taken 13 times.
|
26 | const char *accurate_str = (accurate) ? "accurate" : "approximate"; |
268 | |||
269 |
2/2✓ Branch 1 taken 24 times.
✓ Branch 2 taken 2 times.
|
26 | declare_func_emms(AV_CPU_FLAG_MMX, void, enum AVPixelFormat dstFormat, |
270 | const uint8_t *chrDither, const int16_t *chrFilter, | ||
271 | int chrFilterSize, const int16_t **chrUSrc, | ||
272 | const int16_t **chrVSrc, uint8_t *dest, int dstW); | ||
273 | |||
274 | const int16_t *srcU[LARGEST_FILTER], *srcV[LARGEST_FILTER]; | ||
275 | 26 | LOCAL_ALIGNED_16(int16_t, srcU_pixels, [LARGEST_FILTER * LARGEST_INPUT_SIZE]); | |
276 | 26 | LOCAL_ALIGNED_16(int16_t, srcV_pixels, [LARGEST_FILTER * LARGEST_INPUT_SIZE]); | |
277 | 26 | LOCAL_ALIGNED_16(int16_t, filter_coeff, [LARGEST_FILTER]); | |
278 | 26 | LOCAL_ALIGNED_16(uint8_t, dst0, [LARGEST_INPUT_SIZE * 2]); | |
279 | 26 | LOCAL_ALIGNED_16(uint8_t, dst1, [LARGEST_INPUT_SIZE * 2]); | |
280 | 26 | LOCAL_ALIGNED_16(uint8_t, dither, [LARGEST_INPUT_SIZE]); | |
281 | 26 | uint8_t d_val = rnd(); | |
282 | 26 | memset(dither, d_val, LARGEST_INPUT_SIZE); | |
283 |
2/2✓ Branch 1 taken 106496 times.
✓ Branch 2 taken 26 times.
|
106522 | randomize_buffers((uint8_t*)srcU_pixels, LARGEST_FILTER * LARGEST_INPUT_SIZE * sizeof(int16_t)); |
284 |
2/2✓ Branch 1 taken 106496 times.
✓ Branch 2 taken 26 times.
|
106522 | randomize_buffers((uint8_t*)srcV_pixels, LARGEST_FILTER * LARGEST_INPUT_SIZE * sizeof(int16_t)); |
285 |
2/2✓ Branch 0 taken 416 times.
✓ Branch 1 taken 26 times.
|
442 | for (int i = 0; i < LARGEST_FILTER; i++) { |
286 | 416 | srcU[i] = &srcU_pixels[i * LARGEST_INPUT_SIZE]; | |
287 | 416 | srcV[i] = &srcV_pixels[i * LARGEST_INPUT_SIZE]; | |
288 | } | ||
289 | |||
290 | 26 | sws = sws_alloc_context(); | |
291 | 26 | sws->dst_format = AV_PIX_FMT_NV12; | |
292 |
2/2✓ Branch 0 taken 13 times.
✓ Branch 1 taken 13 times.
|
26 | if (accurate) |
293 | 13 | sws->flags |= SWS_ACCURATE_RND; | |
294 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 26 times.
|
26 | if (sws_init_context(sws, NULL, NULL) < 0) |
295 | ✗ | fail(); | |
296 | |||
297 | 26 | c = sws_internal(sws); | |
298 | 26 | ff_sws_init_scale(c); | |
299 |
2/2✓ Branch 0 taken 156 times.
✓ Branch 1 taken 26 times.
|
182 | for (int isi = 0; isi < FF_ARRAY_ELEMS(input_sizes); isi++){ |
300 | 156 | const int dstW = input_sizes[isi]; | |
301 |
2/2✓ Branch 0 taken 624 times.
✓ Branch 1 taken 156 times.
|
780 | for (int fsi = 0; fsi < FF_ARRAY_ELEMS(filter_sizes); fsi++) { |
302 | 624 | const int filter_size = filter_sizes[fsi]; | |
303 |
2/2✓ Branch 0 taken 4680 times.
✓ Branch 1 taken 624 times.
|
5304 | for (int i = 0; i < filter_size; i++) |
304 | 4680 | filter_coeff[i] = -((1 << 12) / (filter_size - 1)); | |
305 | 624 | filter_coeff[rnd() % filter_size] = (1 << 13) - 1; | |
306 | |||
307 |
2/2✓ Branch 3 taken 72 times.
✓ Branch 4 taken 552 times.
|
624 | if (check_func(c->yuv2nv12cX, "yuv2nv12cX_%d_%d_%s", filter_size, dstW, accurate_str)){ |
308 | 72 | memset(dst0, 0, LARGEST_INPUT_SIZE * sizeof(dst0[0])); | |
309 | 72 | memset(dst1, 0, LARGEST_INPUT_SIZE * sizeof(dst1[0])); | |
310 | |||
311 | 72 | call_ref(sws->dst_format, dither, &filter_coeff[0], filter_size, srcU, srcV, dst0, dstW); | |
312 | 72 | call_new(sws->dst_format, dither, &filter_coeff[0], filter_size, srcU, srcV, dst1, dstW); | |
313 | |||
314 |
3/4✓ Branch 0 taken 24 times.
✓ Branch 1 taken 48 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 72 times.
|
72 | if (cmp_off_by_n(dst0, dst1, dstW * 2 * sizeof(dst0[0]), accurate ? 0 : 2)) { |
315 | ✗ | fail(); | |
316 | ✗ | printf("failed: yuv2nv12wX_%d_%d_%s\n", filter_size, dstW, accurate_str); | |
317 | ✗ | show_differences(dst0, dst1, dstW * 2 * sizeof(dst0[0])); | |
318 | } | ||
319 |
2/2✓ Branch 0 taken 12 times.
✓ Branch 1 taken 60 times.
|
72 | if (dstW == LARGEST_INPUT_SIZE) |
320 |
1/8✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
|
12 | bench_new(sws->dst_format, dither, &filter_coeff[0], filter_size, srcU, srcV, dst1, dstW); |
321 | |||
322 | } | ||
323 | } | ||
324 | } | ||
325 | 26 | sws_freeContext(sws); | |
326 | 26 | } | |
327 | #undef LARGEST_FILTER | ||
328 | #undef LARGEST_INPUT_SIZE | ||
329 | |||
330 | #undef SRC_PIXELS | ||
331 | #define SRC_PIXELS 512 | ||
332 | |||
333 | 13 | static void check_hscale(void) | |
334 | { | ||
335 | #define MAX_FILTER_WIDTH 40 | ||
336 | #define FILTER_SIZES 6 | ||
337 | static const int filter_sizes[FILTER_SIZES] = { 4, 8, 12, 16, 32, 40 }; | ||
338 | |||
339 | #define HSCALE_PAIRS 2 | ||
340 | static const int hscale_pairs[HSCALE_PAIRS][2] = { | ||
341 | { 8, 14 }, | ||
342 | { 8, 18 }, | ||
343 | }; | ||
344 | |||
345 | #define LARGEST_INPUT_SIZE 512 | ||
346 | static const int input_sizes[] = {8, 24, 128, 144, 256, 512}; | ||
347 | |||
348 | int i, j, fsi, hpi, width, dstWi; | ||
349 | SwsContext *sws; | ||
350 | SwsInternal *c; | ||
351 | |||
352 | // padded | ||
353 | 13 | LOCAL_ALIGNED_32(uint8_t, src, [FFALIGN(SRC_PIXELS + MAX_FILTER_WIDTH - 1, 4)]); | |
354 | 13 | LOCAL_ALIGNED_32(uint32_t, dst0, [SRC_PIXELS]); | |
355 | 13 | LOCAL_ALIGNED_32(uint32_t, dst1, [SRC_PIXELS]); | |
356 | |||
357 | // padded | ||
358 | 13 | LOCAL_ALIGNED_32(int16_t, filter, [SRC_PIXELS * MAX_FILTER_WIDTH + MAX_FILTER_WIDTH]); | |
359 | 13 | LOCAL_ALIGNED_32(int32_t, filterPos, [SRC_PIXELS]); | |
360 | 13 | LOCAL_ALIGNED_32(int16_t, filterAvx2, [SRC_PIXELS * MAX_FILTER_WIDTH + MAX_FILTER_WIDTH]); | |
361 | 13 | LOCAL_ALIGNED_32(int32_t, filterPosAvx, [SRC_PIXELS]); | |
362 | |||
363 | // The dst parameter here is either int16_t or int32_t but we use void* to | ||
364 | // just cover both cases. | ||
365 | 13 | declare_func(void, void *c, void *dst, int dstW, | |
366 | const uint8_t *src, const int16_t *filter, | ||
367 | const int32_t *filterPos, int filterSize); | ||
368 | |||
369 | 13 | sws = sws_alloc_context(); | |
370 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 13 times.
|
13 | if (sws_init_context(sws, NULL, NULL) < 0) |
371 | ✗ | fail(); | |
372 | |||
373 | 13 | c = sws_internal(sws); | |
374 |
2/2✓ Branch 1 taken 1794 times.
✓ Branch 2 taken 13 times.
|
1807 | randomize_buffers(src, SRC_PIXELS + MAX_FILTER_WIDTH - 1); |
375 | |||
376 |
2/2✓ Branch 0 taken 26 times.
✓ Branch 1 taken 13 times.
|
39 | for (hpi = 0; hpi < HSCALE_PAIRS; hpi++) { |
377 |
2/2✓ Branch 0 taken 156 times.
✓ Branch 1 taken 26 times.
|
182 | for (fsi = 0; fsi < FILTER_SIZES; fsi++) { |
378 |
2/2✓ Branch 0 taken 936 times.
✓ Branch 1 taken 156 times.
|
1092 | for (dstWi = 0; dstWi < FF_ARRAY_ELEMS(input_sizes); dstWi++) { |
379 | 936 | width = filter_sizes[fsi]; | |
380 | |||
381 | 936 | c->srcBpc = hscale_pairs[hpi][0]; | |
382 | 936 | c->dstBpc = hscale_pairs[hpi][1]; | |
383 | 936 | c->hLumFilterSize = c->hChrFilterSize = width; | |
384 | |||
385 |
2/2✓ Branch 0 taken 479232 times.
✓ Branch 1 taken 936 times.
|
480168 | for (i = 0; i < SRC_PIXELS; i++) { |
386 | 479232 | filterPos[i] = i; | |
387 | 479232 | filterPosAvx[i] = i; | |
388 | |||
389 | // These filter cofficients are chosen to try break two corner | ||
390 | // cases, namely: | ||
391 | // | ||
392 | // - Negative filter coefficients. The filters output signed | ||
393 | // values, and it should be possible to end up with negative | ||
394 | // output values. | ||
395 | // | ||
396 | // - Positive clipping. The hscale filter function has clipping | ||
397 | // at (1<<15) - 1 | ||
398 | // | ||
399 | // The coefficients sum to the 1.0 point for the hscale | ||
400 | // functions (1 << 14). | ||
401 | |||
402 |
2/2✓ Branch 0 taken 8945664 times.
✓ Branch 1 taken 479232 times.
|
9424896 | for (j = 0; j < width; j++) { |
403 | 8945664 | filter[i * width + j] = -((1 << 14) / (width - 1)); | |
404 | } | ||
405 | 479232 | filter[i * width + (rnd() % width)] = ((1 << 15) - 1); | |
406 | } | ||
407 | |||
408 |
2/2✓ Branch 0 taken 37440 times.
✓ Branch 1 taken 936 times.
|
38376 | for (i = 0; i < MAX_FILTER_WIDTH; i++) { |
409 | // These values should be unused in SIMD implementations but | ||
410 | // may still be read, random coefficients here should help show | ||
411 | // issues where they are used in error. | ||
412 | |||
413 | 37440 | filter[SRC_PIXELS * width + i] = rnd(); | |
414 | } | ||
415 | 936 | sws->dst_w = c->chrDstW = input_sizes[dstWi]; | |
416 | 936 | ff_sws_init_scale(c); | |
417 | 936 | memcpy(filterAvx2, filter, sizeof(uint16_t) * (SRC_PIXELS * MAX_FILTER_WIDTH + MAX_FILTER_WIDTH)); | |
418 | 936 | ff_shuffle_filter_coefficients(c, filterPosAvx, width, filterAvx2, sws->dst_w); | |
419 | |||
420 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 936 times.
|
936 | av_assert0(c->hyScale == c->hcScale); |
421 |
2/2✓ Branch 3 taken 288 times.
✓ Branch 4 taken 648 times.
|
936 | if (check_func(c->hcScale, "hscale_%d_to_%d__fs_%d_dstW_%d", c->srcBpc, c->dstBpc + 1, width, sws->dst_w)) { |
422 | 288 | memset(dst0, 0, SRC_PIXELS * sizeof(dst0[0])); | |
423 | 288 | memset(dst1, 0, SRC_PIXELS * sizeof(dst1[0])); | |
424 | |||
425 | 288 | call_ref(NULL, dst0, sws->dst_w, src, filter, filterPos, width); | |
426 | 288 | call_new(NULL, dst1, sws->dst_w, src, filterAvx2, filterPosAvx, width); | |
427 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 288 times.
|
288 | if (memcmp(dst0, dst1, sws->dst_w * sizeof(dst0[0]))) |
428 | ✗ | fail(); | |
429 |
1/8✗ Branch 1 not taken.
✓ Branch 2 taken 288 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
|
288 | bench_new(NULL, dst0, sws->dst_w, src, filter, filterPosAvx, width); |
430 | } | ||
431 | } | ||
432 | } | ||
433 | } | ||
434 | 13 | sws_freeContext(sws); | |
435 | 13 | } | |
436 | |||
437 | 13 | void checkasm_check_sw_scale(void) | |
438 | { | ||
439 | 13 | check_hscale(); | |
440 | 13 | report("hscale"); | |
441 | 13 | check_yuv2yuv1(0); | |
442 | 13 | check_yuv2yuv1(1); | |
443 | 13 | report("yuv2yuv1"); | |
444 | 13 | check_yuv2yuvX(0); | |
445 | 13 | check_yuv2yuvX(1); | |
446 | 13 | report("yuv2yuvX"); | |
447 | 13 | check_yuv2nv12cX(0); | |
448 | 13 | check_yuv2nv12cX(1); | |
449 | 13 | report("yuv2nv12cX"); | |
450 | 13 | } | |
451 |