daily pastebin goal
16%
SHARE
TWEET

arch_lab1_c

a guest Sep 25th, 2018 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <stdint.h>
  3.  
  4. #define ITERATIONS 25000000LL
  5.  
  6. union ticks
  7. {
  8.     uint64_t t64;
  9.     struct s32
  10.     {
  11.         uint32_t th,tl;
  12.     } t32;
  13. };
  14.  
  15. uint64_t commands_per_tick = 16;
  16.  
  17. int main() {
  18.     union ticks start, end;
  19.  
  20.     __asm__ __volatile__(
  21.         "xor %rax, %rax\n\t"
  22.         "movb $2, %al\n\t"
  23.         "cvtsi2sd %rax, %xmm0\n\t"
  24.         "xor %rax, %rax\n\t"
  25.         "movb $2, %al\n\t"
  26.         "cvtsi2sd %rax, %xmm1\n\t"
  27.         "xor %rax, %rax\n\t"
  28.         "movb $2, %al\n\t"
  29.         "cvtsi2sd %rax, %xmm2\n\t"
  30.         "xor %rax, %rax\n\t"
  31.         "movb $2, %al\n\t"
  32.         "cvtsi2sd %rax, %xmm3\n\t"
  33.         "xor %rax, %rax\n\t"
  34.         "movb $2, %al\n\t"
  35.         "cvtsi2sd %rax, %xmm4\n\t"
  36.         "xor %rax, %rax\n\t"
  37.         "movb $2, %al\n\t"
  38.         "cvtsi2sd %rax, %xmm5\n\t"
  39.         "xor %rax, %rax\n\t"
  40.         "movb $2, %al\n\t"
  41.         "cvtsi2sd %rax, %xmm6\n\t"
  42.         "xor %rax, %rax\n\t"
  43.         "movb $2, %al\n\t"
  44.         "cvtsi2sd %rax, %xmm7\n\t"
  45.         "xor %rax, %rax\n\t"
  46.         "movb $2, %al\n\t"
  47.         "cvtsi2sd %rax, %xmm8\n\t"
  48.         "xor %rax, %rax\n\t"
  49.         "movb $2, %al\n\t"
  50.         "cvtsi2sd %rax, %xmm9\n\t"
  51.         "xor %rax, %rax\n\t"
  52.         "movb $2, %al\n\t"
  53.         "cvtsi2sd %rax, %xmm10\n\t"
  54.         "xor %rax, %rax\n\t"
  55.         "movb $2, %al\n\t"
  56.         "cvtsi2sd %rax, %xmm11\n\t"
  57.         "xor %rax, %rax\n\t"
  58.         "movb $2, %al\n\t"
  59.         "cvtsi2sd %rax, %xmm12\n\t"
  60.         "xor %rax, %rax\n\t"
  61.         "movb $2, %al\n\t"
  62.         "cvtsi2sd %rax, %xmm13\n\t"
  63.         "xor %rax, %rax\n\t"
  64.         "movb $2, %al\n\t"
  65.         "cvtsi2sd %rax, %xmm14\n\t"
  66.         "xor %rax, %rax\n\t"
  67.         "movb $2, %al\n\t"
  68.         "cvtsi2sd %rax, %xmm15\n\t"
  69.     );
  70.  
  71.     for (uint64_t i = commands_per_tick * ITERATIONS; i > 0; --i) {
  72.         __asm__ __volatile__(
  73.             "sqrtsd %xmm0, %xmm0\n\t"
  74.         );
  75.     }
  76.  
  77.     asm("rdtsc\n\t":"=a"(end.t32.th),"=d"(end.t32.tl));
  78.  
  79.     uint64_t result = end.t64-start.t64;
  80.     printf("Tacts taken: %lu for %llu commands\n", result, commands_per_tick * ITERATIONS);
  81.     printf("%lf for each\n", (result + 0.0) / (commands_per_tick * ITERATIONS));
  82.  
  83.     for (uint64_t i = ITERATIONS; i > 0; --i) {
  84.         __asm__ __volatile__(
  85.             "sqrtsd %xmm0, %xmm0\n\t"
  86.             "sqrtsd %xmm1, %xmm1\n\t"
  87.             "sqrtsd %xmm2, %xmm2\n\t"
  88.             "sqrtsd %xmm3, %xmm3\n\t"
  89.             "sqrtsd %xmm4, %xmm4\n\t"
  90.             "sqrtsd %xmm5, %xmm5\n\t"
  91.             "sqrtsd %xmm6, %xmm6\n\t"
  92.             "sqrtsd %xmm7, %xmm7\n\t"
  93.             "sqrtsd %xmm8, %xmm8\n\t"
  94.             "sqrtsd %xmm9, %xmm9\n\t"
  95.             "sqrtsd %xmm10, %xmm10\n\t"
  96.             "sqrtsd %xmm11, %xmm11\n\t"
  97.             "sqrtsd %xmm12, %xmm12\n\t"
  98.             "sqrtsd %xmm13, %xmm13\n\t"
  99.             "sqrtsd %xmm14, %xmm14\n\t"
  100.             "sqrtsd %xmm15, %xmm15\n\t"
  101.         );
  102.     }
  103.  
  104.     asm("rdtsc\n\t":"=a"(start.t32.th),"=d"(start.t32.tl));
  105.     for (uint64_t i = ITERATIONS; i > 0; --i) {
  106.         __asm__ __volatile__(
  107.             "sqrtsd %xmm0, %xmm0\n\t"
  108.             "sqrtsd %xmm1, %xmm1\n\t"
  109.             "sqrtsd %xmm2, %xmm2\n\t"
  110.             "sqrtsd %xmm3, %xmm3\n\t"
  111.             "sqrtsd %xmm4, %xmm4\n\t"
  112.             "sqrtsd %xmm5, %xmm5\n\t"
  113.             "sqrtsd %xmm6, %xmm6\n\t"
  114.             "sqrtsd %xmm7, %xmm7\n\t"
  115.             "sqrtsd %xmm8, %xmm8\n\t"
  116.             "sqrtsd %xmm9, %xmm9\n\t"
  117.             "sqrtsd %xmm10, %xmm10\n\t"
  118.             "sqrtsd %xmm11, %xmm11\n\t"
  119.             "sqrtsd %xmm12, %xmm12\n\t"
  120.             "sqrtsd %xmm13, %xmm13\n\t"
  121.             "sqrtsd %xmm14, %xmm14\n\t"
  122.             "sqrtsd %xmm15, %xmm15\n\t"
  123.         );
  124.     }
  125.  
  126.     asm("rdtsc\n\t":"=a"(end.t32.th),"=d"(end.t32.tl));
  127.  
  128.     result = end.t64-start.t64;
  129.     printf("Tacts taken: %lu for %llu commands\n", result, (16*ITERATIONS));
  130.     printf("%lf for each\n", (result + 0.0) / (16*ITERATIONS));
  131.  
  132.  
  133.     return 0;
  134.  
  135. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top