home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.dataforce.net
/
2014.05.ftp.dataforce.net.tar
/
ftp.dataforce.net
/
pub
/
solar
/
membench.c
< prev
next >
Wrap
C/C++ Source or Header
|
1999-03-09
|
2KB
|
121 lines
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <signal.h>
#include <sys/time.h>
#define ALIGNMENT 0x2000
#define TIME 5
volatile int running;
void handler()
{
running = 0;
}
int main(int argc, char **argv)
{
int size;
long *buffer;
int count;
struct itimerval tv;
#if !defined(ASM) && !defined(MMX)
long *ptr;
long dummy1;
volatile long dummy2;
#endif
if (argc != 2 || !(size = atoi(argv[1]) * 1024)) return 1;
buffer = (long *)malloc(size + ALIGNMENT);
(long)buffer += ALIGNMENT - 1;
(long)buffer &= ~(ALIGNMENT - 1);
memset(buffer, 1, size);
running = 1;
signal(SIGVTALRM, handler);
memset(&tv, 0, sizeof(tv));
tv.it_value.tv_sec = TIME;
setitimer(ITIMER_VIRTUAL, &tv, NULL);
count = 0;
while (running) {
#if defined(ASM) || defined(MMX)
#ifdef __i386__
#ifdef MMX
__asm__ __volatile__ (
"movl %0,%%esi;"
"movl %1,%%ecx;"
"1:"
"movq (%%esi),%%mm0;"
"movq 32(%%esi),%%mm4;"
"movq 8(%%esi),%%mm1;"
"movq 16(%%esi),%%mm2;"
"movq 24(%%esi),%%mm3;"
"movq 40(%%esi),%%mm5;"
"movq 48(%%esi),%%mm6;"
"movq 56(%%esi),%%mm7;"
"addl $64,%%esi;"
"subl $16,%%ecx;"
"jnz 1b;"
"emms"
:
: "g" (buffer), "g" (size / sizeof(long))
: "cx", "si", "cc"
);
#else
__asm__ __volatile__ (
"movl %0,%%esi;"
"movl %1,%%ecx;"
"1:"
"movl (%%esi),%%eax;"
"movl 4(%%esi),%%edx;"
"addl $8,%%esi;"
"subl $2,%%ecx;"
"jnz 1b"
:
: "g" (buffer), "g" (size / sizeof(long))
: "ax", "dx", "cx", "si", "cc"
);
#endif
#else
#ifdef __alpha__
__asm__ __volatile__ (
"ldq $0,%0;"
"ldl $1,%1;"
"1:"
"subq $1,8,$1;"
"ldq $2,0($0);"
"ldq $6,32($0);"
"ldq $3,8($0);"
"ldq $4,16($0);"
"ldq $5,24($0);"
"ldq $7,40($0);"
"ldq $8,48($0);"
"ldq $9,56($0);"
"addq $0,64,$0;"
"bne $1,1b"
:
: "m" (buffer), "m" (size / sizeof(long))
: "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"
);
#else
#error Wrong architecture
#endif
#endif
#else
dummy1 = 0;
ptr = buffer;
while (ptr < &buffer[size / sizeof(long)])
dummy1 += *ptr++;
dummy2 = dummy1;
#endif
count++;
};
printf("%.2f Mb/sec\n", (double)size * count / TIME / (1024 * 1024));
return 0;
}