Docsity

Introduction to Advanced Computer Architechture, Lecture notes of Computer System Design and Architecture

Toggle sidebar
bg1
Pipelining
•Two forms of pipelining
–Instruction unit
•overlap fetch-execute cycle so that multiple instructions are being processed at
the same time, each instruction in a different portion of the fetch-execute cycle
–Operation unit
•overlap execution of ALU operations
•only useful if execution takes > 1 cycle
–e.g., floating point operations
•We will concentrate mostly on instruction unit-level
•Terms
–Stage – a portion of the pipeline that can accommodate one instruction,
the length of the pipeline is in stages
–Throughput – how often the pipeline delivers a completed instruction,
our goal is 1.0 (or less!), that is, one instruction leaves the pipeline at
the end of each clock cycle (this would give us an ideal CPI of 1.0)
–Stall – the need to postpone instructions from moving down the
pipeline, stalls are caused by hazards
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24

Partial preview of the text

Download Introduction to Advanced Computer Architechture and more Lecture notes Computer System Design and Architecture in PDF only on Docsity!

Pipelining

  • (^) Two forms of pipelining
    • (^) Instruction unit
      • (^) overlap fetch-execute cycle so that multiple instructions are being processed at the same time, each instruction in a different portion of the fetch-execute cycle
    • (^) Operation unit
      • (^) overlap execution of ALU operations
      • (^) only useful if execution takes > 1 cycle
        • (^) e.g., floating point operations
  • (^) We will concentrate mostly on instruction unit-level
  • (^) Terms
    • (^) Stage – a portion of the pipeline that can accommodate one instruction, the length of the pipeline is in stages
    • (^) Throughput – how often the pipeline delivers a completed instruction, our goal is 1.0 (or less!), that is, one instruction leaves the pipeline at the end of each clock cycle (this would give us an ideal CPI of 1.0)
    • (^) Stall – the need to postpone instructions from moving down the pipeline, stalls are caused by hazards

From Non-pipelined

to Pipelined

We add latches between stages to control when the instruction can move into the new pipe stage Latches will also contain logic which will be used to handle forwarding and insert stalls Latches are registers, Denoted as IF/ID.IR And ID/EX.A for example

Problems with the Pipeline

  • (^) Two instructions might try to alter the PC at the same time
    • (^) PC incremented in IF
    • (^) A branch instruction in EX could alter the PC
  • (^) Two instructions could attempt to access memory at the same time - (^) Instruction fetch in IF and data access in MEM - (^) We will use two separate caches to avoid this problem (instruction

cache accessed by IF stage, data cache accessed by MEM stage)

  • (^) The stages differ in the time it takes to perform their operation
    • (^) IF and MEM are the longest due to cache access time, so we have to

slow the clock speed down to this rate

  • (^) Hazards
    • (^) Covered in a bit, these result in stalls which lengthens the CPI from

an ideal CPI of 1 to something larger (1 + stalls/instruction)

Pipelined vs Non-pipelined MIPS

  • (^) Assume 1 ns (1 GHz) clock speed but the pipeline accrues an added .2 ns overhead
  • (^) Assume benchmark of
    • (^) 40% ALU, 20% branches, 40% for loads and stores
    • (^) CPI for unpipelined machine is 4 cycles for ALU and

branches and 5 for loads and stores

  • (^) How much faster is the pipelined machine assuming no stalls? - (^) Non-pipelined machine has average CPI = .40 * 5 + .60 * 4 =
  • (^) Pipelined machine has CPI = 1
  • (^) Non-pipelined CPU time = 1 ns * 4.4 * IC
  • (^) Pipelined CPU time = 1.2 ns * 1 * IC
  • (^) Pipelined machine is faster by 4.4 / 1.2 = 3.

Another Example

  • (^) Assume MIPS unpipelined has a CPI = 3.85 for a given benchmark and the ideal CPI for pipelined MIPS = 1
  • (^) Assume MIPS pipelined has clock cycle time 1.1 times greater than MIPS unpipelined due to overhead
  • (^) Plot the speedup of the MIPS pipelined over the MIPS unpipelined machine - (^) for stalls that range from 0 per instruction up to 2 per instruction by units of.
  • (^) How many stalls / instruction must occur for the two machines performances to become equal? 0

1

2

3

4 0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2 Stalls / Instruction Speedup The pipelines have equal Performance when 3.85 = 1.1 * (1 + stalls) Or stalls = 3.85 / 1.1 – 1 = 2.5 stalls per instruction

Structural Hazards

  • (^) We have already resolved one structural hazard: two possible cache accesses in one cycle - (^) This would arise any time we have a load/store instruction - (^) As it moves down the pipeline and reaches the MEM stage, it would conflict with the next instruction fetch - (^) Assuming 35% loads and 15% stores in a program, half of the instructions would cause this hazard requiring a stall, this would introduce .5 stalls per instruction or an overall CPI of 1.5! - (^) We avoid this with 2 caches
  • (^) The other source of structural hazard occurs in the EX stage if an operation takes more than 1 cycle to complete - (^) We cannot have the next instruction move into EX if the current instruction is still there - (^) This happens with longer ALU operations: multiplication, division, floating point operations - (^) We will resolve this problem later when we add FP to our pipeline, for now, assume all ALU operations take 1 cycle

