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)\
40 type *a0 = av_mallocz_array(width, sizeof(type));\
41 type *a1 = av_mallocz_array(width, sizeof(type));\
44 randomize_buffers(a0, width * sizeof(type));\
45 memcpy(a1, a0, width*sizeof(type));\
47 static void check_add_bytes(LLVidDSPContext c, int width)
49 uint8_t *dst0 = av_mallocz(width);
50 uint8_t *dst1 = av_mallocz(width);
51 init_buffer(src0, src1, uint8_t, width);
56 declare_func_emms(AV_CPU_FLAG_MMX, void, uint8_t *dst, uint8_t *src, ptrdiff_t w);
58 if (check_func(c.add_bytes, "add_bytes")) {
59 call_ref(dst0, src0, width);
60 call_new(dst1, src1, width);
61 if (memcmp(dst0, dst1, width))
63 bench_new(dst1, src1, width);
72 static void check_add_median_pred(LLVidDSPContext c, int width) {
74 uint8_t *dst0 = av_mallocz(width);
75 uint8_t *dst1 = av_mallocz(width);
76 init_buffer(src0, src1, uint8_t, width);
77 init_buffer(diff0, diff1, uint8_t, width);
84 declare_func_emms(AV_CPU_FLAG_MMX, void, uint8_t *dst, const uint8_t *src1,
85 const uint8_t *diff, ptrdiff_t w,
86 int *left, int *left_top);
88 if (check_func(c.add_median_pred, "add_median_pred")) {
89 call_ref(dst0, src0, diff0, width, &A0, &B0);
90 call_new(dst1, src1, diff1, width, &A1, &B1);
91 if (memcmp(dst0, dst1, width) || (A0 != A1) || (B0 != B1))
93 bench_new(dst1, src1, diff1, width, &A1, &B1);
104 static void check_add_left_pred(LLVidDSPContext c, int width, int acc, const char * report)
106 uint8_t *dst0 = av_mallocz(width);
107 uint8_t *dst1 = av_mallocz(width);
108 init_buffer(src0, src1, uint8_t, width);
113 declare_func_emms(AV_CPU_FLAG_MMX, void, uint8_t *dst, uint8_t *src, ptrdiff_t w, int acc);
115 if (check_func(c.add_left_pred, "%s", report)) {
116 call_ref(dst0, src0, width, acc);
117 call_new(dst1, src1, width, acc);
118 if (memcmp(dst0, dst1, width))
120 bench_new(dst1, src1, width, acc);
129 static void check_add_left_pred_16(LLVidDSPContext c, unsigned mask, int width, unsigned acc, const char * report)
131 uint16_t *dst0 = av_mallocz_array(width, sizeof(uint16_t));
132 uint16_t *dst1 = av_mallocz_array(width, sizeof(uint16_t));
133 init_buffer(src0, src1, uint16_t, width);
138 declare_func_emms(AV_CPU_FLAG_MMX, void, uint16_t *dst, uint16_t *src, unsigned mask, ptrdiff_t w, unsigned acc);
140 if (check_func(c.add_left_pred_int16, "%s", report)) {
141 call_ref(dst0, src0, mask, width, acc);
142 call_new(dst1, src1, mask, width, acc);
143 if (memcmp(dst0, dst1, width))
145 bench_new(dst1, src1, mask, width, acc);
154 void checkasm_check_llviddsp(void)
157 int width = 16 * av_clip(rnd(), 16, 128);
158 int accRnd = rnd() & 0xFF;
160 ff_llviddsp_init(&c);
162 check_add_bytes(c, width);
165 check_add_median_pred(c, width);
166 report("add_median_pred");
168 check_add_left_pred(c, width, 0, "add_left_pred_zero");
169 report("add_left_pred_zero");
171 check_add_left_pred(c, width, accRnd, "add_left_pred_rnd_acc");
172 report("add_left_pred_rnd_acc");
174 check_add_left_pred_16(c, 255, width, accRnd, "add_left_pred_int16");
175 report("add_left_pred_int16");