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