I was solving some problems on number of clocks required in pipelining. However I came across this problem, Consider the sequence of machine instruction given below:

MUL R5,R0,R1 DIV R6,R2,R3 ADD R7,R5,R6 SUB R8,R7,R4 In the above sequence, R0 to R8 are general purpose registers. In the instructions shown, the first register shows the result of the operation performed on the second and the third registers. This sequence of instructions is to be executed in a pipelined instruction processor with the following 4 stages: (1) Instruction Fetch and Decode (IF), (2) Operand Fetch (OF), (3) Perform Operation (PO) and (4) Write back the result (WB). The IF, OF and WB stages take 1 clock cycle each for any instruction. The PO stage takes 1 clock cycle for ADD and SUB instruction, 3 clock cycles for MUL instruction and 5 clock cycles for DIV instruction. The pipelined processor uses operand forwarding from the PO stage to the OF stage. The number of clock cycles taken for the execution of the above sequence of instruction is _________.

I got the answer as 15 however the correct answer is 13. Am I doing something wrong or is the answer key at fault? The link for reference: https://gateoverflow.in/8218/gate2015-2-44


Note the sentence "The pipelined processor uses operand forwarding from the PO stage to the OF stage". That means if a result is written at cycle n, the same result can be read as an operand at the same cycle n. This happens twice in your instruction sequence. If you ignore this, your count will be too high by two.

  • $\begingroup$ could you please give me a solution so I could understand it better? $\endgroup$ – Anonymous Developer Dec 24 '18 at 22:12
  • $\begingroup$ Did you understand what "operand forwarding from the PO stage to the OF stage" means? $\endgroup$ – gnasher729 Dec 24 '18 at 22:48
  • $\begingroup$ yes I am aware of the concept of operator forwarding but wouldn't that mean: OF can execute as soon as PO is over? $\endgroup$ – Anonymous Developer Dec 24 '18 at 22:54
  • $\begingroup$ OF can execute as soon as PO is over even without operator forwarding. Operator forwarding means that in the same cycle, the data can be sent both to the register where it should be stored, AND to the operand that needs it. We are taking a shortcut, that in this case saves 2 of 15 cycles; about 15% more performance. $\endgroup$ – gnasher729 Dec 25 '18 at 14:45
  • $\begingroup$ Alright now I understand why my answer was coming all wrong. Anyway if it was just mentioned that operating forwarding is used (not specifically mentioning that between PO and OF) would we still consider that it is possible to jump from PO to OF? $\endgroup$ – Anonymous Developer Dec 25 '18 at 15:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.