annotate motion_test.c @ 75:bb7d6fe159ad libavcodec

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