429
|
1 /* motion test. (c) 2001 Fabrice Bellard. */
|
75
|
2 #include <stdlib.h>
|
|
3 #include <stdio.h>
|
|
4 #include <string.h>
|
|
5 #include <sys/time.h>
|
|
6 #include <unistd.h>
|
|
7 #include <getopt.h>
|
|
8
|
|
9 #include "dsputil.h"
|
|
10
|
|
11 #include "i386/mmx.h"
|
|
12
|
644
|
13 int pix_abs16x16_mmx(UINT8 *blk1, UINT8 *blk2, int lx);
|
|
14 int pix_abs16x16_mmx1(UINT8 *blk1, UINT8 *blk2, int lx);
|
|
15 int pix_abs16x16_x2_mmx(UINT8 *blk1, UINT8 *blk2, int lx);
|
|
16 int pix_abs16x16_x2_mmx1(UINT8 *blk1, UINT8 *blk2, int lx);
|
|
17 int pix_abs16x16_x2_c(UINT8 *blk1, UINT8 *blk2, int lx);
|
|
18 int pix_abs16x16_y2_mmx(UINT8 *blk1, UINT8 *blk2, int lx);
|
|
19 int pix_abs16x16_y2_mmx1(UINT8 *blk1, UINT8 *blk2, int lx);
|
|
20 int pix_abs16x16_y2_c(UINT8 *blk1, UINT8 *blk2, int lx);
|
|
21 int pix_abs16x16_xy2_mmx(UINT8 *blk1, UINT8 *blk2, int lx);
|
|
22 int pix_abs16x16_xy2_mmx1(UINT8 *blk1, UINT8 *blk2, int lx);
|
|
23 int pix_abs16x16_xy2_c(UINT8 *blk1, UINT8 *blk2, int lx);
|
75
|
24
|
644
|
25 typedef int motion_func(UINT8 *blk1, UINT8 *blk2, int lx);
|
75
|
26
|
|
27 #define WIDTH 64
|
|
28 #define HEIGHT 64
|
|
29
|
|
30 UINT8 img1[WIDTH * HEIGHT];
|
|
31 UINT8 img2[WIDTH * HEIGHT];
|
|
32
|
|
33 void fill_random(UINT8 *tab, int size)
|
|
34 {
|
|
35 int i;
|
|
36 for(i=0;i<size;i++) {
|
|
37 #if 1
|
|
38 tab[i] = random() % 256;
|
|
39 #else
|
|
40 tab[i] = i;
|
|
41 #endif
|
|
42 }
|
|
43 }
|
|
44
|
|
45 void help(void)
|
|
46 {
|
|
47 printf("motion-test [-h]\n"
|
|
48 "test motion implementations\n");
|
|
49 exit(1);
|
|
50 }
|
|
51
|
|
52 INT64 gettime(void)
|
|
53 {
|
|
54 struct timeval tv;
|
|
55 gettimeofday(&tv,NULL);
|
|
56 return (INT64)tv.tv_sec * 1000000 + tv.tv_usec;
|
|
57 }
|
|
58
|
|
59 #define NB_ITS 500
|
|
60
|
|
61 int dummy;
|
|
62
|
|
63 void test_motion(const char *name,
|
|
64 motion_func *test_func, motion_func *ref_func)
|
|
65 {
|
|
66 int x, y, d1, d2, it;
|
|
67 UINT8 *ptr;
|
|
68 INT64 ti;
|
|
69 printf("testing '%s'\n", name);
|
|
70
|
|
71 /* test correctness */
|
|
72 for(it=0;it<20;it++) {
|
|
73
|
|
74 fill_random(img1, WIDTH * HEIGHT);
|
|
75 fill_random(img2, WIDTH * HEIGHT);
|
|
76
|
|
77 for(y=0;y<HEIGHT-17;y++) {
|
|
78 for(x=0;x<WIDTH-17;x++) {
|
|
79 ptr = img2 + y * WIDTH + x;
|
644
|
80 d1 = test_func(img1, ptr, WIDTH);
|
|
81 d2 = ref_func(img1, ptr, WIDTH);
|
75
|
82 if (d1 != d2) {
|
|
83 printf("error: mmx=%d c=%d\n", d1, d2);
|
|
84 }
|
|
85 }
|
|
86 }
|
|
87 }
|
|
88 emms();
|
|
89
|
|
90 /* speed test */
|
|
91 ti = gettime();
|
|
92 d1 = 0;
|
|
93 for(it=0;it<NB_ITS;it++) {
|
|
94 for(y=0;y<HEIGHT-17;y++) {
|
|
95 for(x=0;x<WIDTH-17;x++) {
|
|
96 ptr = img2 + y * WIDTH + x;
|
644
|
97 d1 += test_func(img1, ptr, WIDTH);
|
75
|
98 }
|
|
99 }
|
|
100 }
|
|
101 emms();
|
|
102 dummy = d1; /* avoid optimisation */
|
|
103 ti = gettime() - ti;
|
|
104
|
|
105 printf(" %0.0f kop/s\n",
|
|
106 (double)NB_ITS * (WIDTH - 16) * (HEIGHT - 16) /
|
|
107 (double)(ti / 1000.0));
|
|
108 }
|
|
109
|
|
110
|
|
111 int main(int argc, char **argv)
|
|
112 {
|
|
113 int c;
|
|
114
|
|
115 for(;;) {
|
|
116 c = getopt(argc, argv, "h");
|
|
117 if (c == -1)
|
|
118 break;
|
|
119 switch(c) {
|
|
120 case 'h':
|
|
121 help();
|
|
122 break;
|
|
123 }
|
|
124 }
|
|
125
|
|
126 printf("ffmpeg motion test\n");
|
|
127
|
|
128 test_motion("mmx", pix_abs16x16_mmx, pix_abs16x16_c);
|
|
129 test_motion("mmx_x2", pix_abs16x16_x2_mmx, pix_abs16x16_x2_c);
|
|
130 test_motion("mmx_y2", pix_abs16x16_y2_mmx, pix_abs16x16_y2_c);
|
|
131 test_motion("mmx_xy2", pix_abs16x16_xy2_mmx, pix_abs16x16_xy2_c);
|
|
132 return 0;
|
|
133 }
|