Pipeline 1

download Pipeline 1

of 19

Transcript of Pipeline 1

  • 8/3/2019 Pipeline 1

    1/19

    1

    Pipelining

  • 8/3/2019 Pipeline 1

    2/19

    2

    Pipelining

    Cycle

    F

    Instruction

    R X M W

    F R X M W

    F R X M W

    F R X M W

    F R X M

    F R X

    1 2 3....

  • 8/3/2019 Pipeline 1

    3/19

  • 8/3/2019 Pipeline 1

    4/19

    4

    Reservation Table for a Simple Pipeline

    1 2 3 4 5

    I-MEM X

    REGS-R X

    ALU X

    D-MEM X

    REGS-W X

    CYCLE

    I-Mem

    A DO

    RegFile

    RW

    D-Mem

    A DO

    DI

    IR

    IR

    B

    AC

    D

    IR IR

    E

    +4 PC PC

  • 8/3/2019 Pipeline 1

    5/19

    5

    Single Cycle, Multiple Cycle, vs. Pipeline

    ClkCycle 1

    Ifetch Reg Exec Mem Wr

    Cycle 2 Cycle 3 Cycle 4 Cycle 5 Cycle 6 Cycle 7 Cycle 8 Cycle 9 Cycle 10

    Load Ifetch Reg Exec Mem Wr

    Ifetch Reg Exec Mem

    Load Store

    Ifetch Reg Exec Mem WrStore

    Clk

    Load Store Waste

    Ifetch

    R-type

    Ifetch Reg Exec Mem WrR-type

    Cycle 1 Cycle 2

    Multiple Cycle Implementation:

    Pipeline Implementation:

    Single Cycle Implementation:

    Slide courtesy of D. Patterson

  • 8/3/2019 Pipeline 1

    6/19

    6

    Why Pipeline?

    Suppose we execute 100 instructions Single Cycle Machine

    45 ns/cycle x 1 CPI x 100 inst = 4500 ns

    Multicycle Machine

    10 ns/cycle x 4.6 CPI (due to inst mix) x 100 inst = 4600 ns Ideal pipelined machine

    10 ns/cycle x (1 CPI x 100 inst + 4 cycle drain) = 1040 ns

    Slide courtesy of D. Patterson

  • 8/3/2019 Pipeline 1

    7/19

    7

    Why Pipeline? Because the resources are there!

    I

    n

    s

    t

    r.

    O

    r

    d

    e

    r

    Time (clock cycles)

    Inst 0

    Inst 1

    Inst 2

    Inst 4

    Inst 3

    ALUIm Reg Dm Reg

    ALUIm Reg Dm Reg

    ALUIm Reg Dm Reg

    A

    LUIm Reg Dm Reg

    ALUIm Reg Dm Reg

    Slide courtesy of D. Patterson

  • 8/3/2019 Pipeline 1

    8/19

    8

    Benefits of Pipelining

    Before pipelining: Throughput: 1 instruction per cycle

    (or lower cycle time and CPI=5)

    After pipelining (multiple instructions in pipe at one time) Throughput: 1 instruction per cycle

    WMXRFclktttttt !

    latchWMXRFclkttttttt ! ),,,,max(

  • 8/3/2019 Pipeline 1

    9/19

    9

    Pipelining Rules

    Forward travelling signals at each stage arelatched

    Only perform logic on signals in the same stage signal labeling useful to prevent errors,

    e.g., IR

    R, IR

    A, IR

    M, IR

    W

    Backward travelling signals at each stagerepresent hazards

  • 8/3/2019 Pipeline 1

    10/19

    10

    Pipeline Hazards

    Data hazards an instruction uses the result of a previous instruction (RAW)

    ADD R1, R2, R3 or SW R1, 3(R2)ADD R4, R1, R5 LW R3, 3(R2)

    Control hazards

    the location of an instruction depends on a previous instructionJMP LOOP

    LOOP: ADD R1, R2, R3

    Structural hazards two instructions need access to the same resource

    e.g., single memory shared for instruction fetch andload/store

    collision in reservation table

  • 8/3/2019 Pipeline 1

    11/19

    11

    Data Hazards (RAW)

    Cycle

    F

    Instruction

    R X M W

    F R X M W

    Write Data to R1 Here

    Read from R1 HereADD R1, R2, R3

    ADD R4, R1, R5

  • 8/3/2019 Pipeline 1

    12/19

  • 8/3/2019 Pipeline 1

    13/19

    13

    Control Hazards

    Cycle

    F

    Instruction

    R X M W

    F R X M W

    Destination Available Here

    Need Destination HereJR R25

    ...

    XX: ADD ...

  • 8/3/2019 Pipeline 1

    14/19

    14

    Resolving Hazards: Pipeline Stalls

    Can resolve any type of hazard data, control, or structural

    Detect the hazard

    Freeze the pipeline up to the dependent stage

    until the hazard is resolved

  • 8/3/2019 Pipeline 1

    15/19

    15

    Example Pipeline Stall (Diagram)

    Cycle

    F

    Instruction

    R X M W

    F R X M W

    Write Data to R1 Here

    Read from R1 Here

    ADD R1, R2, R3

    ADD R4, R1, R5

    Bubble

  • 8/3/2019 Pipeline 1

    16/19

    16

    Resolving Hazards: Bypass (Forwarding)

    If data is available elsewhere in the pipeline,there is no need to stall

    Detect condition

    Bypass (or forward) data directly to the

    consuming pipeline stage Bypass eliminates stalls for single-cycle operations

    reduces longest stall to N-1 cycles for N-cycleoperations

  • 8/3/2019 Pipeline 1

    17/19

    17

    Simple Pipeline with Bypass Multiplexers

    I-Mem

    A DO

    Reg

    File

    RW

    D-Mem

    A DO

    DI

    IR

    IR

    B

    AC

    D

    IR IR

    E

    +4 IP IP

  • 8/3/2019 Pipeline 1

    18/19

    18

    Data Hazards With Bypassing

    Cycle

    F

    I

    nstruction

    R X M W

    F R X M W

    R1 computed

    R1 used

    ADD R1, R2, R3

    ADD R4, R1, R5

    SUB R5, R1, R6

    XOR R7, R8, R1

    F R X M W

    F R X M W

    ADD

    SUB

    XOR

  • 8/3/2019 Pipeline 1

    19/19

    19

    Summary

    Pipelining principles Hazards

    Hazard prevention