We now examine in detail how the basic pipeline CPU executes the load instruction.
|
Dest Reg P OpCode I Src Reg1 Src Reg2 +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ | 0 | 1 | D | D | D | x | 0 | Op| Op| x | S | S | S | R | R | R | +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ OpCode P: (1 update PSR, 0 do not) ----------------------- I: (1 use Src 2 as constant, 0 reg num) 0 0 Add 0 1 Subtract 1 0 AND 1 1 OR |
Example:
Dest Reg P OpCode I Src Reg1 Src Reg2 +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ | 0 | 1 | 1 | 1 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 1 | 1 | 0 | 1 | 0 | +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ ===> ldr r6,[r3 - r2] (Load content of memory address R3-R2 into reg R6) |
ldr r1, [r2 + r3] (Load data from memory addr R2+R3 into reg R1) |
Execution:
|
Slideshow:
|
|
|
|
There are many situations that can cause stalling
That means that the stall signal is computed to represent all the stalling events
We must find all possible conflict situations and form the stall signal for each conflicting situation.
In this example, you see that first situation where you need to stall:
If ( MEM stage contains a "ldr" instruction ) then Stall IF stage |
We will learn about other conflicting situations very soon (STORE instruction)....
Graphical representation of the stall situation:
|
In this example, I will assume that:
|
Later, you will see that you may also need to stall the EX stage when the MEM stage contains a LOAD instruction....
|
Solution:
|
|
Note: I omit this Mux in many of the figures for simplicity. You must assume that the mux is inside the IF stage in all figures
(So the value R2 + R3) in ALUo1 is not used in a LOAD instruction !!)
Result of the execution of ldr r1,[r2+r3] is:
/home/cs3550001/demo/pipeline/2-ld-instr Executes the following instructions: 10 65 // mov r1, #65 18 10 // mov r2, #10 26 22 // mov r3, #22 34 1 // mov r4, #1 42 8 // mov r5, #8 58 2 // mov r7, #2 0 0 // nop 0 0 // nop 0 0 // nop 0 0 // nop 0 0 // nop 72 19 // ldr r1,[r2+r3] ( R1=memorylocation[R2+R3] ) 0 1 0 1 // Used to show "NOP insertion" by IF stage 0 1 0 1 0 0 0 0 .... 32: 255 254 (11111111 11111110) <--- data loaded into R1) |