6 Replies Latest reply on Jun 24, 2013 10:58 PM by himanshu.gautam

    Cannot do the math: what is the number of cycle needed in a branch.

    cocular

      In APP guide, there is a code snippet:

      if (A>B) {
      C += D;
      } else {
      C -= D;
      }
      
      

      It says that

      In the first block of code, this translates into an IF/ELSE/ENDIF sequence of
      conditional code, each taking ~8 cycles. If divergent, this code executes in
      ~36 clocks; otherwise, in ~28 clocks. A branch not taken costs four cycles
      (one instruction slot); a branch taken adds four slots of latency to fetch
      instructions from the instruction cache, for a total of 16 clocks. Since the
      execution mask is saved, then modified, then restored for the branch, ~12
      clocks are added when divergent, ~8 clocks when not.
      

       

      Anyway I cannot get 36 or 28……  How many cycles each line takes in both case?