Data Hazards

Solutions

• We will implement 3 solutions to data hazards

  • (^) First, we will only access registers in the first half of the cycle in WB and the second half of the cycle in ID - (^) this permits an instruction to place a result in the register file and in the same cycle another instruction can read the same register to get the new value
  • (^) Second, we will implement forwarding (covered in the next slide) - (^) this will shunt a value directly from the ALU as output directly into the ALU as input - (^) this will shunt a value received from memory directly into the ALU as input or directly back to memory
  • (^) Third, we will let the compiler fill any remaining stalls with neutral instructions, this is called compiler scheduling

Forwarding Examples

Notice that The DADD And OR do Not require Forwarding Since the WB write happens before the ID read

Forwarding is Not Enough

  • (^) Forwarding will resolve the following situations:
    • (^) DADDI R1, R1, #
    • (^) DSUBI R2, R1, R
      • (^) the value of R1 is passed from ALU output to ALU input
    • (^) LD R1, 0(R3)
    • (^) SD R1, 0(R4)
      • (^) the value of R1 is passed from MEM output to MEM input
    • (^) DSUBI R1, R1, #
    • (^) BNEZ R1, foo
      • (^) the value of R1 is passed from ALU output to ALU input
  • (^) It does not resolve these problems
    • (^) LD R1, 0(R2) IF ID EX MEM WB
    • (^) DADDI R1, R1, #1 IF ID …. EX
      • (^) the value of R1 is available at the end of MEM but needed in DADDI at the beginning of EX
    • (^) LD R1, 0(R2)
    • (^) BNEZ R1, foo
      • (^) same

Impact of Stalls

  • (^) Assume a benchmark of 35% loads, 15% stores, 10% branches, 40% ALU operations - (^) Of the loads, 50% of the loaded values are used immediately afterward - (^) Of the ALU operations, 25% are used immediately afterward either in other ALU operations, stores or branches
  • (^) Without coordinating the ID/WB stages, forwarding or scheduling, all stalls result in 3 cycle penalties - (^) Number of stalls per instruction = .35 * .50 * 3 + .40 * .25 * 3 = .825, or a CPI of 1.
  • (^) With coordinating the ID/WB stages and forwarding, stalls are reduced to 1 cycle for LD  ALU and LD  Branch operations - (^) Number of stalls per instruction = .35 * .50 * 1 = .175, or a CPI of 1.
  • (^) Assuming an optimizing compiler can schedule half of these situations, number of stalls per instruction = .0875 or a CPI of

Branch Hazards

  • (^) The last form of stall occurs with any branch that is taken
    • (^) Unconditional branches are always taken
    • (^) Conditional branches are taken when the condition is true
  • (^) Why is the branch a problem?
    • (^) Branch conditions (conditional branches) and branch target

locations (PC + offset) are both computed in the EX stage (we

do not reset the PC until the MEM stage, but let’s move that

MUX into the EX stage to further reduce the penalty by 1)

  • (^) We have a 2 cycle penalty because we fetched two instructions in the meantime (one is in IF, one is in ID)
  • (^) If the branch is taken, those 2 instructions need to be flushed

from the pipeline, thus taken branches cause a penalty of 2

cycles

  • (^) There are several ways to handle the 2 cycle penalty, both

through hardware and software

MIPS Solutions to the Branch Penalty

  • (^) Hardware solution
    • (^) There is no particular reason why the PC + offset and condition evaluation have to wait until the EX stage
    • (^) Let’s add an ADDER to the ID stage to do PC + offset
    • (^) We can also move the zero tester into the ID stage so that the comparison takes place after registers are read - (^) recall that the ID stage is one of the two shortest (time-wise) in

the pipeline, we should have enough time in this stage to read

from registers and do the zero test

  • (^) If the branches are now being determined in the ID stage, it reduces the branch penalty to 1
  • (^) Software solution
  • (^) The compiler can try to move a neutral instruction into that penalty location, known as the branch delay slot

• The new IF and ID stages are Continued

shown to the right

  • (^) The PC + Offset is computed automatically
  • (^) A MUX is used to select which PC value should be used in the next fetch, PC + 4 or PC + Offset, this is based on two decisions - (^) is the instruction in ID a branch and if the instruction is a conditional branch, is the condition true? if so, use PC + Offset
  • (^) We simplified our MIPS instruction set so that the only two branches are BEQZ and BNEZ, that is, an integer register is simply tested against 0, this can be done quickly (in essence, all bits are NORed together) One consequence of this new architecture is a new source of stall LW R1, 0(R2) BEQZ R1, foo // 2 cycles DSUBI R1, R1, # BNEZ R1, foo // 1 cycle stall