Presentation is loading. Please wait.

Presentation is loading. Please wait.

\course\cpeg323-08F\Topic6b-323

Similar presentations


Presentation on theme: "\course\cpeg323-08F\Topic6b-323"— Presentation transcript:

1 \course\cpeg323-08F\Topic6b-323
Pipeline Control 2018/9/18 \course\cpeg323-08F\Topic6b-323

2 \course\cpeg323-08F\Topic6b-323
Assumptions PC is updated at each cycle. Pipeline registers are also updated at each cycle. Only need to set control values during each pipeline stage. 2018/9/18 \course\cpeg323-08F\Topic6b-323

3 \course\cpeg323-08F\Topic6b-323
Control lines See P&H Fig rd Ed. or th Ed. 2018/9/18 \course\cpeg323-08F\Topic6b-323

4 Five Groups of Control Lines
Instruction Fetch: The control signals to read instruction memory and to write the PC are always asserted, so there is nothing special to control in this pipeline stage. Instruction Decode/Register Fetch: As in the previous stage, the same thing happens at every clock cycle, so there are no optional control lines to set. Execution: The signals to be set are RegDst, ALUOp, and ALUSrc. The signals select the Result register, the ALU operation, and either a register or a sign-extended immediate for the ALU. 2018/9/18 \course\cpeg323-08F\Topic6b-323

5 Five Groups of Control Lines
(Cont’d) Memory Stage: The control lines set in this stage are Branch, MemRead, and MemWrite. These signals are set by the branch equal, load, and store instructions, respectively. Write Back: The two control lines are MemtoReg, which decides between sending the ALU result or the memory value to the registers, and RegWrite, which writes the chosen value. 2018/9/18 \course\cpeg323-08F\Topic6b-323

6 \course\cpeg323-08F\Topic6b-323
ALU control input See P&H Fig rd Ed or th Ed ALU control bits are set depending on the ALUOp and the different function codes for the R-type instruction. 2018/9/18 \course\cpeg323-08F\Topic6b-323

7 \course\cpeg323-08F\Topic6b-323
Function of control lines See P&H Fig rd Ed or th Ed 2018/9/18 \course\cpeg323-08F\Topic6b-323

8 \course\cpeg323-08F\Topic6b-323
Value of control lines See P&H Fig rd Ed or th Ed ALU control bits are set depending on the ALUOp and the different function codes for the R-type instruction. 2018/9/18 \course\cpeg323-08F\Topic6b-323

9 \course\cpeg323-08F\Topic6b-323
Control Lines for the Final Three Stages See P&H Fig rd Ed or th Ed 2018/9/18 \course\cpeg323-08F\Topic6b-323

10 \course\cpeg323-08F\Topic6b-323
Pipelined Datapath with control signals See P&H Fig rd Ed or th Ed The control values for the last three stages are created during the instruction decode stage and then placed in the ID/EX pipeline register. The control lines for each pipe stage are used, and remaining control lines are then passed to the next pipeline stage. 2018/9/18 \course\cpeg323-08F\Topic6b-323

11 Hazards and Hazards Resolution
Hazards detection Hazards resolution 2018/9/18 \course\cpeg323-08F\Topic6b-323

12 \course\cpeg323-08F\Topic6b-323
(cont’d) Hazards Situations that prevent the next instruction in the instruction stream to be executed at the designated clock cycle. 2018/9/18 \course\cpeg323-08F\Topic6b-323

13 Hazards (structral and data)
(cont’d) Hazards (structral and data) Structural: Resource conflicts when hardware cannot support all possible combinations of instructions in simultaneous overlapped execution. Data: Instructions depend on the results of a previous instruction in a way that is exposed by the overlapping execution. 2018/9/18 \course\cpeg323-08F\Topic6b-323

14 \course\cpeg323-08F\Topic6b-323
(cont’d) Hazards (control) Control: Due to branches and other instructions that change PC. Hazard will cause “stall”, but in pipeline “stall” is serious - it will hold multiple instructions. It stalls later instructions, not earlier instructions. 2018/9/18 \course\cpeg323-08F\Topic6b-323

15 \course\cpeg323-08F\Topic6b-323
Hazards (cont’d) Structural Hazards Non-pipelined FUs One port of a R-file One port of M. Othes ? Data hazards for some data hazards ( e.g. ALU/ALU ops): forwards (bypass) 2018/9/18 \course\cpeg323-08F\Topic6b-323

16 \course\cpeg323-08F\Topic6b-323
Data Hazards (cont’d) for others: pipeline interlock + pipeline stall (bypass cannot do on time) Lw $t1, 0(t3) Add $t4, $t1, $t5 This may need a “stall” or bubble 2018/9/18 \course\cpeg323-08F\Topic6b-323

