2 * benchmark tool for fast_memcpy code from libvo
4 * NOTE: This code can not be used on Pentium MMX / II because they contain
5 * a bug in rdtsc. For Intel processors since P6(PII) rdpmc should be used
6 * instead. For PIII it's disputable and it seems the bug was fixed but this
7 * was not confirmed through testing.
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 #include <sys/ioctl.h>
35 #include "cpudetect.h"
37 #define BLOCK_SIZE 4096
38 #define CONFUSION_FACTOR 0
49 #define COMPILE_AMD3DNOW
65 #define HAVE_AMD3DNOW 0
68 #define RENAME(a) a ## _MMX
69 #include "libvo/aclib_template.c"
81 #define HAVE_AMD3DNOW 0
84 #define RENAME(a) a ## _MMX2
85 #include "libvo/aclib_template.c"
88 #ifdef COMPILE_AMD3DNOW
97 #define HAVE_AMD3DNOW 1
100 #define RENAME(a) a ## _3DNow
101 #include "libvo/aclib_template.c"
113 #define HAVE_AMD3DNOW 0
116 #define RENAME(a) a ## _SSE
117 #include "libvo/aclib_template.c"
120 //#define ARR_SIZE 100000
121 #define ARR_SIZE (1024*768*2)
125 #include "drivers/mga_vid.h"
127 static mga_vid_config_t mga_vid_config
;
128 static unsigned char* frame
= NULL
;
131 static int mga_init(void)
133 f
= open("/dev/mga_vid", O_RDWR
);
135 fprintf(stderr
, "Couldn't open /dev/mga_vid.\n");
139 mga_vid_config
.num_frames
= 1;
140 mga_vid_config
.frame_size
= ARR_SIZE
;
141 mga_vid_config
.format
= MGA_VID_FORMAT_YUY2
;
143 mga_vid_config
.colkey_on
= 0;
144 mga_vid_config
.src_width
= 640;
145 mga_vid_config
.src_height
= 480;
146 mga_vid_config
.dest_width
= 320;
147 mga_vid_config
.dest_height
= 200;
148 mga_vid_config
.x_org
= 0;
149 mga_vid_config
.y_org
= 0;
151 mga_vid_config
.version
= MGA_VID_VERSION
;
152 if (ioctl(f
, MGA_VID_CONFIG
, &mga_vid_config
)) {
153 perror("Error in mga_vid_config ioctl()");
154 printf("Your mga_vid driver version is incompatible with this MPlayer version!\n");
157 ioctl(f
, MGA_VID_ON
, 0);
159 frame
= (char*)mmap(0, mga_vid_config
.frame_size
*mga_vid_config
.num_frames
,
160 PROT_WRITE
,MAP_SHARED
, f
, 0);
162 printf("Can't mmap MGA frame.\n");
167 //memset(frames[0], 0x80, mga_vid_config.frame_size*mga_vid_config.num_frames);
174 // Returns current time in microseconds
175 static unsigned int GetTimer(void)
180 gettimeofday(&tv
, &tz
);
181 //s = tv.tv_usec; s *= 0.000001; s += tv.tv_sec;
182 return tv
.tv_sec
* 1000000 + tv
.tv_usec
;
185 static inline unsigned long long int read_tsc(void)
187 unsigned long long int retval
;
188 __asm__
volatile ("rdtsc":"=A" (retval
)::"memory");
192 unsigned char __attribute__((aligned(4096)))arr1
[ARR_SIZE
], arr2
[ARR_SIZE
];
196 unsigned long long int v1
, v2
;
197 unsigned char *marr1
, *marr2
;
208 for (i
= 0; i
< ARR_SIZE
- 16; i
++)
209 marr1
[i
] = marr2
[i
] = i
;
211 #define testblock(func, name) \
214 for (i = 0; i < 100; i++) \
215 func(marr1, marr2, ARR_SIZE - 16); \
217 t = GetTimer() - t; \
218 /* ARR_SIZE*100 / (1024*1024) / (t/1000000) = ARR_SIZE*95.36743 / t */ \
219 printf(name "CPU clocks=%llu = %dus (%5.3ffps) %5.1fMB/s\n", v2-v1, t, \
220 100000000.0f / (float)t, (float)ARR_SIZE*95.36743f / (float)t);
222 testblock(memcpy
, "libc: ");
225 testblock(fast_memcpy_MMX
, "MMX: ");
229 testblock(fast_memcpy_3DNow
, "3DNow!: ");
233 testblock(fast_memcpy_MMX2
, "MMX2: ");
237 testblock(fast_memcpy_SSE
, "SSE: ");