2 * (c) 2001 Fabrice Bellard
4 * This file is part of FFmpeg.
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (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 GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
34 #include "libavutil/lfg.h"
41 static uint8_t img1[WIDTH * HEIGHT];
42 static uint8_t img2[WIDTH * HEIGHT];
44 static void fill_random(uint8_t *tab, int size)
49 av_lfg_init(&prng, 1);
51 tab[i] = av_lfg_get(&prng) % 256;
55 static void help(void)
57 printf("motion-test [-h]\n"
58 "test motion implementations\n");
61 static int64_t gettime(void)
64 gettimeofday(&tv,NULL);
65 return (int64_t)tv.tv_sec * 1000000 + tv.tv_usec;
72 static void test_motion(const char *name,
73 me_cmp_func test_func, me_cmp_func ref_func)
78 printf("testing '%s'\n", name);
80 /* test correctness */
81 for(it=0;it<20;it++) {
83 fill_random(img1, WIDTH * HEIGHT);
84 fill_random(img2, WIDTH * HEIGHT);
86 for(y=0;y<HEIGHT-17;y++) {
87 for(x=0;x<WIDTH-17;x++) {
88 ptr = img2 + y * WIDTH + x;
89 d1 = test_func(NULL, img1, ptr, WIDTH, 1);
90 d2 = ref_func(NULL, img1, ptr, WIDTH, 1);
92 printf("error: mmx=%d c=%d\n", d1, d2);
102 for(it=0;it<NB_ITS;it++) {
103 for(y=0;y<HEIGHT-17;y++) {
104 for(x=0;x<WIDTH-17;x++) {
105 ptr = img2 + y * WIDTH + x;
106 d1 += test_func(NULL, img1, ptr, WIDTH, 1);
111 dummy = d1; /* avoid optimization */
114 printf(" %0.0f kop/s\n",
115 (double)NB_ITS * (WIDTH - 16) * (HEIGHT - 16) /
116 (double)(ti / 1000.0));
120 int main(int argc, char **argv)
124 DSPContext cctx, mmxctx;
125 int flags[2] = { AV_CPU_FLAG_MMX, AV_CPU_FLAG_MMX2 };
126 int flags_size = HAVE_MMX2 ? 2 : 1;
129 c = getopt(argc, argv, "h");
139 printf("ffmpeg motion test\n");
141 ctx = avcodec_alloc_context3(NULL);
142 ctx->dsp_mask = AV_CPU_FLAG_FORCE;
143 ff_dsputil_init(&cctx, ctx);
144 for (c = 0; c < flags_size; c++) {
146 ctx->dsp_mask = AV_CPU_FLAG_FORCE | flags[c];
147 ff_dsputil_init(&mmxctx, ctx);
149 for (x = 0; x < 2; x++) {
150 printf("%s for %dx%d pixels\n", c ? "mmx2" : "mmx",
151 x ? 8 : 16, x ? 8 : 16);
152 test_motion("mmx", mmxctx.pix_abs[x][0], cctx.pix_abs[x][0]);
153 test_motion("mmx_x2", mmxctx.pix_abs[x][1], cctx.pix_abs[x][1]);
154 test_motion("mmx_y2", mmxctx.pix_abs[x][2], cctx.pix_abs[x][2]);
155 test_motion("mmx_xy2", mmxctx.pix_abs[x][3], cctx.pix_abs[x][3]);