17 Example of Structural Hazard
A pipeline stalled for a structural hazard-a load with one memory port. With only one memory port, the pipeline cannot initiate a data fetch and instruction fetch in the same cycle. A load instruction effectively steals an instructin-fetch cycle, causing the pipeline to stall - no instruction is initiated on clock cycle 4 (which normally would be instruction i+3). Because the instruction being fetched is stalled, all other instructions in the pipeline can proceed normally. The stall cycle will continue to pass through the pipeline. 2018/9/18 \course\cpeg323-08F\Topic6b-323

18 Why ALUOUTPUT has a “1” in IF?
PC IF ID EX MEM WB M R a ALU op IF ID EX MEM WB PC Unit R ALU ALU OUTPUT M Why ALUOUTPUT has a “1” in IF? 2018/9/18 \course\cpeg323-08F\Topic6b-323

19 \course\cpeg323-08F\Topic6b-323
Data hazard example See P&H Fig rd Ed or th Ed Pipelined dependencies in a five-instruction sequence using simplified datapaths to show the dependencies. 2018/9/18 \course\cpeg323-08F\Topic6b-323

20 \course\cpeg323-08F\Topic6b-323
The dependencies between the pipeline registers move forward in time, so it is possible to supply the inputs to the ALU needed by the AND instruction and OR instruction by forwarding the results found in the pipeline registers. See P&H Fig rd Ed or th Ed 2018/9/18 \course\cpeg323-08F\Topic6b-323

21 Data Hazard Resolution
Software method Architecture features 2018/9/18 \course\cpeg323-08F\Topic6b-323

22 \course\cpeg323-08F\Topic6b-323
Flow Dependency (R/W conflicts) A B + C . E A + D 2018/9/18 \course\cpeg323-08F\Topic6b-323

23 \course\cpeg323-08F\Topic6b-323
Output Dependency (W/W conflicts) A B + C . A B - C Leave A in wrong state if order is changed 2018/9/18 \course\cpeg323-08F\Topic6b-323

24 \course\cpeg323-08F\Topic6b-323
Anti Dependency (W/R conflicts) X A + B . A C + D 2018/9/18 \course\cpeg323-08F\Topic6b-323

25 \course\cpeg323-08F\Topic6b-323
How about arrays? . A [i] = = A[i-1]+… RAW (read after write) - j tries to read a source before i writes it, so j incorrectly gets the old value. This is the most common type of hazard. WAR (write after read) - j tries to write a destination before it is read by i, so i incorrectly gets the new value. This cannot happen in our example pipeline because all reads are early (in ID) and all writes are late (in WB). This hazard occurs when there are some instructions that write results early in the instruction pipeline, and other instructions that read a source after a write of an instruction later in the pipeline. For example, autoincrement addressing can create a WAR hazard. WAW (write after write) - j tries to write an operand before it is written by i. The writes end up being performed in the wrong order, leaving the value written by i rather than the value written by j in the destination. This hazard is present only in pipelines that write in more than one pipe stage (or allow an instruction to proceed even when a previous instruction is stalled). The DLX pipeline writes a register only in WB and avoids this class of hazards. 2018/9/18 \course\cpeg323-08F\Topic6b-323

26 \course\cpeg323-08F\Topic6b-323
Data Dependence j i MIPS Read / Read Write / Write no Read / Write yes Write / Read no “Shared Datum” conflicts This case is different from the situation with back-to-back ALU operations. The LW instructioan does not have the data until the end of the MEM cycle., while the ADD instruction needs to have the data by the beginning of that clock cycle. Thus, the data hazard from using the result of a load instruction cannot be completely eliminated with simple hardware. We can forward the result immediately to the ALU from the MDR and for the SUB instruction - which begins two clock cycles after the load - the result arrives in time, as shown in ?. However, for the ADD instruction, the forwarded result arrives too late - at the end of a clock cycle though it is needed at the beginning. LW R1, 32 (R6) IF ID EX MEM WB ADD R4, R1, R IF ID EX MEM SUB R5, R1, R IF ID EX AND R6, R1, R IF ID Pipeline hazard occurring when the result of a load instruction is used by the next instruction as a source operand and is forwarded. The value is avaiable when it returns from memory at the end of the load instructions’s MEM cycle. However, it is needed at the beginning of that clock cycle for the ADD (the EX stage of the add). The load value can be forwarded to the SUB instruction and will arrive in time for that instruction (EX). The AND can simply read the value during ID since it reads the registers in the second half of the cycle and the value is written in the first half. 2018/9/18 \course\cpeg323-08F\Topic6b-323

27 \course\cpeg323-08F\Topic6b-323
Data Dependence S1 S2 S3 S4 o Flow-dependence Output-dependence Anti-dependence S1: $R1 = $R2 + 1 S2: $R3 = $R1 + $R4 S3: $R4 = $R1 – 2 S4: $R3 = 2 Dependences: S1, S2  flow-dependence S1, S3  flow-dependence S2, S3  anti-dependence S2, S4  output-dependence 2018/9/18 \course\cpeg323-08F\Topic6b-323


Download ppt "\course\cpeg323-08F\Topic6b-323"

Similar presentations


Ads by Google