2 * MMX optimized DSP utils
3 * Copyright (c) 2000, 2001 Gerard Lantau.
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.
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.
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.
23 //#include "../libavcodec/dsputil.c"
24 #include "../libavcodec/i386/cputest.c"
25 #include "../libavcodec/i386/dsputil_mmx.c"
30 * for testing speed of various routine - should be probably extended
31 * for a general purpose regression test later
33 * currently only for i386 - FIXME
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 }
42 { #a "_mmx", a ## _mmx, MM_MMX }, \
43 { #a "_3dnow", a ## _3dnow, MM_3DNOW }, \
44 { #a "_mmx2", a ## _mmx2, MM_MMXEXT | PAD }
46 #define PIX_FUNC_MMX(a) \
47 { #a "_mmx", a ## _mmx, MM_MMX | PAD }
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),
60 static const struct pix_func {
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),
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),
76 PIX_FUNC(avg_pixels_x2),
77 PIX_FUNC(avg_pixels_y2),
78 PIX_FUNC(avg_pixels_xy2),
83 static inline long long rdtsc()
86 asm volatile( "rdtsc\n\t"
92 static test_speed(int step)
94 const struct pix_func* pix = pix_func;
95 const int linesize = 720;
97 char* bu =(char*)(((long)empty + 32) & ~0xf);
105 op_pixels_func func = pix->func;
108 if (!(pix->mm_flags & mm_flags))
111 printf("%30s... ", pix->name);
114 for(i=0; i<100000; i++){
115 func(im, im + 1000, linesize, 16);
122 printf("% 9d\n", (int)(te - ts));
123 sum += (te - ts) / 100000;
124 if (pix->mm_flags & PAD)
129 printf("Total sum: %d\n", sum);
132 int main(int argc, char* argv[])
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]);
144 mm_flags = mm_support();
145 printf("dsptest: CPU flags:");
146 if (mm_flags & MM_MMX)
148 if (mm_flags & MM_MMXEXT)
150 if (mm_flags & MM_3DNOW)
152 if (mm_flags & MM_SSE)
154 if (mm_flags & MM_SSE2)
158 printf("Using step: %d\n", step);