2 * This file is part of FFmpeg.
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 #include "libavutil/intreadwrite.h"
20 #include "libavutil/mem.h"
21 #include "libavutil/mem_internal.h"
23 #include "libavcodec/mpegvideoencdsp.h"
27 #define randomize_buffers(buf, size) \
29 for (int j = 0; j < size; j += 4) \
30 AV_WN32(buf + j, rnd()); \
33 static void check_pix_sum(MpegvideoEncDSPContext
*c
)
35 LOCAL_ALIGNED_16(uint8_t, src
, [16 * 16]);
37 declare_func(int, const uint8_t *pix
, ptrdiff_t line_size
);
39 randomize_buffers(src
, 16 * 16);
41 for (int n
= 0; n
< 2; n
++) {
42 const char *negstride_str
= n
? "_negstride" : "";
43 if (check_func(c
->pix_sum
, "pix_sum%s", negstride_str
)) {
45 const uint8_t *pix
= src
+ (n
? (15 * 16) : 0);
46 ptrdiff_t line_size
= 16 * (n
? -1 : 1);
47 sum0
= call_ref(pix
, line_size
);
48 sum1
= call_new(pix
, line_size
);
51 bench_new(pix
, line_size
);
56 static void check_pix_norm1(MpegvideoEncDSPContext
*c
)
58 LOCAL_ALIGNED_16(uint8_t, src
, [16 * 16]);
60 declare_func(int, const uint8_t *pix
, ptrdiff_t line_size
);
62 randomize_buffers(src
, 16 * 16);
64 for (int n
= 0; n
< 2; n
++) {
65 const char *negstride_str
= n
? "_negstride" : "";
66 if (check_func(c
->pix_norm1
, "pix_norm1%s", negstride_str
)) {
68 const uint8_t *pix
= src
+ (n
? (15 * 16) : 0);
69 ptrdiff_t line_size
= 16 * (n
? -1 : 1);
70 sum0
= call_ref(pix
, line_size
);
71 sum1
= call_new(pix
, line_size
);
74 bench_new(pix
, line_size
);
80 #define MAX_LINE_SIZE 1920
82 #define LINESIZE (EDGE_WIDTH + MAX_LINE_SIZE + EDGE_WIDTH)
83 #define BUFSIZE ((EDGE_WIDTH + NUM_LINES + EDGE_WIDTH) * LINESIZE)
85 static void check_draw_edges(MpegvideoEncDSPContext
*c
)
87 static const int input_sizes
[] = {8, 128, 1080, MAX_LINE_SIZE
, -MAX_LINE_SIZE
};
88 LOCAL_ALIGNED_16(uint8_t, buf0
, [BUFSIZE
]);
89 LOCAL_ALIGNED_16(uint8_t, buf1
, [BUFSIZE
]);
91 declare_func_emms(AV_CPU_FLAG_MMX
, void, uint8_t *buf
, ptrdiff_t wrap
, int width
, int height
,
92 int w
, int h
, int sides
);
94 for (int isi
= 0; isi
< FF_ARRAY_ELEMS(input_sizes
); isi
++) {
95 int input_size
= input_sizes
[isi
];
96 int negstride
= input_size
< 0;
97 const char *negstride_str
= negstride
? "_negstride" : "";
98 int width
= FFABS(input_size
);
99 ptrdiff_t linesize
= EDGE_WIDTH
+ width
+ EDGE_WIDTH
;
100 /* calculate height based on specified width to use the entire buffer. */
101 int height
= (BUFSIZE
/ linesize
) - (2 * EDGE_WIDTH
);
102 uint8_t *dst0
= buf0
+ EDGE_WIDTH
* linesize
+ EDGE_WIDTH
;
103 uint8_t *dst1
= buf1
+ EDGE_WIDTH
* linesize
+ EDGE_WIDTH
;
106 dst0
+= (height
- 1) * linesize
;
107 dst1
+= (height
- 1) * linesize
;
111 for (int shift
= 0; shift
< 3; shift
++) {
112 int edge
= EDGE_WIDTH
>> shift
;
113 if (check_func(c
->draw_edges
, "draw_edges_%d_%d_%d%s", width
, height
, edge
, negstride_str
)) {
114 randomize_buffers(buf0
, BUFSIZE
);
115 memcpy(buf1
, buf0
, BUFSIZE
);
116 call_ref(dst0
, linesize
, width
, height
, edge
, edge
, EDGE_BOTTOM
| EDGE_TOP
);
117 call_new(dst1
, linesize
, width
, height
, edge
, edge
, EDGE_BOTTOM
| EDGE_TOP
);
118 if (memcmp(buf0
, buf1
, BUFSIZE
))
120 bench_new(dst1
, linesize
, width
, height
, edge
, edge
, EDGE_BOTTOM
| EDGE_TOP
);
132 void checkasm_check_mpegvideoencdsp(void)
134 AVCodecContext avctx
= {
135 .bits_per_raw_sample
= 8,
137 MpegvideoEncDSPContext c
= { 0 };
139 ff_mpegvideoencdsp_init(&c
, &avctx
);
145 check_draw_edges(&c
);
146 report("draw_edges");