Consider a 4 stage pipeline processor. The number of cycles needed by the four instructions I1, I2, I3, I4 in stages S1, S2, S3, S4 is shown below:
S1

S2

S3

S4


I1

2

1

1

1

I2

1

3

2

2

I3

2

1

1

3

I4

1

2

2

2

What is the number of cycles needed to execute the following loop?
For (i=1 to 2) {I1; I2; I3; I4;}
(A) 16
(B) 23
(C) 28
(D) 30
Answer: (B)
Explanation: This question is different from other questions on pipeline with respect to the no of cycles taken by each instruction in each stage, i.e. an instruction here may take different no of cycles in different stages, and also that two instructions may take different no of cycles in the same stage as well.
Therefore, here we have to consider two things : 1) Eligibility 2) Availability
i.e. an instruction i should be eligible to be given to stage j, and a stage j should be available(free) to handle/process instruction i.
Now, let’s see how both the above things can be achieved.
An instruction i will be eligible to be given to stage j, if and only if, the instruction i has completed stage j1.
Similarly, a Stage j will be available for instruction i, if and only if, the Stage j has completed instruction i1.
So, by following and fulfilling above two criteria we have to determine the total no of cycles taken by these instructions in a loop of 2 iterations.
Note: An instruction i will be eligible for processing in iteration 2, if and only if, it has completed its processing in iteration 1.