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