]> git.sesse.net Git - ffmpeg/blob - tests/dsptest.c
ab51027fa6704831260c0598b4e2d84cb081eae4
[ffmpeg] / tests / dsptest.c
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/dsputil.c"
24 #include "../libavcodec/i386/cputest.c"
25 #include "../libavcodec/i386/dsputil_mmx.c"
26 #undef TESTCPU_MAIN
27
28 #define PAD 0x10000
29 /*
30  * for testing speed of various routine - should be probably extended
31  * for a general purpose regression test later
32  *
33  * currently only for i386 - FIXME
34  */
35
36 #define PIX_FUNC_C(a) \
37     { #a "_c", a ## _c, 0 }, \
38     { #a "_mmx", a ## _mmx, MM_MMX }, \
39     { #a "_mmx2", a ## _mmx2, MM_MMXEXT | PAD }
40
41 #define PIX_FUNC(a) \
42     { #a "_mmx", a ## _mmx, MM_MMX }, \
43     { #a "_3dnow", a ## _3dnow, MM_3DNOW }, \
44     { #a "_mmx2", a ## _mmx2, MM_MMXEXT | PAD }
45
46 #define PIX_FUNC_MMX(a) \
47     { #a "_mmx", a ## _mmx, MM_MMX | PAD }
48
49 /*
50     PIX_FUNC_C(pix_abs16x16),
51     PIX_FUNC_C(pix_abs16x16_x2),
52     PIX_FUNC_C(pix_abs16x16_y2),
53     PIX_FUNC_C(pix_abs16x16_xy2),
54     PIX_FUNC_C(pix_abs8x8),
55     PIX_FUNC_C(pix_abs8x8_x2),
56     PIX_FUNC_C(pix_abs8x8_y2),
57     PIX_FUNC_C(pix_abs8x8_xy2),
58 */
59
60 static const struct pix_func {
61     char* name;
62     op_pixels_func func;
63     int mm_flags;
64 } pix_func[] = {
65
66     PIX_FUNC_MMX(put_pixels),
67     PIX_FUNC_MMX(put_pixels_x2),
68     PIX_FUNC_MMX(put_pixels_y2),
69     PIX_FUNC_MMX(put_pixels_xy2),
70
71     PIX_FUNC(put_no_rnd_pixels_x2),
72     PIX_FUNC(put_no_rnd_pixels_y2),
73     PIX_FUNC_MMX(put_no_rnd_pixels_xy2),
74
75     PIX_FUNC(avg_pixels),
76     PIX_FUNC(avg_pixels_x2),
77     PIX_FUNC(avg_pixels_y2),
78     PIX_FUNC(avg_pixels_xy2),
79
80     { 0, 0 }
81 };
82
83 static inline long long rdtsc()
84 {
85     long long l;
86     asm volatile(   "rdtsc\n\t"
87                     : "=A" (l)
88                 );
89     return l;
90 }
91
92 static test_speed(int step)
93 {
94     const struct pix_func* pix = pix_func;
95     const int linesize = 720;
96     char empty[32768];
97     char* bu =(char*)(((long)empty + 32) & ~0xf);
98
99     int sum = 0;
100
101     while (pix->name)
102     {
103         int i;
104         uint64_t te, ts;
105         op_pixels_func func = pix->func;
106         char* im = bu;
107
108         if (!(pix->mm_flags & mm_flags))
109             continue;
110
111         printf("%30s... ", pix->name);
112         fflush(stdout);
113         ts = rdtsc();
114         for(i=0; i<100000; i++){
115             func(im, im + 1000, linesize, 16);
116             im += step;
117             if (im > bu + 20000)
118                 im = bu;
119         }
120         te = rdtsc();
121         emms();
122         printf("% 9d\n", (int)(te - ts));
123         sum += (te - ts) / 100000;
124         if (pix->mm_flags & PAD)
125             puts("");
126         pix++;
127     }
128
129     printf("Total sum: %d\n", sum);
130 }
131
132 int main(int argc, char* argv[])
133 {
134     int step = 16;
135
136     if (argc > 1)
137     {
138         // something simple for now
139         if (argc > 2 && (strcmp("-s", argv[1]) == 0
140                          || strcmp("-step", argv[1]) == 0))
141             step = atoi(argv[2]);
142     }
143
144     mm_flags = mm_support();
145     printf("dsptest: CPU flags:");
146     if (mm_flags & MM_MMX)
147         printf(" mmx");
148     if (mm_flags & MM_MMXEXT)
149         printf(" mmxext");
150     if (mm_flags & MM_3DNOW)
151         printf(" 3dnow");
152     if (mm_flags & MM_SSE)
153         printf(" sse");
154     if (mm_flags & MM_SSE2)
155         printf(" sse2");
156     printf("\n");
157
158     printf("Using step: %d\n", step);
159     test_speed(step);
160 }