title: Getting cpu cycles using RDTSC - why does the value of RDTSC always increase?
body: <p>I want to get the CPU cycles at a specific point. I use this function at that point:</p>
  
  <pre><code>static __inline__ unsigned long long rdtsc(void)
  {
      unsigned long long int x;
      __asm__ volatile (".byte 0x0f, 0x31" : "=A" (x));
      // broken for 64-bit builds; don't copy this code
      return x;
  }
  </code></pre>
  
  <p>(editor's note: <code>"=A"</code> is wrong for x86-64; it picks <em>either</em> RDX or RAX.    Only in 32-bit mode will it pick the EDX:EAX output you want.  See <a href="https://stackoverflow.com/questions/13772567/how-to-get-the-cpu-cycle-count-in-x86-64-from-c">How to get the CPU cycle count in x86_64 from C++?</a>.)</p>
  
  <p>The problem is that it returns always an <strong>increasing</strong> number (in every run). It's as if it is referring to the absolute time.</p>
  
  <p>Am I using the functions incorrectly?</p>