Sunday, May 11, 2014

ARM Processors : In-order execution versus Out-of-order execution

Every program code gets converted into its corresponding machine language instructions. In-order and Out-of-order differs in the way these instructions gets executed by processor. The below examples are with respect to ARM processor.

Consider the below instructions (r0 ~ r6 are registers):
1) mov r0, #3    // Moves value 3 to register r0
2) mov r1, #5    // Moves value 5 to register r1
3) mov r2, #6    // Moves value 5 to register r2
4) add r4, r1, r2  // Adds contents of r1 and r2 and stores in r4
5) add r5, r0, r0  // Adds contents of r0 and r0 and stores in r5.  ie r5 = 2*r0
6) add r6, r1, r3  // Adds contents of r2 and r3 and stores in r6

Imagine that processor can execute two instructions in a cycle.

In-order execution :
Instructions will be executed as 
Cycle 1:  Instruction_1 + Instruction_2 (because both instructions does not have dependency with each other)

Cycle 2:  Instruction_3 only (Instruction 4 is not executed, because result of 4, depends on r2 which gets updated in Instruction_3 )

Cycle 3: Instruction_4 + Instruction_5 (because both instructions does not have dependency with each other)

Cycle 4: Instruction_6

Total cycles consumed is 4.

Out-of-order execution:
Instructions will be executed as 
Cycle 1:  Instruction_1 + Instruction_2 (because both instructions does not have dependency with each other)

Cycle 2:  Instruction_3 + Instruction_5 (because both instructions does not have dependency with each other)

Cycle 3:  Instruction_4 + Instruction_6 (because both instructions does not have dependency with each other)

Total cycles consumed is 3.


Summary

No comments:

Post a Comment