Statistics
| Branch: | Revision:

ffmpeg / tests / dsptest.c @ d0c30ca5

History | View | Annotate | Download (3.78 KB)

1
/*
2
 * MMX optimized DSP utils
3
 * Copyright (c) 2000, 2001, 2002 Fabrice Bellard.
4
 *
5
 * This library is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU Lesser General Public
7
 * License as published by the Free Software Foundation; either
8
 * version 2 of the License, or (at your option) any later version.
9
 *
10
 * This library 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 GNU
13
 * Lesser General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU Lesser General Public
16
 * License along with this library; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
 */
19
#define TESTCPU_MAIN
20
#include "dsputil.h"
21
//#include "../libavcodec/dsputil.c"
22
#include "../libavcodec/i386/cputest.c"
23
#include "../libavcodec/i386/dsputil_mmx.c"
24
#undef TESTCPU_MAIN
25

    
26
#define PAD 0x10000
27
/*
28
 * for testing speed of various routine - should be probably extended
29
 * for a general purpose regression test later
30
 *
31
 * currently only for i386 - FIXME
32
 */
33

    
34
#define PIX_FUNC_C(a) \
35
    { #a "_c", a ## _c, 0 }, \
36
    { #a "_mmx", a ## _mmx, MM_MMX }, \
37
    { #a "_mmx2", a ## _mmx2, MM_MMXEXT | PAD }
38

    
39
#define PIX_FUNC(a) \
40
    { #a "_mmx", a ## _mmx, MM_MMX }, \
41
    { #a "_3dnow", a ## _3dnow, MM_3DNOW }, \
42
    { #a "_mmx2", a ## _mmx2, MM_MMXEXT | PAD }
43

    
44
#define PIX_FUNC_MMX(a) \
45
    { #a "_mmx", a ## _mmx, MM_MMX | PAD }
46

    
47
/*
48
    PIX_FUNC_C(pix_abs16x16),
49
    PIX_FUNC_C(pix_abs16x16_x2),
50
    PIX_FUNC_C(pix_abs16x16_y2),
51
    PIX_FUNC_C(pix_abs16x16_xy2),
52
    PIX_FUNC_C(pix_abs8x8),
53
    PIX_FUNC_C(pix_abs8x8_x2),
54
    PIX_FUNC_C(pix_abs8x8_y2),
55
    PIX_FUNC_C(pix_abs8x8_xy2),
56
*/
57

    
58
static const struct pix_func {
59
    char* name;
60
    op_pixels_func func;
61
    int mm_flags;
62
} pix_func[] = {
63

    
64
    PIX_FUNC_MMX(put_pixels),
65
#if 1
66
    PIX_FUNC(put_pixels_x2),
67
    PIX_FUNC(put_pixels_y2),
68
    PIX_FUNC_MMX(put_pixels_xy2),
69

    
70
    PIX_FUNC(put_no_rnd_pixels_x2),
71
    PIX_FUNC(put_no_rnd_pixels_y2),
72
    PIX_FUNC_MMX(put_no_rnd_pixels_xy2),
73

    
74
    PIX_FUNC(avg_pixels),
75
    PIX_FUNC(avg_pixels_x2),
76
    PIX_FUNC(avg_pixels_y2),
77
    PIX_FUNC(avg_pixels_xy2),
78
#endif
79
    { 0, 0 }
80
};
81

    
82
static inline long long rdtsc()
83
{
84
    long long l;
85
    asm volatile(   "rdtsc\n\t"
86
                    : "=A" (l)
87
                );
88
    return l;
89
}
90

    
91
static test_speed(int step)
92
{
93
    const struct pix_func* pix = pix_func;
94
    const int linesize = 720;
95
    char empty[32768];
96
    char* bu =(char*)(((long)empty + 32) & ~0xf);
97

    
98
    int sum = 0;
99

    
100
    while (pix->name)
101
    {
102
        int i;
103
        uint64_t te, ts;
104
        op_pixels_func func = pix->func;
105
        char* im = bu;
106

    
107
        if (!(pix->mm_flags & mm_flags))
108
            continue;
109

    
110
        printf("%30s... ", pix->name);
111
        fflush(stdout);
112
        ts = rdtsc();
113
        for(i=0; i<100000; i++){
114
            func(im, im + 1000, linesize, 16);
115
            im += step;
116
            if (im > bu + 20000)
117
                im = bu;
118
        }
119
        te = rdtsc();
120
        emms();
121
        printf("% 9d\n", (int)(te - ts));
122
        sum += (te - ts) / 100000;
123
        if (pix->mm_flags & PAD)
124
            puts("");
125
        pix++;
126
    }
127

    
128
    printf("Total sum: %d\n", sum);
129
}
130

    
131
int main(int argc, char* argv[])
132
{
133
    int step = 16;
134

    
135
    if (argc > 1)
136
    {
137
        // something simple for now
138
        if (argc > 2 && (strcmp("-s", argv[1]) == 0
139
                         || strcmp("-step", argv[1]) == 0))
140
            step = atoi(argv[2]);
141
    }
142

    
143
    mm_flags = mm_support();
144
    printf("%s: detected CPU flags:", argv[0]);
145
    if (mm_flags & MM_MMX)
146
        printf(" mmx");
147
    if (mm_flags & MM_MMXEXT)
148
        printf(" mmxext");
149
    if (mm_flags & MM_3DNOW)
150
        printf(" 3dnow");
151
    if (mm_flags & MM_SSE)
152
        printf(" sse");
153
    if (mm_flags & MM_SSE2)
154
        printf(" sse2");
155
    printf("\n");
156

    
157
    printf("Using step: %d\n", step);
158
    test_speed(step);
159
}