ffmpeg / tests / dsptest.c @ 5509bffa
History | View | Annotate | Download (4.55 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
18 |
*/
|
19 |
#define TESTCPU_MAIN
|
20 |
#include "avcodec.h" |
21 |
#include "dsputil.h" |
22 |
#include "mpegvideo.h" |
23 |
#include "mpeg12data.h" |
24 |
#include "mpeg4data.h" |
25 |
#include "../libavcodec/i386/cputest.c" |
26 |
#include "../libavcodec/i386/dsputil_mmx.c" |
27 |
|
28 |
#include "../libavcodec/i386/fdct_mmx.c" |
29 |
#include "../libavcodec/i386/idct_mmx.c" |
30 |
#include "../libavcodec/i386/motion_est_mmx.c" |
31 |
#include "../libavcodec/i386/simple_idct_mmx.c" |
32 |
#include "../libavcodec/dsputil.c" |
33 |
#include "../libavcodec/simple_idct.c" |
34 |
#include "../libavcodec/jfdctfst.c" |
35 |
|
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 |
*/
|
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 |
|
70 |
static const struct pix_func { |
71 |
char* name;
|
72 |
op_pixels_func func; |
73 |
int mm_flags;
|
74 |
} pix_func[] = { |
75 |
|
76 |
PIX_FUNC_MMX(put_pixels), |
77 |
//PIX_FUNC_MMX(get_pixels),
|
78 |
//PIX_FUNC_MMX(put_pixels_clamped),
|
79 |
#if 1 |
80 |
PIX_FUNC(put_pixels_x2), |
81 |
PIX_FUNC(put_pixels_y2), |
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), |
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), |
97 |
#endif
|
98 |
{ 0, 0 } |
99 |
}; |
100 |
|
101 |
static inline long long rdtsc() |
102 |
{ |
103 |
long long l; |
104 |
asm volatile( "rdtsc\n\t" |
105 |
: "=A" (l)
|
106 |
); |
107 |
return l;
|
108 |
} |
109 |
|
110 |
static 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 |
|
117 |
int sum = 0; |
118 |
|
119 |
while (pix->name)
|
120 |
{ |
121 |
int i;
|
122 |
uint64_t te, ts; |
123 |
op_pixels_func func = pix->func; |
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++; |
145 |
} |
146 |
|
147 |
printf("Total sum: %d\n", sum);
|
148 |
} |
149 |
|
150 |
int main(int argc, char* argv[]) |
151 |
{ |
152 |
int step = 16; |
153 |
|
154 |
if (argc > 1) |
155 |
{ |
156 |
// something simple for now
|
157 |
if (argc > 2 && (strcmp("-s", argv[1]) == 0 |
158 |
|| strcmp("-step", argv[1]) == 0)) |
159 |
step = atoi(argv[2]);
|
160 |
} |
161 |
|
162 |
mm_flags = mm_support(); |
163 |
printf("%s: detected CPU flags:", argv[0]); |
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 |
} |