Do not specify directories in #include path, -I flags take care of this.
[libav.git] / tests / dsptest.c
CommitLineData
ec9a41f5
ZK
1/*
2 * MMX optimized DSP utils
d0c30ca5 3 * Copyright (c) 2000, 2001, 2002 Fabrice Bellard.
ec9a41f5 4 *
d0c30ca5
FB
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.
ec9a41f5 9 *
d0c30ca5 10 * This library is distributed in the hope that it will be useful,
ec9a41f5 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
d0c30ca5
FB
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
ec9a41f5 14 *
d0c30ca5
FB
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
5509bffa 17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
ec9a41f5 18 */
ec9a41f5 19#define TESTCPU_MAIN
6fea8454 20#include "avcodec.h"
ec9a41f5 21#include "dsputil.h"
6fea8454
ZK
22#include "mpegvideo.h"
23#include "mpeg12data.h"
24#include "mpeg4data.h"
f3ab6d91
RB
25#include "cputest.c"
26#include "dsputil_mmx.c"
6fea8454 27
f3ab6d91
RB
28#include "fdct_mmx.c"
29#include "idct_mmx.c"
30#include "motion_est_mmx.c"
31#include "simple_idct_mmx.c"
32#include "dsputil.c"
33#include "simple_idct.c"
34#include "jfdctfst.c"
6fea8454 35
ec9a41f5
ZK
36#undef TESTCPU_MAIN
37
38#define PAD 0x10000
39/*
40 * for testing speed of various routine - should be probably extended
41 * for a general purpose regression test later
42 *
43 * currently only for i386 - FIXME
44 */
9e8098e7
ZK
45
46#define PIX_FUNC_C(a) \
47 { #a "_c", a ## _c, 0 }, \
48 { #a "_mmx", a ## _mmx, MM_MMX }, \
49 { #a "_mmx2", a ## _mmx2, MM_MMXEXT | PAD }
50
51#define PIX_FUNC(a) \
52 { #a "_mmx", a ## _mmx, MM_MMX }, \
53 { #a "_3dnow", a ## _3dnow, MM_3DNOW }, \
54 { #a "_mmx2", a ## _mmx2, MM_MMXEXT | PAD }
55
56#define PIX_FUNC_MMX(a) \
57 { #a "_mmx", a ## _mmx, MM_MMX | PAD }
58
59/*
60 PIX_FUNC_C(pix_abs16x16),
61 PIX_FUNC_C(pix_abs16x16_x2),
62 PIX_FUNC_C(pix_abs16x16_y2),
63 PIX_FUNC_C(pix_abs16x16_xy2),
64 PIX_FUNC_C(pix_abs8x8),
65 PIX_FUNC_C(pix_abs8x8_x2),
66 PIX_FUNC_C(pix_abs8x8_y2),
67 PIX_FUNC_C(pix_abs8x8_xy2),
68*/
69
ec9a41f5
ZK
70static const struct pix_func {
71 char* name;
72 op_pixels_func func;
73 int mm_flags;
74} pix_func[] = {
ec9a41f5 75
9e8098e7 76 PIX_FUNC_MMX(put_pixels),
6fea8454
ZK
77 //PIX_FUNC_MMX(get_pixels),
78 //PIX_FUNC_MMX(put_pixels_clamped),
423d391b
ZK
79#if 1
80 PIX_FUNC(put_pixels_x2),
81 PIX_FUNC(put_pixels_y2),
9e8098e7
ZK
82 PIX_FUNC_MMX(put_pixels_xy2),
83
84 PIX_FUNC(put_no_rnd_pixels_x2),
85 PIX_FUNC(put_no_rnd_pixels_y2),
86 PIX_FUNC_MMX(put_no_rnd_pixels_xy2),
87
88 PIX_FUNC(avg_pixels),
89 PIX_FUNC(avg_pixels_x2),
90 PIX_FUNC(avg_pixels_y2),
91 PIX_FUNC(avg_pixels_xy2),
6fea8454
ZK
92
93 PIX_FUNC_MMX(avg_no_rnd_pixels),
94 PIX_FUNC_MMX(avg_no_rnd_pixels_x2),
95 PIX_FUNC_MMX(avg_no_rnd_pixels_y2),
96 PIX_FUNC_MMX(avg_no_rnd_pixels_xy2),
423d391b 97#endif
ec9a41f5
ZK
98 { 0, 0 }
99};
100
101static inline long long rdtsc()
102{
103 long long l;
104 asm volatile( "rdtsc\n\t"
bb270c08
DB
105 : "=A" (l)
106 );
ec9a41f5
ZK
107 return l;
108}
109
110static test_speed(int step)
111{
112 const struct pix_func* pix = pix_func;
113 const int linesize = 720;
114 char empty[32768];
115 char* bu =(char*)(((long)empty + 32) & ~0xf);
116
9e8098e7
ZK
117 int sum = 0;
118
ec9a41f5
ZK
119 while (pix->name)
120 {
bb270c08 121 int i;
ec9a41f5
ZK
122 uint64_t te, ts;
123 op_pixels_func func = pix->func;
bb270c08
DB
124 char* im = bu;
125
126 if (pix->mm_flags & mm_flags)
127 {
128 printf("%30s... ", pix->name);
129 fflush(stdout);
130 ts = rdtsc();
131 for(i=0; i<100000; i++){
132 func(im, im + 1000, linesize, 16);
133 im += step;
134 if (im > bu + 20000)
135 im = bu;
136 }
137 te = rdtsc();
138 emms();
139 printf("% 9d\n", (int)(te - ts));
140 sum += (te - ts) / 100000;
141 if (pix->mm_flags & PAD)
142 puts("");
143 }
144 pix++;
ec9a41f5 145 }
9e8098e7
ZK
146
147 printf("Total sum: %d\n", sum);
ec9a41f5
ZK
148}
149
150int main(int argc, char* argv[])
151{
152 int step = 16;
153
154 if (argc > 1)
155 {
156 // something simple for now
bb270c08
DB
157 if (argc > 2 && (strcmp("-s", argv[1]) == 0
158 || strcmp("-step", argv[1]) == 0))
ec9a41f5
ZK
159 step = atoi(argv[2]);
160 }
161
162 mm_flags = mm_support();
b6fee9b6 163 printf("%s: detected CPU flags:", argv[0]);
ec9a41f5
ZK
164 if (mm_flags & MM_MMX)
165 printf(" mmx");
166 if (mm_flags & MM_MMXEXT)
167 printf(" mmxext");
168 if (mm_flags & MM_3DNOW)
169 printf(" 3dnow");
170 if (mm_flags & MM_SSE)
171 printf(" sse");
172 if (mm_flags & MM_SSE2)
173 printf(" sse2");
174 printf("\n");
175
176 printf("Using step: %d\n", step);
177 test_speed(step);
178}