title: Why dependency in a loop iteration can't be executed together with the previous one
body: <p>I use this code to test the impact of dependency in a loop iteration on IvyBridge:</p>
  
  <pre><code>global _start
  _start:
      mov rcx,    1000000000
  .for_loop:          
      inc rax     ; uop A
      inc rax     ; uop B
      dec rcx     ; uop C
      jnz .for_loop   
  
      xor rdi,    rdi
      mov rax,    60  ; _exit(0)
      syscall
  </code></pre>
  
  <p>Since <code>dec</code> and <code>jnz</code> will be macro-fused to a single uop, there are 3 uops in my loop, they are labeled in the comments.</p>
  
  <p>uop B depends on uop A, so I think the execution would be like this:</p>
  
  <pre><code>A C
  B A C  ; the previous B and current A can be in the same cycle
  B A C
  ...
  B A C
  B
  </code></pre>
  
  <p>Therefore the loop can be executed 1 cycle per iter.</p>
  
  <p>However, the <code>perf</code> tool shows:</p>
  
  <pre><code> 2,009,704,779      cycles                
   1,008,054,984      stalled-cycles-frontend   #   50.16% frontend cycles idl
  </code></pre>
  
  <p>So it's 2 cycle per iter, and there are 50% frontend cycle idle.</p>
  
  <p>What caused the frontend 50% idle? Why the hypothetical execution diagram can't be realized?</p>