00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00026 #include <stdlib.h>
00027 #include <stdio.h>
00028 #include <string.h>
00029 #include <sys/time.h>
00030 #include <unistd.h>
00031
00032 #include "dsputil.h"
00033
00034 #undef exit
00035 #undef printf
00036 #undef random
00037
00038 #define WIDTH 64
00039 #define HEIGHT 64
00040
00041 uint8_t img1[WIDTH * HEIGHT];
00042 uint8_t img2[WIDTH * HEIGHT];
00043
00044 void fill_random(uint8_t *tab, int size)
00045 {
00046 int i;
00047 for(i=0;i<size;i++) {
00048 #if 1
00049 tab[i] = random() % 256;
00050 #else
00051 tab[i] = i;
00052 #endif
00053 }
00054 }
00055
00056 void help(void)
00057 {
00058 printf("motion-test [-h]\n"
00059 "test motion implementations\n");
00060 exit(1);
00061 }
00062
00063 int64_t gettime(void)
00064 {
00065 struct timeval tv;
00066 gettimeofday(&tv,NULL);
00067 return (int64_t)tv.tv_sec * 1000000 + tv.tv_usec;
00068 }
00069
00070 #define NB_ITS 500
00071
00072 int dummy;
00073
00074 void test_motion(const char *name,
00075 me_cmp_func test_func, me_cmp_func ref_func)
00076 {
00077 int x, y, d1, d2, it;
00078 uint8_t *ptr;
00079 int64_t ti;
00080 printf("testing '%s'\n", name);
00081
00082
00083 for(it=0;it<20;it++) {
00084
00085 fill_random(img1, WIDTH * HEIGHT);
00086 fill_random(img2, WIDTH * HEIGHT);
00087
00088 for(y=0;y<HEIGHT-17;y++) {
00089 for(x=0;x<WIDTH-17;x++) {
00090 ptr = img2 + y * WIDTH + x;
00091 d1 = test_func(NULL, img1, ptr, WIDTH, 1);
00092 d2 = ref_func(NULL, img1, ptr, WIDTH, 1);
00093 if (d1 != d2) {
00094 printf("error: mmx=%d c=%d\n", d1, d2);
00095 }
00096 }
00097 }
00098 }
00099 emms_c();
00100
00101
00102 ti = gettime();
00103 d1 = 0;
00104 for(it=0;it<NB_ITS;it++) {
00105 for(y=0;y<HEIGHT-17;y++) {
00106 for(x=0;x<WIDTH-17;x++) {
00107 ptr = img2 + y * WIDTH + x;
00108 d1 += test_func(NULL, img1, ptr, WIDTH, 1);
00109 }
00110 }
00111 }
00112 emms_c();
00113 dummy = d1;
00114 ti = gettime() - ti;
00115
00116 printf(" %0.0f kop/s\n",
00117 (double)NB_ITS * (WIDTH - 16) * (HEIGHT - 16) /
00118 (double)(ti / 1000.0));
00119 }
00120
00121
00122 int main(int argc, char **argv)
00123 {
00124 AVCodecContext *ctx;
00125 int c;
00126 DSPContext cctx, mmxctx;
00127 int flags[2] = { FF_MM_MMX, FF_MM_MMXEXT };
00128
00129 for(;;) {
00130 c = getopt(argc, argv, "h");
00131 if (c == -1)
00132 break;
00133 switch(c) {
00134 case 'h':
00135 help();
00136 break;
00137 }
00138 }
00139
00140 printf("ffmpeg motion test\n");
00141
00142 ctx = avcodec_alloc_context();
00143 ctx->dsp_mask = FF_MM_FORCE;
00144 dsputil_init(&cctx, ctx);
00145 for (c = 0; c < 2; c++) {
00146 int x;
00147 ctx->dsp_mask = FF_MM_FORCE | flags[c];
00148 dsputil_init(&mmxctx, ctx);
00149
00150 for (x = 0; x < 2; x++) {
00151 printf("%s for %dx%d pixels\n", c ? "mmx2" : "mmx",
00152 x ? 8 : 16, x ? 8 : 16);
00153 test_motion("mmx", mmxctx.pix_abs[x][0], cctx.pix_abs[x][0]);
00154 test_motion("mmx_x2", mmxctx.pix_abs[x][1], cctx.pix_abs[x][1]);
00155 test_motion("mmx_y2", mmxctx.pix_abs[x][2], cctx.pix_abs[x][2]);
00156 test_motion("mmx_xy2", mmxctx.pix_abs[x][3], cctx.pix_abs[x][3]);
00157 }
00158 }
00159 av_free(ctx);
00160
00161 return 0;
00162 }