Why did it took so long to branch ???
 

Understand the branch delay:

  • The branch instruction must first compute the branch destination address:

       Branch destination address = PC + offset     
      

  • Only then, the CPU can update the PC with the new value (PC + offset) to execute a branch instruction

  • The cause of a long delay:

      • The operation PC + offset can only be performed in the 3rd stage (= EX stage) in the pipelined CPU

Can the pipelined CPU execute a branch instruction sooner in the pipeline ???
 

What do you need to execute a (any) instruction (in general):

  1. All the source operands used by the instruction

  2. The circuitry to perform the necessary operation on the source operands

What do you need to execute a (conditional/unconditional) branch instruction:

  1. The source operands used by a (conditional) branch instruction:

      1. The value in the Program Counter (PC)
      2. The offset stored in the branch instruction
      3. The value of the N,Z,V,C flags in the PSR (that is updated by the instruction before the conditional branch instruction !!!)

  2. An adder circuit to compute the value PC + offset

Can the pipelined CPU execute a branch instruction sooner in the pipeline ???

This diagram shows the information needed to execute a (conditional) branch instruction:

We must figure out how soon all the information are available.
The answer to this question will determine when a (cond) branch instruction can be executed...

Can the pipelined CPU execute a branch instruction sooner in the pipeline ???

It is obvious that the PC and the offset is available in the ID stage:

(1) Can we obtain the N,Z,V,C flag values of the compare instruction ???
(2) We must be able to add PC + offset !!!

Can the pipelined CPU execute a branch instruction sooner in the pipeline ???

The earliest pipeline stage that can execute a (any) branch instruction is the ID stage:

(1) We need an extra adder circuit to perform PC + offset
(2) The PSR must be updated in the middle of the clock period to obtain the N,Z,V,C flag values!