]> git.sesse.net Git - ffmpeg/blob - tests/checkasm/llviddsp.c
Merge commit '45c4bf3df03ef53ae61fa1473424d4ae024f22e4'
[ffmpeg] / tests / checkasm / llviddsp.c
1 /*
2  * Copyright (c) 2016 Alexandra Hájková
3  *
4  * This file is part of FFmpeg.
5  *
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.
10  *
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.
15  *
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.
19  */
20
21 #include <string.h>
22
23 #include "libavutil/common.h"
24 #include "libavutil/intreadwrite.h"
25 #include "libavutil/mem.h"
26
27 #include "libavcodec/lossless_videodsp.h"
28
29 #include "checkasm.h"
30
31 #define randomize_buffers(buf, size)     \
32     do {                                 \
33         int j;                           \
34         uint8_t *tmp_buf = (uint8_t *)buf;\
35         for (j = 0; j < size; j++)       \
36             tmp_buf[j] = rnd() & 0xFF;       \
37     } while (0)
38
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));\
42     if (!a0 || !a1)\
43         fail();\
44     randomize_buffers(a0, width * sizeof(type));\
45     memcpy(a1, a0, width*sizeof(type));\
46
47 static void check_add_bytes(LLVidDSPContext c, int width)
48 {
49     uint8_t *dst0 = av_mallocz(width);
50     uint8_t *dst1 = av_mallocz(width);
51     init_buffer(src0, src1, uint8_t, width);
52
53     if (!dst0 || !dst1)
54         fail();
55
56     declare_func_emms(AV_CPU_FLAG_MMX, void, uint8_t *dst, uint8_t *src, ptrdiff_t w);
57
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))
62             fail();
63         bench_new(dst1, src1, width);
64     }
65
66     av_free(src0);
67     av_free(src1);
68     av_free(dst0);
69     av_free(dst1);
70 }
71
72 static void check_add_median_pred(LLVidDSPContext c, int width) {
73     int A0, A1, B0, B1;
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);
78
79     A0 = rnd() & 0xFF;
80     B0 = rnd() & 0xFF;
81     A1 = A0;
82     B1 = B0;
83
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);
87
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))
92             fail();
93         bench_new(dst1, src1, diff1, width, &A1, &B1);
94     }
95
96     av_free(src0);
97     av_free(src1);
98     av_free(diff0);
99     av_free(diff1);
100     av_free(dst0);
101     av_free(dst1);
102 }
103
104 static void check_add_left_pred(LLVidDSPContext c, int width, int acc, const char * report)
105 {
106     uint8_t *dst0 = av_mallocz(width);
107     uint8_t *dst1 = av_mallocz(width);
108     init_buffer(src0, src1, uint8_t, width);
109
110     if (!dst0 || !dst1)
111         fail();
112
113     declare_func_emms(AV_CPU_FLAG_MMX, void, uint8_t *dst, uint8_t *src, ptrdiff_t w, int acc);
114
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))
119             fail();
120         bench_new(dst1, src1, width, acc);
121     }
122
123     av_free(src0);
124     av_free(src1);
125     av_free(dst0);
126     av_free(dst1);
127 }
128
129 static void check_add_left_pred_16(LLVidDSPContext c, unsigned mask, int width, unsigned acc, const char * report)
130 {
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);
134
135     if (!dst0 || !dst1)
136         fail();
137
138     declare_func_emms(AV_CPU_FLAG_MMX, void, uint16_t *dst, uint16_t *src, unsigned mask, ptrdiff_t w, unsigned acc);
139
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))
144             fail();
145         bench_new(dst1, src1, mask, width, acc);
146     }
147
148     av_free(src0);
149     av_free(src1);
150     av_free(dst0);
151     av_free(dst1);
152 }
153
154 void checkasm_check_llviddsp(void)
155 {
156     LLVidDSPContext c;
157     int width = 16 * av_clip(rnd(), 16, 128);
158     int accRnd = rnd() & 0xFF;
159
160     ff_llviddsp_init(&c);
161
162     check_add_bytes(c, width);
163     report("add_bytes");
164
165     check_add_median_pred(c, width);
166     report("add_median_pred");
167
168     check_add_left_pred(c, width, 0, "add_left_pred_zero");
169     report("add_left_pred_zero");
170
171     check_add_left_pred(c, width, accRnd, "add_left_pred_rnd_acc");
172     report("add_left_pred_rnd_acc");
173
174     check_add_left_pred_16(c, 255, width, accRnd, "add_left_pred_int16");
175     report("add_left_pred_int16");
176 }