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