motion-test.c
Go to the documentation of this file.
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 
30 #include "config.h"
31 #include "dsputil.h"
32 #include "libavutil/internal.h"
33 #include "libavutil/lfg.h"
34 #include "libavutil/mem.h"
35 #include "libavutil/time.h"
36 
37 #undef printf
38 
39 #define WIDTH 64
40 #define HEIGHT 64
41 
44 
45 static 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  tab[i] = av_lfg_get(&prng) % 256;
53  }
54 }
55 
56 static void help(void)
57 {
58  printf("motion-test [-h]\n"
59  "test motion implementations\n");
60 }
61 
62 #define NB_ITS 500
63 
64 int dummy;
65 
66 static void test_motion(const char *name,
67  me_cmp_func test_func, me_cmp_func ref_func)
68 {
69  int x, y, d1, d2, it;
70  uint8_t *ptr;
71  int64_t ti;
72  printf("testing '%s'\n", name);
73 
74  /* test correctness */
75  for(it=0;it<20;it++) {
76 
78  fill_random(img2, WIDTH * HEIGHT);
79 
80  for(y=0;y<HEIGHT-17;y++) {
81  for(x=0;x<WIDTH-17;x++) {
82  ptr = img2 + y * WIDTH + x;
83  d1 = test_func(NULL, img1, ptr, WIDTH, 8);
84  d2 = ref_func(NULL, img1, ptr, WIDTH, 8);
85  if (d1 != d2) {
86  printf("error: mmx=%d c=%d\n", d1, d2);
87  }
88  }
89  }
90  }
91  emms_c();
92 
93  /* speed test */
94  ti = av_gettime();
95  d1 = 0;
96  for(it=0;it<NB_ITS;it++) {
97  for(y=0;y<HEIGHT-17;y++) {
98  for(x=0;x<WIDTH-17;x++) {
99  ptr = img2 + y * WIDTH + x;
100  d1 += test_func(NULL, img1, ptr, WIDTH, 8);
101  }
102  }
103  }
104  emms_c();
105  dummy = d1; /* avoid optimization */
106  ti = av_gettime() - ti;
107 
108  printf(" %0.0f kop/s\n",
109  (double)NB_ITS * (WIDTH - 16) * (HEIGHT - 16) /
110  (double)(ti / 1000.0));
111 }
112 
113 
114 int main(int argc, char **argv)
115 {
116  AVCodecContext *ctx;
117  int c;
118  DSPContext cctx, mmxctx;
120  int flags_size = HAVE_MMXEXT ? 2 : 1;
121 
122  if (argc > 1) {
123  help();
124  return 1;
125  }
126 
127  printf("ffmpeg motion test\n");
128 
130  ctx->flags |= CODEC_FLAG_BITEXACT;
131  memset(&cctx, 0, sizeof(cctx));
132  ff_dsputil_init(&cctx, ctx);
133  for (c = 0; c < flags_size; c++) {
134  int x;
135  av_force_cpu_flags(flags[c]);
136  memset(&mmxctx, 0, sizeof(mmxctx));
137  ff_dsputil_init(&mmxctx, ctx);
138 
139  for (x = 0; x < 2; x++) {
140  printf("%s for %dx%d pixels\n", c ? "mmx2" : "mmx",
141  x ? 8 : 16, x ? 8 : 16);
142  test_motion("mmx", mmxctx.pix_abs[x][0], cctx.pix_abs[x][0]);
143  test_motion("mmx_x2", mmxctx.pix_abs[x][1], cctx.pix_abs[x][1]);
144  test_motion("mmx_y2", mmxctx.pix_abs[x][2], cctx.pix_abs[x][2]);
145  test_motion("mmx_xy2", mmxctx.pix_abs[x][3], cctx.pix_abs[x][3]);
146  }
147  }
148  av_free(ctx);
149 
150  return 0;
151 }
const char * name
Definition: avisynth_c.h:675
Definition: lfg.h:25
av_cold void ff_dsputil_init(DSPContext *c, AVCodecContext *avctx)
Definition: dsputil.c:2675
memory handling functions
#define NB_ITS
Definition: motion-test.c:62
int main(int argc, char **argv)
Definition: motion-test.c:114
uint8_t
#define emms_c()
#define AV_CPU_FLAG_MMXEXT
SSE integer functions or AMD MMX ext.
Definition: cpu.h:30
#define CODEC_FLAG_BITEXACT
Use only bitexact stuff (except (I)DCT).
Discrete Time axis x
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
Definition: mem.c:183
#define WIDTH
Definition: motion-test.c:39
static uint8_t img1[WIDTH *HEIGHT]
Definition: motion-test.c:42
int flags
CODEC_FLAG_*.
init variable d2
static void test_motion(const char *name, me_cmp_func test_func, me_cmp_func ref_func)
Definition: motion-test.c:66
int size
common internal API header
AVCodecContext * avcodec_alloc_context3(const AVCodec *codec)
Allocate an AVCodecContext and set its fields to default values.
static void help(void)
Definition: motion-test.c:56
int(* me_cmp_func)(void *s, uint8_t *blk1, uint8_t *blk2, int line_size, int h)
Definition: dsputil.h:109
int64_t av_gettime(void)
Get the current time in microseconds.
Definition: time.c:39
NULL
Definition: eval.c:55
main external API structure.
#define AV_CPU_FLAG_MMX
standard MMX
Definition: cpu.h:29
static unsigned int av_lfg_get(AVLFG *c)
Get the next random unsigned 32-bit number using an ALFG.
Definition: lfg.h:38
synthesis window for stochastic i
av_cold void av_lfg_init(AVLFG *c, unsigned int seed)
Definition: lfg.c:30
#define HEIGHT
Definition: motion-test.c:40
static uint8_t img2[WIDTH *HEIGHT]
Definition: motion-test.c:43
static int flags
Definition: cpu.c:23
static double c[64]
#define HAVE_MMXEXT
Definition: config.h:49
function y
Definition: D.m:1
DSP utils.
printf("static const uint8_t my_array[100] = {\n")
static void fill_random(uint8_t *tab, int size)
Definition: motion-test.c:45
static const struct twinvq_data tab
void av_force_cpu_flags(int arg)
Disables cpu detection and forces the specified flags.
Definition: cpu.c:25
int dummy
Definition: motion-test.c:64
me_cmp_func pix_abs[2][4]
Definition: dsputil.h:194
DSPContext.
Definition: dsputil.h:127