2 * Copyright (c) 2016 Alexandra Hájková
4 * This file is part of FFmpeg.
6 * FFmpeg is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with FFmpeg; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #include "libavutil/common.h"
24 #include "libavutil/intreadwrite.h"
25 #include "libavutil/mem.h"
27 #include "libavcodec/lossless_videodsp.h"
31 #define randomize_buffers(buf, size) \
34 uint8_t *tmp_buf = (uint8_t *)buf;\
35 for (j = 0; j < size; j++) \
36 tmp_buf[j] = rnd() & 0xFF; \
39 #define init_buffer(a0, a1, type, width)\
42 randomize_buffers(a0, width * sizeof(type));\
43 memcpy(a1, a0, width*sizeof(type));\
45 static void check_add_bytes(LLVidDSPContext *c, int width)
47 uint8_t *dst0
= av_mallocz(width
);
48 uint8_t *dst1
= av_mallocz(width
);
49 uint8_t *src0
= av_calloc(width
, sizeof(*src0
));
50 uint8_t *src1
= av_calloc(width
, sizeof(*src1
));
51 declare_func(void, uint8_t *dst
, uint8_t *src
, ptrdiff_t w
);
53 init_buffer(src0
, src1
, uint8_t, width
);
59 if (check_func(c
->add_bytes
, "add_bytes")) {
60 call_ref(dst0
, src0
, width
);
61 call_new(dst1
, src1
, width
);
62 if (memcmp(dst0
, dst1
, width
))
64 bench_new(dst1
, src1
, width
);
73 static void check_add_median_pred(LLVidDSPContext
*c
, int width
) {
75 uint8_t *dst0
= av_mallocz(width
);
76 uint8_t *dst1
= av_mallocz(width
);
77 uint8_t *src0
= av_calloc(width
, sizeof(*src0
));
78 uint8_t *src1
= av_calloc(width
, sizeof(*src1
));
79 uint8_t *diff0
= av_calloc(width
, sizeof(*diff0
));
80 uint8_t *diff1
= av_calloc(width
, sizeof(*diff1
));
81 declare_func(void, uint8_t *dst
, const uint8_t *src1
,
82 const uint8_t *diff
, ptrdiff_t w
,
83 int *left
, int *left_top
);
85 init_buffer(src0
, src1
, uint8_t, width
);
86 init_buffer(diff0
, diff1
, uint8_t, width
);
94 if (check_func(c
->add_median_pred
, "add_median_pred")) {
95 call_ref(dst0
, src0
, diff0
, width
, &a0
, &b0
);
96 call_new(dst1
, src1
, diff1
, width
, &a1
, &b1
);
97 if (memcmp(dst0
, dst1
, width
) || (a0
!= a1
) || (b0
!= b1
))
99 bench_new(dst1
, src1
, diff1
, width
, &a1
, &b1
);
110 static void check_add_left_pred(LLVidDSPContext
*c
, int width
, int acc
, const char * report
)
113 uint8_t *dst0
= av_mallocz(width
);
114 uint8_t *dst1
= av_mallocz(width
);
115 uint8_t *src0
= av_calloc(width
, sizeof(*src0
));
116 uint8_t *src1
= av_calloc(width
, sizeof(*src1
));
117 declare_func(int, uint8_t *dst
, const uint8_t *src
, ptrdiff_t w
, int acc
);
119 init_buffer(src0
, src1
, uint8_t, width
);
124 if (check_func(c
->add_left_pred
, "%s", report
)) {
125 res0
= call_ref(dst0
, src0
, width
, acc
);
126 res1
= call_new(dst1
, src1
, width
, acc
);
127 if ((res0
& 0xFF) != (res1
& 0xFF)||\
128 memcmp(dst0
, dst1
, width
))
130 bench_new(dst1
, src1
, width
, acc
);
139 static void check_add_left_pred_16(LLVidDSPContext
*c
, unsigned mask
, int width
, unsigned acc
, const char * report
)
142 uint16_t *dst0
= av_calloc(width
, sizeof(*dst0
));
143 uint16_t *dst1
= av_calloc(width
, sizeof(*dst1
));
144 uint16_t *src0
= av_calloc(width
, sizeof(*src0
));
145 uint16_t *src1
= av_calloc(width
, sizeof(*src1
));
146 declare_func(int, uint16_t *dst
, const uint16_t *src
, unsigned mask
, ptrdiff_t w
, unsigned acc
);
148 init_buffer(src0
, src1
, uint16_t, width
);
153 if (check_func(c
->add_left_pred_int16
, "%s", report
)) {
154 res0
= call_ref(dst0
, src0
, mask
, width
, acc
);
155 res1
= call_new(dst1
, src1
, mask
, width
, acc
);
156 if ((res0
&0xFFFF) != (res1
&0xFFFF)||\
157 memcmp(dst0
, dst1
, width
))
159 bench_new(dst1
, src1
, mask
, width
, acc
);
168 static void check_add_gradient_pred(LLVidDSPContext
*c
, int w
) {
169 int src_size
, stride
;
170 uint8_t *src0
, *src1
;
171 declare_func(void, uint8_t *src
, const ptrdiff_t stride
,
172 const ptrdiff_t width
);
175 src_size
= (stride
+ 32) * 2; /* dsp need previous line, and ignore the start of the line */
176 src0
= av_mallocz(src_size
);
177 src1
= av_mallocz(src_size
);
179 init_buffer(src0
, src1
, uint8_t, src_size
);
181 if (check_func(c
->add_gradient_pred
, "add_gradient_pred")) {
182 call_ref(src0
+ stride
+ 32, stride
, w
);
183 call_new(src1
+ stride
+ 32, stride
, w
);
184 if (memcmp(src0
, src1
, stride
)||/* previous line doesn't change */
185 memcmp(src0
+stride
, src1
+ stride
, w
+ 32)) {
188 bench_new(src1
+ stride
+ 32, stride
, w
);
195 void checkasm_check_llviddsp(void)
198 int width
= 16 * av_clip(rnd(), 16, 128);
199 int accRnd
= rnd() & 0xFF;
201 ff_llviddsp_init(&c
);
203 check_add_bytes(&c
, width
);
206 check_add_median_pred(&c
, width
);
207 report("add_median_pred");
209 check_add_left_pred(&c
, width
, 0, "add_left_pred_zero");
210 report("add_left_pred_zero");
212 check_add_left_pred(&c
, width
, accRnd
, "add_left_pred_rnd_acc");
213 report("add_left_pred_rnd_acc");
215 check_add_left_pred_16(&c
, 255, width
, accRnd
, "add_left_pred_int16");
216 report("add_left_pred_int16");
218 check_add_gradient_pred(&c
, width
);
219 report("add_gradient_pred");