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 >
C/C++ Source or Header  |  1999-03-09  |  2KB  |  121 lines

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4. #include <signal.h>
  5. #include <sys/time.h>
  6.  
  7. #define ALIGNMENT            0x2000
  8. #define TIME                5
  9.  
  10. volatile int running;
  11.  
  12. void handler()
  13. {
  14.     running = 0;
  15. }
  16.  
  17. int main(int argc, char **argv)
  18. {
  19.     int size;
  20.     long *buffer;
  21.     int count;
  22.     struct itimerval tv;
  23. #if !defined(ASM) && !defined(MMX)
  24.     long *ptr;
  25.     long dummy1;
  26.     volatile long dummy2;
  27. #endif
  28.  
  29.     if (argc != 2 || !(size = atoi(argv[1]) * 1024)) return 1;
  30.     buffer = (long *)malloc(size + ALIGNMENT);
  31.     (long)buffer += ALIGNMENT - 1;
  32.     (long)buffer &= ~(ALIGNMENT - 1);
  33.  
  34.     memset(buffer, 1, size);
  35.  
  36.     running = 1;
  37.     signal(SIGVTALRM, handler);
  38.     memset(&tv, 0, sizeof(tv));
  39.     tv.it_value.tv_sec = TIME;
  40.     setitimer(ITIMER_VIRTUAL, &tv, NULL);
  41.  
  42.     count = 0;
  43.     while (running) {
  44. #if defined(ASM) || defined(MMX)
  45. #ifdef __i386__
  46. #ifdef MMX
  47.         __asm__ __volatile__ (
  48.             "movl %0,%%esi;"
  49.             "movl %1,%%ecx;"
  50.             "1:"
  51.             "movq (%%esi),%%mm0;"
  52.             "movq 32(%%esi),%%mm4;"
  53.             "movq 8(%%esi),%%mm1;"
  54.             "movq 16(%%esi),%%mm2;"
  55.             "movq 24(%%esi),%%mm3;"
  56.             "movq 40(%%esi),%%mm5;"
  57.             "movq 48(%%esi),%%mm6;"
  58.             "movq 56(%%esi),%%mm7;"
  59.             "addl $64,%%esi;"
  60.             "subl $16,%%ecx;"
  61.             "jnz 1b;"
  62.             "emms"
  63.             :
  64.             : "g" (buffer), "g" (size / sizeof(long))
  65.             : "cx", "si", "cc"
  66.         );
  67. #else
  68.         __asm__ __volatile__ (
  69.             "movl %0,%%esi;"
  70.             "movl %1,%%ecx;"
  71.             "1:"
  72.             "movl (%%esi),%%eax;"
  73.             "movl 4(%%esi),%%edx;"
  74.             "addl $8,%%esi;"
  75.             "subl $2,%%ecx;"
  76.             "jnz 1b"
  77.             :
  78.             : "g" (buffer), "g" (size / sizeof(long))
  79.             : "ax", "dx", "cx", "si", "cc"
  80.         );
  81. #endif
  82. #else
  83. #ifdef __alpha__
  84.         __asm__ __volatile__ (
  85.             "ldq $0,%0;"
  86.             "ldl $1,%1;"
  87.             "1:"
  88.             "subq $1,8,$1;"
  89.             "ldq $2,0($0);"
  90.             "ldq $6,32($0);"
  91.             "ldq $3,8($0);"
  92.             "ldq $4,16($0);"
  93.             "ldq $5,24($0);"
  94.             "ldq $7,40($0);"
  95.             "ldq $8,48($0);"
  96.             "ldq $9,56($0);"
  97.             "addq $0,64,$0;"
  98.             "bne $1,1b"
  99.             :
  100.             : "m" (buffer), "m" (size / sizeof(long))
  101.             : "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"
  102.         );
  103. #else
  104. #error Wrong architecture
  105. #endif
  106. #endif
  107. #else
  108.         dummy1 = 0;
  109.         ptr = buffer;
  110.         while (ptr < &buffer[size / sizeof(long)])
  111.             dummy1 += *ptr++;
  112.         dummy2 = dummy1;
  113. #endif
  114.         count++;
  115.     };
  116.  
  117.     printf("%.2f Mb/sec\n", (double)size * count / TIME / (1024 * 1024));
  118.  
  119.     return 0;
  120. }
  121.