lab3: pipeline
TRANSCRIPT
![Page 1: Lab3: Pipeline](https://reader031.vdocuments.us/reader031/viewer/2022013001/61ca77b58540ad6c6f5550fe/html5/thumbnails/1.jpg)
Lab3: Pipeline
Dimitar Nikolov
![Page 2: Lab3: Pipeline](https://reader031.vdocuments.us/reader031/viewer/2022013001/61ca77b58540ad6c6f5550fe/html5/thumbnails/2.jpg)
Lund University / Electrical and Information Technology / 1
Goal
• Understand how pipelining works
• Learn what happens in different pipeline stages
• Leran how to avoid pipeline hazzards
![Page 3: Lab3: Pipeline](https://reader031.vdocuments.us/reader031/viewer/2022013001/61ca77b58540ad6c6f5550fe/html5/thumbnails/3.jpg)
Lund University / Electrical and Information Technology / 2
Tools
• Tools used for this exercise:
– MipsIt.exe
– MipsPipeS.exe
Used for program editing
Used for simulation
![Page 4: Lab3: Pipeline](https://reader031.vdocuments.us/reader031/viewer/2022013001/61ca77b58540ad6c6f5550fe/html5/thumbnails/4.jpg)
Lund University / Electrical and Information Technology / 3
Online test
• The online test is scheduled on Monday 23th November
• Access the test from the course web-page
• Example of an online test is provided
![Page 5: Lab3: Pipeline](https://reader031.vdocuments.us/reader031/viewer/2022013001/61ca77b58540ad6c6f5550fe/html5/thumbnails/5.jpg)
Lund University / Electrical and Information Technology / 4
Overview
• Background
• Simulation
![Page 6: Lab3: Pipeline](https://reader031.vdocuments.us/reader031/viewer/2022013001/61ca77b58540ad6c6f5550fe/html5/thumbnails/6.jpg)
Lund University / Electrical and Information Technology / 5
Motivation
• Instructions are exectued one at a time
• Each instruction occupies a set of resources
– access to memory
– access to registers
– access to ALU
• Resources are not occupied all the time
• Execution of an instruction can be split into a number of
stages
• Overlap execution of instructions
• Goal: improve throughput (number of instructions over time)
![Page 7: Lab3: Pipeline](https://reader031.vdocuments.us/reader031/viewer/2022013001/61ca77b58540ad6c6f5550fe/html5/thumbnails/7.jpg)
Lund University / Electrical and Information Technology / 6
Pipeline
• Execution of instructions is split into a sequence of
dependent stages
• Once an instruction has completed with one stage it can
proceed to the next stage, and a new instruction can take
over the stage that has been released
• The time to execute a single instruction is not altered
• The number of executed instructions over time is increased
![Page 8: Lab3: Pipeline](https://reader031.vdocuments.us/reader031/viewer/2022013001/61ca77b58540ad6c6f5550fe/html5/thumbnails/8.jpg)
Lund University / Electrical and Information Technology / 7
MIPS pipeline
• Five stages, one step per stage
1. IF: Instruction fetch from memory
2. ID: Instruction decode & register read
3. EX: Execute operation or calculate address
4. MEM: Access memory operand
5. WB: Write result back to register
![Page 9: Lab3: Pipeline](https://reader031.vdocuments.us/reader031/viewer/2022013001/61ca77b58540ad6c6f5550fe/html5/thumbnails/9.jpg)
Lund University / Electrical and Information Technology / 8
IF (Instruction Fetch)
![Page 10: Lab3: Pipeline](https://reader031.vdocuments.us/reader031/viewer/2022013001/61ca77b58540ad6c6f5550fe/html5/thumbnails/10.jpg)
Lund University / Electrical and Information Technology / 9
ID (Instruction decode & register read)
![Page 11: Lab3: Pipeline](https://reader031.vdocuments.us/reader031/viewer/2022013001/61ca77b58540ad6c6f5550fe/html5/thumbnails/11.jpg)
Lund University / Electrical and Information Technology / 10
EX (Execute operation or calculate address)
![Page 12: Lab3: Pipeline](https://reader031.vdocuments.us/reader031/viewer/2022013001/61ca77b58540ad6c6f5550fe/html5/thumbnails/12.jpg)
Lund University / Electrical and Information Technology / 11
MEM (Access memory operand)
![Page 13: Lab3: Pipeline](https://reader031.vdocuments.us/reader031/viewer/2022013001/61ca77b58540ad6c6f5550fe/html5/thumbnails/13.jpg)
Lund University / Electrical and Information Technology / 12
WB (Write result back to register)
![Page 14: Lab3: Pipeline](https://reader031.vdocuments.us/reader031/viewer/2022013001/61ca77b58540ad6c6f5550fe/html5/thumbnails/14.jpg)
Lund University / Electrical and Information Technology / 13
Potential hazards
• Structural hazards
– A resource is used by two instructions that are in
different pipeline stages
• Data hazards
– Due to data dependencies between instructions
• Control hazards
– Due to branch instructions
![Page 15: Lab3: Pipeline](https://reader031.vdocuments.us/reader031/viewer/2022013001/61ca77b58540ad6c6f5550fe/html5/thumbnails/15.jpg)
Lund University / Electrical and Information Technology / 14
Structural hazards
IF ID EX MEM WB
IF ID EX MEM WB
IF ID EX MEM WB
IF ID EX MEM WB
Memory
read
IF ID EX MEM WB
time
Use separate Instruction and Data Cache
![Page 16: Lab3: Pipeline](https://reader031.vdocuments.us/reader031/viewer/2022013001/61ca77b58540ad6c6f5550fe/html5/thumbnails/16.jpg)
Lund University / Electrical and Information Technology / 15
Data hazards
ADD $s0, $t0, $t1
SUB $t2, $s0, $t3 Read after Write (RAW) dependency
![Page 17: Lab3: Pipeline](https://reader031.vdocuments.us/reader031/viewer/2022013001/61ca77b58540ad6c6f5550fe/html5/thumbnails/17.jpg)
Lund University / Electrical and Information Technology / 16
Data hazards
Need to stall
for one cycle
Forwarding
![Page 18: Lab3: Pipeline](https://reader031.vdocuments.us/reader031/viewer/2022013001/61ca77b58540ad6c6f5550fe/html5/thumbnails/18.jpg)
Lund University / Electrical and Information Technology / 17
Data hazards
Stall inserted
here
![Page 19: Lab3: Pipeline](https://reader031.vdocuments.us/reader031/viewer/2022013001/61ca77b58540ad6c6f5550fe/html5/thumbnails/19.jpg)
Lund University / Electrical and Information Technology / 18
Control hazards
• Branch is taken or not taken
• The next instruction to be fetched might depend on the
branch condition
• The condition may not be evaluated before the branch
instruction reaches the MEM stage in the pipeline
• Unneeded instructions are already in the pipeline
![Page 20: Lab3: Pipeline](https://reader031.vdocuments.us/reader031/viewer/2022013001/61ca77b58540ad6c6f5550fe/html5/thumbnails/20.jpg)
Lund University / Electrical and Information Technology / 19
Control hazards
• To avoid:
– Delayed branching (place the branch instruction earlier
in the code, without violating data dependencies, and
proceed with the instructions that must be executed
irrespective of the evaluation of the branch condition)
– Delayed branching (add nops after the branch
instruction, such that in case the branch is taken the
nops will fill in the pipeline prior to the execution of
instructions that should be executed when the branch
is taken)
![Page 21: Lab3: Pipeline](https://reader031.vdocuments.us/reader031/viewer/2022013001/61ca77b58540ad6c6f5550fe/html5/thumbnails/21.jpg)
Lund University / Electrical and Information Technology / 20
Overview
• Background
• Simulation
![Page 22: Lab3: Pipeline](https://reader031.vdocuments.us/reader031/viewer/2022013001/61ca77b58540ad6c6f5550fe/html5/thumbnails/22.jpg)
Lund University / Electrical and Information Technology / 21
Compile, Build and Upload
![Page 23: Lab3: Pipeline](https://reader031.vdocuments.us/reader031/viewer/2022013001/61ca77b58540ad6c6f5550fe/html5/thumbnails/23.jpg)
Lund University / Electrical and Information Technology / 22
MipsPipeS
Click to see the pipeline
![Page 24: Lab3: Pipeline](https://reader031.vdocuments.us/reader031/viewer/2022013001/61ca77b58540ad6c6f5550fe/html5/thumbnails/24.jpg)
Lund University / Electrical and Information Technology / 23
MipsPipeS Simulate by stepping
![Page 25: Lab3: Pipeline](https://reader031.vdocuments.us/reader031/viewer/2022013001/61ca77b58540ad6c6f5550fe/html5/thumbnails/25.jpg)
Lund University / Electrical and Information Technology / 24