Libav 0.7.1
|
00001 /* 00002 * (c) 2001 Fabrice Bellard 00003 * 00004 * This file is part of Libav. 00005 * 00006 * Libav is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU Lesser General Public 00008 * License as published by the Free Software Foundation; either 00009 * version 2.1 of the License, or (at your option) any later version. 00010 * 00011 * Libav is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 * Lesser General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Lesser General Public 00017 * License along with Libav; if not, write to the Free Software 00018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 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 "config.h" 00033 #include "dsputil.h" 00034 #include "libavutil/lfg.h" 00035 00036 #undef exit 00037 #undef printf 00038 00039 #define WIDTH 64 00040 #define HEIGHT 64 00041 00042 uint8_t img1[WIDTH * HEIGHT]; 00043 uint8_t img2[WIDTH * HEIGHT]; 00044 00045 static void fill_random(uint8_t *tab, int size) 00046 { 00047 int i; 00048 AVLFG prng; 00049 00050 av_lfg_init(&prng, 1); 00051 for(i=0;i<size;i++) { 00052 #if 1 00053 tab[i] = av_lfg_get(&prng) % 256; 00054 #else 00055 tab[i] = i; 00056 #endif 00057 } 00058 } 00059 00060 static void help(void) 00061 { 00062 printf("motion-test [-h]\n" 00063 "test motion implementations\n"); 00064 exit(1); 00065 } 00066 00067 static int64_t gettime(void) 00068 { 00069 struct timeval tv; 00070 gettimeofday(&tv,NULL); 00071 return (int64_t)tv.tv_sec * 1000000 + tv.tv_usec; 00072 } 00073 00074 #define NB_ITS 500 00075 00076 int dummy; 00077 00078 static void test_motion(const char *name, 00079 me_cmp_func test_func, me_cmp_func ref_func) 00080 { 00081 int x, y, d1, d2, it; 00082 uint8_t *ptr; 00083 int64_t ti; 00084 printf("testing '%s'\n", name); 00085 00086 /* test correctness */ 00087 for(it=0;it<20;it++) { 00088 00089 fill_random(img1, WIDTH * HEIGHT); 00090 fill_random(img2, WIDTH * HEIGHT); 00091 00092 for(y=0;y<HEIGHT-17;y++) { 00093 for(x=0;x<WIDTH-17;x++) { 00094 ptr = img2 + y * WIDTH + x; 00095 d1 = test_func(NULL, img1, ptr, WIDTH, 1); 00096 d2 = ref_func(NULL, img1, ptr, WIDTH, 1); 00097 if (d1 != d2) { 00098 printf("error: mmx=%d c=%d\n", d1, d2); 00099 } 00100 } 00101 } 00102 } 00103 emms_c(); 00104 00105 /* speed test */ 00106 ti = gettime(); 00107 d1 = 0; 00108 for(it=0;it<NB_ITS;it++) { 00109 for(y=0;y<HEIGHT-17;y++) { 00110 for(x=0;x<WIDTH-17;x++) { 00111 ptr = img2 + y * WIDTH + x; 00112 d1 += test_func(NULL, img1, ptr, WIDTH, 1); 00113 } 00114 } 00115 } 00116 emms_c(); 00117 dummy = d1; /* avoid optimization */ 00118 ti = gettime() - ti; 00119 00120 printf(" %0.0f kop/s\n", 00121 (double)NB_ITS * (WIDTH - 16) * (HEIGHT - 16) / 00122 (double)(ti / 1000.0)); 00123 } 00124 00125 00126 int main(int argc, char **argv) 00127 { 00128 AVCodecContext *ctx; 00129 int c; 00130 DSPContext cctx, mmxctx; 00131 int flags[2] = { AV_CPU_FLAG_MMX, AV_CPU_FLAG_MMX2 }; 00132 int flags_size = HAVE_MMX2 ? 2 : 1; 00133 00134 for(;;) { 00135 c = getopt(argc, argv, "h"); 00136 if (c == -1) 00137 break; 00138 switch(c) { 00139 case 'h': 00140 help(); 00141 break; 00142 } 00143 } 00144 00145 printf("ffmpeg motion test\n"); 00146 00147 ctx = avcodec_alloc_context(); 00148 ctx->dsp_mask = AV_CPU_FLAG_FORCE; 00149 dsputil_init(&cctx, ctx); 00150 for (c = 0; c < flags_size; c++) { 00151 int x; 00152 ctx->dsp_mask = AV_CPU_FLAG_FORCE | flags[c]; 00153 dsputil_init(&mmxctx, ctx); 00154 00155 for (x = 0; x < 2; x++) { 00156 printf("%s for %dx%d pixels\n", c ? "mmx2" : "mmx", 00157 x ? 8 : 16, x ? 8 : 16); 00158 test_motion("mmx", mmxctx.pix_abs[x][0], cctx.pix_abs[x][0]); 00159 test_motion("mmx_x2", mmxctx.pix_abs[x][1], cctx.pix_abs[x][1]); 00160 test_motion("mmx_y2", mmxctx.pix_abs[x][2], cctx.pix_abs[x][2]); 00161 test_motion("mmx_xy2", mmxctx.pix_abs[x][3], cctx.pix_abs[x][3]); 00162 } 00163 } 00164 av_free(ctx); 00165 00166 return 0; 00167 }