]> git.sesse.net Git - ffmpeg/blob - libavcodec/motion-test.c
ivi_common: Initialize a variable at declaration in ff_ivi_decode_blocks().
[ffmpeg] / libavcodec / motion-test.c
1 /*
2  * (c) 2001 Fabrice Bellard
3  *
4  * This file is part of Libav.
5  *
6  * Libav 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.
10  *
11  * Libav 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.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with Libav; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20
21 /**
22  * @file
23  * motion test.
24  */
25
26 #include <stdlib.h>
27 #include <stdio.h>
28 #include <string.h>
29 #include <sys/time.h>
30 #include <unistd.h>
31
32 #include "config.h"
33 #include "dsputil.h"
34 #include "libavutil/lfg.h"
35
36 #undef printf
37
38 #define WIDTH 64
39 #define HEIGHT 64
40
41 static uint8_t img1[WIDTH * HEIGHT];
42 static uint8_t img2[WIDTH * HEIGHT];
43
44 static void fill_random(uint8_t *tab, int size)
45 {
46     int i;
47     AVLFG prng;
48
49     av_lfg_init(&prng, 1);
50     for(i=0;i<size;i++) {
51 #if 1
52         tab[i] = av_lfg_get(&prng) % 256;
53 #else
54         tab[i] = i;
55 #endif
56     }
57 }
58
59 static void help(void)
60 {
61     printf("motion-test [-h]\n"
62            "test motion implementations\n");
63 }
64
65 static int64_t gettime(void)
66 {
67     struct timeval tv;
68     gettimeofday(&tv,NULL);
69     return (int64_t)tv.tv_sec * 1000000 + tv.tv_usec;
70 }
71
72 #define NB_ITS 500
73
74 int dummy;
75
76 static void test_motion(const char *name,
77                  me_cmp_func test_func, me_cmp_func ref_func)
78 {
79     int x, y, d1, d2, it;
80     uint8_t *ptr;
81     int64_t ti;
82     printf("testing '%s'\n", name);
83
84     /* test correctness */
85     for(it=0;it<20;it++) {
86
87         fill_random(img1, WIDTH * HEIGHT);
88         fill_random(img2, WIDTH * HEIGHT);
89
90         for(y=0;y<HEIGHT-17;y++) {
91             for(x=0;x<WIDTH-17;x++) {
92                 ptr = img2 + y * WIDTH + x;
93                 d1 = test_func(NULL, img1, ptr, WIDTH, 1);
94                 d2 = ref_func(NULL, img1, ptr, WIDTH, 1);
95                 if (d1 != d2) {
96                     printf("error: mmx=%d c=%d\n", d1, d2);
97                 }
98             }
99         }
100     }
101     emms_c();
102
103     /* speed test */
104     ti = gettime();
105     d1 = 0;
106     for(it=0;it<NB_ITS;it++) {
107         for(y=0;y<HEIGHT-17;y++) {
108             for(x=0;x<WIDTH-17;x++) {
109                 ptr = img2 + y * WIDTH + x;
110                 d1 += test_func(NULL, img1, ptr, WIDTH, 1);
111             }
112         }
113     }
114     emms_c();
115     dummy = d1; /* avoid optimization */
116     ti = gettime() - ti;
117
118     printf("  %0.0f kop/s\n",
119            (double)NB_ITS * (WIDTH - 16) * (HEIGHT - 16) /
120            (double)(ti / 1000.0));
121 }
122
123
124 int main(int argc, char **argv)
125 {
126     AVCodecContext *ctx;
127     int c;
128     DSPContext cctx, mmxctx;
129     int flags[2] = { AV_CPU_FLAG_MMX, AV_CPU_FLAG_MMX2 };
130     int flags_size = HAVE_MMX2 ? 2 : 1;
131
132     for(;;) {
133         c = getopt(argc, argv, "h");
134         if (c == -1)
135             break;
136         switch(c) {
137         case 'h':
138             help();
139             return 1;
140         }
141     }
142
143     printf("Libav motion test\n");
144
145     ctx = avcodec_alloc_context3(NULL);
146     ctx->dsp_mask = AV_CPU_FLAG_FORCE;
147     ff_dsputil_init(&cctx, ctx);
148     for (c = 0; c < flags_size; c++) {
149         int x;
150         ctx->dsp_mask = AV_CPU_FLAG_FORCE | flags[c];
151         ff_dsputil_init(&mmxctx, ctx);
152
153         for (x = 0; x < 2; x++) {
154             printf("%s for %dx%d pixels\n", c ? "mmx2" : "mmx",
155                    x ? 8 : 16, x ? 8 : 16);
156             test_motion("mmx",     mmxctx.pix_abs[x][0], cctx.pix_abs[x][0]);
157             test_motion("mmx_x2",  mmxctx.pix_abs[x][1], cctx.pix_abs[x][1]);
158             test_motion("mmx_y2",  mmxctx.pix_abs[x][2], cctx.pix_abs[x][2]);
159             test_motion("mmx_xy2", mmxctx.pix_abs[x][3], cctx.pix_abs[x][3]);
160         }
161     }
162     av_free(ctx);
163
164     return 0;
165 }