Statistics
| Branch: | Revision:

ffmpeg / tests / dsptest.c @ ec9a41f5

History | View | Annotate | Download (3.21 KB)

1
/*
2
 * MMX optimized DSP utils
3
 * Copyright (c) 2000, 2001 Gerard Lantau.
4
 *
5
 * This program is free software; you can redistribute it and/or modify
6
 * it under the terms of the GNU General Public License as published by
7
 * the Free Software Foundation; either version 2 of the License, or
8
 * (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18
 *
19
 */
20

    
21
#define TESTCPU_MAIN
22
#include "dsputil.h"
23
#include "../libavcodec/i386/cputest.c"
24
#include "../libavcodec/i386/dsputil_mmx.c"
25
#undef TESTCPU_MAIN
26

    
27
#define PAD 0x10000
28
/*
29
 * for testing speed of various routine - should be probably extended
30
 * for a general purpose regression test later
31
 *
32
 * currently only for i386 - FIXME
33
 */
34
static const struct pix_func {
35
    char* name;
36
    op_pixels_func func;
37
    int mm_flags;
38
} pix_func[] = {
39
    { "put_pixels_x2_mmx", put_pixels_y2_mmx, MM_MMX },
40
    { "put_pixels_x2_3dnow", put_pixels_y2_3dnow, MM_3DNOW },
41
    { "put_pixels_x2_mmx2", put_pixels_y2_mmx2, MM_MMXEXT | PAD },
42

    
43
    { "put_no_rnd_pixels_x2_mmx", put_no_rnd_pixels_x2_mmx, MM_MMX },
44
    { "put_no_rnd_pixels_x2_3dnow", put_no_rnd_pixels_x2_3dnow, MM_3DNOW },
45
    { "put_no_rnd_pixels_x2_mmx2", put_no_rnd_pixels_x2_mmx2, MM_MMXEXT | PAD },
46

    
47
    { "put_pixels_y2_mmx", put_pixels_y2_mmx, MM_MMX },
48
    { "put_pixels_y2_3dnow", put_pixels_y2_3dnow, MM_3DNOW },
49
    { "put_pixels_y2_mmx2", put_pixels_y2_mmx2, MM_MMXEXT | PAD },
50
    { 0, 0 }
51
};
52

    
53
static inline long long rdtsc()
54
{
55
    long long l;
56
    asm volatile(   "rdtsc\n\t"
57
                    : "=A" (l)
58
                );
59
    return l;
60
}
61

    
62
static test_speed(int step)
63
{
64
    const struct pix_func* pix = pix_func;
65
    const int linesize = 720;
66
    char empty[32768];
67
    char* bu =(char*)(((long)empty + 32) & ~0xf);
68

    
69
    while (pix->name)
70
    {
71
        int i;
72
        uint64_t te, ts;
73
        op_pixels_func func = pix->func;
74
        char* im = bu;
75

    
76
        if (!(pix->mm_flags & mm_flags))
77
            continue;
78

    
79
        printf("%30s... ", pix->name);
80
        fflush(stdout);
81
        ts = rdtsc();
82
        for(i=0; i<100000; i++){
83
            func(im, im + 1000, linesize, 16);
84
            im += step;
85
            if (im > bu + 20000)
86
                im = bu;
87
        }
88
        te = rdtsc();
89
        emms();
90
        printf("% 9d\n", (int)(te - ts));
91
        if (pix->mm_flags & PAD)
92
            puts("");
93
        pix++;
94
    }
95
}
96

    
97
int main(int argc, char* argv[])
98
{
99
    int step = 16;
100

    
101
    if (argc > 1)
102
    {
103
        // something simple for now
104
        if (argc > 2 && (strcmp("-s", argv[1]) == 0
105
                         || strcmp("-step", argv[1]) == 0))
106
            step = atoi(argv[2]);
107
    }
108

    
109
    mm_flags = mm_support();
110
    printf("dsptest: CPU flags:");
111
    if (mm_flags & MM_MMX)
112
        printf(" mmx");
113
    if (mm_flags & MM_MMXEXT)
114
        printf(" mmxext");
115
    if (mm_flags & MM_3DNOW)
116
        printf(" 3dnow");
117
    if (mm_flags & MM_SSE)
118
        printf(" sse");
119
    if (mm_flags & MM_SSE2)
120
        printf(" sse2");
121
    printf("\n");
122

    
123
    printf("Using step: %d\n", step);
124
    test_speed(step);
125
}