Statistics
| Branch: | Revision:

ffmpeg / libavcodec / motion_test.c @ 7a886063

History | View | Annotate | Download (4 KB)

1 04d7f601 Diego Biurrun
/*
2
 * (c) 2001 Fabrice Bellard
3
 *
4 b78e7197 Diego Biurrun
 * This file is part of FFmpeg.
5
 *
6
 * FFmpeg is free software; you can redistribute it and/or
7 04d7f601 Diego Biurrun
 * modify it under the terms of the GNU Lesser General Public
8
 * License as published by the Free Software Foundation; either
9 b78e7197 Diego Biurrun
 * version 2.1 of the License, or (at your option) any later version.
10 04d7f601 Diego Biurrun
 *
11 b78e7197 Diego Biurrun
 * FFmpeg is distributed in the hope that it will be useful,
12 04d7f601 Diego Biurrun
 * 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 b78e7197 Diego Biurrun
 * License along with FFmpeg; if not, write to the Free Software
18 04d7f601 Diego Biurrun
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
 */
20 983e3246 Michael Niedermayer
21
/**
22
 * @file motion_test.c
23
 * motion test.
24
 */
25
26 d0a0b248 Fabrice Bellard
#include <stdlib.h>
27
#include <stdio.h>
28
#include <string.h>
29
#include <sys/time.h>
30
#include <unistd.h>
31
32
#include "dsputil.h"
33
34
#include "i386/mmx.h"
35
36 8823419f Diego Biurrun
#undef printf
37
38 0c1a9eda Zdenek Kabelac
int pix_abs16x16_mmx(uint8_t *blk1, uint8_t *blk2, int lx);
39
int pix_abs16x16_mmx1(uint8_t *blk1, uint8_t *blk2, int lx);
40 cad35abc Diego Biurrun
int pix_abs16x16_c(uint8_t *blk1, uint8_t *blk2, int lx);
41 0c1a9eda Zdenek Kabelac
int pix_abs16x16_x2_mmx(uint8_t *blk1, uint8_t *blk2, int lx);
42
int pix_abs16x16_x2_mmx1(uint8_t *blk1, uint8_t *blk2, int lx);
43
int pix_abs16x16_x2_c(uint8_t *blk1, uint8_t *blk2, int lx);
44
int pix_abs16x16_y2_mmx(uint8_t *blk1, uint8_t *blk2, int lx);
45
int pix_abs16x16_y2_mmx1(uint8_t *blk1, uint8_t *blk2, int lx);
46
int pix_abs16x16_y2_c(uint8_t *blk1, uint8_t *blk2, int lx);
47
int pix_abs16x16_xy2_mmx(uint8_t *blk1, uint8_t *blk2, int lx);
48
int pix_abs16x16_xy2_mmx1(uint8_t *blk1, uint8_t *blk2, int lx);
49
int pix_abs16x16_xy2_c(uint8_t *blk1, uint8_t *blk2, int lx);
50 6acce86b Michael Niedermayer
51 0c1a9eda Zdenek Kabelac
typedef int motion_func(uint8_t *blk1, uint8_t *blk2, int lx);
52 d0a0b248 Fabrice Bellard
53
#define WIDTH 64
54
#define HEIGHT 64
55
56 0c1a9eda Zdenek Kabelac
uint8_t img1[WIDTH * HEIGHT];
57
uint8_t img2[WIDTH * HEIGHT];
58 d0a0b248 Fabrice Bellard
59 0c1a9eda Zdenek Kabelac
void fill_random(uint8_t *tab, int size)
60 d0a0b248 Fabrice Bellard
{
61
    int i;
62
    for(i=0;i<size;i++) {
63
#if 1
64
        tab[i] = random() % 256;
65
#else
66
        tab[i] = i;
67
#endif
68
    }
69
}
70
71
void help(void)
72
{
73
    printf("motion-test [-h]\n"
74
           "test motion implementations\n");
75
    exit(1);
76
}
77
78 0c1a9eda Zdenek Kabelac
int64_t gettime(void)
79 d0a0b248 Fabrice Bellard
{
80
    struct timeval tv;
81
    gettimeofday(&tv,NULL);
82 0c1a9eda Zdenek Kabelac
    return (int64_t)tv.tv_sec * 1000000 + tv.tv_usec;
83 d0a0b248 Fabrice Bellard
}
84
85
#define NB_ITS 500
86
87
int dummy;
88
89
void test_motion(const char *name,
90
                 motion_func *test_func, motion_func *ref_func)
91
{
92
    int x, y, d1, d2, it;
93 0c1a9eda Zdenek Kabelac
    uint8_t *ptr;
94
    int64_t ti;
95 d0a0b248 Fabrice Bellard
    printf("testing '%s'\n", name);
96
97
    /* test correctness */
98
    for(it=0;it<20;it++) {
99
100
        fill_random(img1, WIDTH * HEIGHT);
101
        fill_random(img2, WIDTH * HEIGHT);
102 115329f1 Diego Biurrun
103 d0a0b248 Fabrice Bellard
        for(y=0;y<HEIGHT-17;y++) {
104
            for(x=0;x<WIDTH-17;x++) {
105 115329f1 Diego Biurrun
                ptr = img2 + y * WIDTH + x;
106 6acce86b Michael Niedermayer
                d1 = test_func(img1, ptr, WIDTH);
107
                d2 = ref_func(img1, ptr, WIDTH);
108 d0a0b248 Fabrice Bellard
                if (d1 != d2) {
109
                    printf("error: mmx=%d c=%d\n", d1, d2);
110
                }
111
            }
112
        }
113
    }
114
    emms();
115 115329f1 Diego Biurrun
116 d0a0b248 Fabrice Bellard
    /* speed test */
117
    ti = gettime();
118
    d1 = 0;
119
    for(it=0;it<NB_ITS;it++) {
120
        for(y=0;y<HEIGHT-17;y++) {
121
            for(x=0;x<WIDTH-17;x++) {
122 115329f1 Diego Biurrun
                ptr = img2 + y * WIDTH + x;
123 6acce86b Michael Niedermayer
                d1 += test_func(img1, ptr, WIDTH);
124 d0a0b248 Fabrice Bellard
            }
125
        }
126
    }
127
    emms();
128
    dummy = d1; /* avoid optimisation */
129
    ti = gettime() - ti;
130 115329f1 Diego Biurrun
131
    printf("  %0.0f kop/s\n",
132
           (double)NB_ITS * (WIDTH - 16) * (HEIGHT - 16) /
133 d0a0b248 Fabrice Bellard
           (double)(ti / 1000.0));
134
}
135
136
137
int main(int argc, char **argv)
138
{
139
    int c;
140 115329f1 Diego Biurrun
141 d0a0b248 Fabrice Bellard
    for(;;) {
142
        c = getopt(argc, argv, "h");
143
        if (c == -1)
144
            break;
145
        switch(c) {
146
        case 'h':
147
            help();
148
            break;
149
        }
150
    }
151 115329f1 Diego Biurrun
152 d0a0b248 Fabrice Bellard
    printf("ffmpeg motion test\n");
153
154
    test_motion("mmx", pix_abs16x16_mmx, pix_abs16x16_c);
155
    test_motion("mmx_x2", pix_abs16x16_x2_mmx, pix_abs16x16_x2_c);
156
    test_motion("mmx_y2", pix_abs16x16_y2_mmx, pix_abs16x16_y2_c);
157
    test_motion("mmx_xy2", pix_abs16x16_xy2_mmx, pix_abs16x16_xy2_c);
158
    return 0;
159
}