1/* 2 * (c) 2001 Fabrice Bellard 3 * 4 * This file is part of FFmpeg. 5 * 6 * FFmpeg is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU Lesser General Public 8 * License as published by the Free Software Foundation; either 9 * version 2.1 of the License, or (at your option) any later version. 10 * 11 * FFmpeg is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 * Lesser General Public License for more details. 15 * 16 * You should have received a copy of the GNU Lesser General Public 17 * License along with FFmpeg; if not, write to the Free Software 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 */ 20 21/** 22 * @file 23 * motion test. 24 */ 25 26#include <stdlib.h> 27#include <stdio.h> 28#include <string.h> 29#include <sys/time.h> 30#include <unistd.h> 31 32#include "config.h" 33#include "dsputil.h" 34#include "libavutil/lfg.h" 35 36#undef exit 37#undef printf 38 39#define WIDTH 64 40#define HEIGHT 64 41 42uint8_t img1[WIDTH * HEIGHT]; 43uint8_t img2[WIDTH * HEIGHT]; 44 45static void fill_random(uint8_t *tab, int size) 46{ 47 int i; 48 AVLFG prng; 49 50 av_lfg_init(&prng, 1); 51 for(i=0;i<size;i++) { 52#if 1 53 tab[i] = av_lfg_get(&prng) % 256; 54#else 55 tab[i] = i; 56#endif 57 } 58} 59 60static void help(void) 61{ 62 printf("motion-test [-h]\n" 63 "test motion implementations\n"); 64 exit(1); 65} 66 67static int64_t gettime(void) 68{ 69 struct timeval tv; 70 gettimeofday(&tv,NULL); 71 return (int64_t)tv.tv_sec * 1000000 + tv.tv_usec; 72} 73 74#define NB_ITS 500 75 76int dummy; 77 78static void test_motion(const char *name, 79 me_cmp_func test_func, me_cmp_func ref_func) 80{ 81 int x, y, d1, d2, it; 82 uint8_t *ptr; 83 int64_t ti; 84 printf("testing '%s'\n", name); 85 86 /* test correctness */ 87 for(it=0;it<20;it++) { 88 89 fill_random(img1, WIDTH * HEIGHT); 90 fill_random(img2, WIDTH * HEIGHT); 91 92 for(y=0;y<HEIGHT-17;y++) { 93 for(x=0;x<WIDTH-17;x++) { 94 ptr = img2 + y * WIDTH + x; 95 d1 = test_func(NULL, img1, ptr, WIDTH, 1); 96 d2 = ref_func(NULL, img1, ptr, WIDTH, 1); 97 if (d1 != d2) { 98 printf("error: mmx=%d c=%d\n", d1, d2); 99 } 100 } 101 } 102 } 103 emms_c(); 104 105 /* speed test */ 106 ti = gettime(); 107 d1 = 0; 108 for(it=0;it<NB_ITS;it++) { 109 for(y=0;y<HEIGHT-17;y++) { 110 for(x=0;x<WIDTH-17;x++) { 111 ptr = img2 + y * WIDTH + x; 112 d1 += test_func(NULL, img1, ptr, WIDTH, 1); 113 } 114 } 115 } 116 emms_c(); 117 dummy = d1; /* avoid optimization */ 118 ti = gettime() - ti; 119 120 printf(" %0.0f kop/s\n", 121 (double)NB_ITS * (WIDTH - 16) * (HEIGHT - 16) / 122 (double)(ti / 1000.0)); 123} 124 125 126int main(int argc, char **argv) 127{ 128 AVCodecContext *ctx; 129 int c; 130 DSPContext cctx, mmxctx; 131 int flags[2] = { FF_MM_MMX, FF_MM_MMX2 }; 132 int flags_size = HAVE_MMX2 ? 2 : 1; 133 134 for(;;) { 135 c = getopt(argc, argv, "h"); 136 if (c == -1) 137 break; 138 switch(c) { 139 case 'h': 140 help(); 141 break; 142 } 143 } 144 145 printf("ffmpeg motion test\n"); 146 147 ctx = avcodec_alloc_context(); 148 ctx->dsp_mask = FF_MM_FORCE; 149 dsputil_init(&cctx, ctx); 150 for (c = 0; c < flags_size; c++) { 151 int x; 152 ctx->dsp_mask = FF_MM_FORCE | flags[c]; 153 dsputil_init(&mmxctx, ctx); 154 155 for (x = 0; x < 2; x++) { 156 printf("%s for %dx%d pixels\n", c ? "mmx2" : "mmx", 157 x ? 8 : 16, x ? 8 : 16); 158 test_motion("mmx", mmxctx.pix_abs[x][0], cctx.pix_abs[x][0]); 159 test_motion("mmx_x2", mmxctx.pix_abs[x][1], cctx.pix_abs[x][1]); 160 test_motion("mmx_y2", mmxctx.pix_abs[x][2], cctx.pix_abs[x][2]); 161 test_motion("mmx_xy2", mmxctx.pix_abs[x][3], cctx.pix_abs[x][3]); 162 } 163 } 164 av_free(ctx); 165 166 return 0; 167} 168