]> git.sesse.net Git - ffmpeg/blob - libavcodec/motion_test.c
Simplify ptr[0]; ptr++; to *ptr++
[ffmpeg] / libavcodec / motion_test.c
1 /*
2  * (c) 2001 Fabrice Bellard
3  *
4  * This file is part of FFmpeg.
5  *
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.
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 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 FFmpeg; 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 motion_test.c
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 "dsputil.h"
33
34 #include "i386/mmx.h"
35
36 #undef exit
37 #undef printf
38
39 int pix_abs16x16_mmx(uint8_t *blk1, uint8_t *blk2, int lx);
40 int pix_abs16x16_mmx1(uint8_t *blk1, uint8_t *blk2, int lx);
41 int pix_abs16x16_c(uint8_t *blk1, uint8_t *blk2, int lx);
42 int pix_abs16x16_x2_mmx(uint8_t *blk1, uint8_t *blk2, int lx);
43 int pix_abs16x16_x2_mmx1(uint8_t *blk1, uint8_t *blk2, int lx);
44 int pix_abs16x16_x2_c(uint8_t *blk1, uint8_t *blk2, int lx);
45 int pix_abs16x16_y2_mmx(uint8_t *blk1, uint8_t *blk2, int lx);
46 int pix_abs16x16_y2_mmx1(uint8_t *blk1, uint8_t *blk2, int lx);
47 int pix_abs16x16_y2_c(uint8_t *blk1, uint8_t *blk2, int lx);
48 int pix_abs16x16_xy2_mmx(uint8_t *blk1, uint8_t *blk2, int lx);
49 int pix_abs16x16_xy2_mmx1(uint8_t *blk1, uint8_t *blk2, int lx);
50 int pix_abs16x16_xy2_c(uint8_t *blk1, uint8_t *blk2, int lx);
51
52 typedef int motion_func(uint8_t *blk1, uint8_t *blk2, int lx);
53
54 #define WIDTH 64
55 #define HEIGHT 64
56
57 uint8_t img1[WIDTH * HEIGHT];
58 uint8_t img2[WIDTH * HEIGHT];
59
60 void fill_random(uint8_t *tab, int size)
61 {
62     int i;
63     for(i=0;i<size;i++) {
64 #if 1
65         tab[i] = random() % 256;
66 #else
67         tab[i] = i;
68 #endif
69     }
70 }
71
72 void help(void)
73 {
74     printf("motion-test [-h]\n"
75            "test motion implementations\n");
76     exit(1);
77 }
78
79 int64_t gettime(void)
80 {
81     struct timeval tv;
82     gettimeofday(&tv,NULL);
83     return (int64_t)tv.tv_sec * 1000000 + tv.tv_usec;
84 }
85
86 #define NB_ITS 500
87
88 int dummy;
89
90 void test_motion(const char *name,
91                  motion_func *test_func, motion_func *ref_func)
92 {
93     int x, y, d1, d2, it;
94     uint8_t *ptr;
95     int64_t ti;
96     printf("testing '%s'\n", name);
97
98     /* test correctness */
99     for(it=0;it<20;it++) {
100
101         fill_random(img1, WIDTH * HEIGHT);
102         fill_random(img2, WIDTH * HEIGHT);
103
104         for(y=0;y<HEIGHT-17;y++) {
105             for(x=0;x<WIDTH-17;x++) {
106                 ptr = img2 + y * WIDTH + x;
107                 d1 = test_func(img1, ptr, WIDTH);
108                 d2 = ref_func(img1, ptr, WIDTH);
109                 if (d1 != d2) {
110                     printf("error: mmx=%d c=%d\n", d1, d2);
111                 }
112             }
113         }
114     }
115     emms();
116
117     /* speed test */
118     ti = gettime();
119     d1 = 0;
120     for(it=0;it<NB_ITS;it++) {
121         for(y=0;y<HEIGHT-17;y++) {
122             for(x=0;x<WIDTH-17;x++) {
123                 ptr = img2 + y * WIDTH + x;
124                 d1 += test_func(img1, ptr, WIDTH);
125             }
126         }
127     }
128     emms();
129     dummy = d1; /* avoid optimisation */
130     ti = gettime() - ti;
131
132     printf("  %0.0f kop/s\n",
133            (double)NB_ITS * (WIDTH - 16) * (HEIGHT - 16) /
134            (double)(ti / 1000.0));
135 }
136
137
138 int main(int argc, char **argv)
139 {
140     int c;
141
142     for(;;) {
143         c = getopt(argc, argv, "h");
144         if (c == -1)
145             break;
146         switch(c) {
147         case 'h':
148             help();
149             break;
150         }
151     }
152
153     printf("ffmpeg motion test\n");
154
155     test_motion("mmx", pix_abs16x16_mmx, pix_abs16x16_c);
156     test_motion("mmx_x2", pix_abs16x16_x2_mmx, pix_abs16x16_x2_c);
157     test_motion("mmx_y2", pix_abs16x16_y2_mmx, pix_abs16x16_y2_c);
158     test_motion("mmx_xy2", pix_abs16x16_xy2_mmx, pix_abs16x16_xy2_c);
159     return 0;
160 }