VirtualBox

source: vbox/trunk/src/libs/ffmpeg-20060710/libavcodec/motion_test.c@ 11551

Last change on this file since 11551 was 5776, checked in by vboxsync, 17 years ago

ffmpeg: exported to OSE

File size: 3.2 KB
Line 
1/* motion test. (c) 2001 Fabrice Bellard. */
2
3/**
4 * @file motion_test.c
5 * motion test.
6 */
7
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
18int pix_abs16x16_mmx(uint8_t *blk1, uint8_t *blk2, int lx);
19int pix_abs16x16_mmx1(uint8_t *blk1, uint8_t *blk2, int lx);
20int pix_abs16x16_x2_mmx(uint8_t *blk1, uint8_t *blk2, int lx);
21int pix_abs16x16_x2_mmx1(uint8_t *blk1, uint8_t *blk2, int lx);
22int pix_abs16x16_x2_c(uint8_t *blk1, uint8_t *blk2, int lx);
23int pix_abs16x16_y2_mmx(uint8_t *blk1, uint8_t *blk2, int lx);
24int pix_abs16x16_y2_mmx1(uint8_t *blk1, uint8_t *blk2, int lx);
25int pix_abs16x16_y2_c(uint8_t *blk1, uint8_t *blk2, int lx);
26int pix_abs16x16_xy2_mmx(uint8_t *blk1, uint8_t *blk2, int lx);
27int pix_abs16x16_xy2_mmx1(uint8_t *blk1, uint8_t *blk2, int lx);
28int pix_abs16x16_xy2_c(uint8_t *blk1, uint8_t *blk2, int lx);
29
30typedef int motion_func(uint8_t *blk1, uint8_t *blk2, int lx);
31
32#define WIDTH 64
33#define HEIGHT 64
34
35uint8_t img1[WIDTH * HEIGHT];
36uint8_t img2[WIDTH * HEIGHT];
37
38void fill_random(uint8_t *tab, int size)
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
50void help(void)
51{
52 printf("motion-test [-h]\n"
53 "test motion implementations\n");
54 exit(1);
55}
56
57int64_t gettime(void)
58{
59 struct timeval tv;
60 gettimeofday(&tv,NULL);
61 return (int64_t)tv.tv_sec * 1000000 + tv.tv_usec;
62}
63
64#define NB_ITS 500
65
66int dummy;
67
68void test_motion(const char *name,
69 motion_func *test_func, motion_func *ref_func)
70{
71 int x, y, d1, d2, it;
72 uint8_t *ptr;
73 int64_t ti;
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;
85 d1 = test_func(img1, ptr, WIDTH);
86 d2 = ref_func(img1, ptr, WIDTH);
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;
102 d1 += test_func(img1, ptr, WIDTH);
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
116int 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}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette