CS 230 - Spring 2020 3-1
Computer Systems Lecture 13 Pipeline Stages CS 230 - Spring 2020 - - PowerPoint PPT Presentation
Computer Systems Lecture 13 Pipeline Stages CS 230 - Spring 2020 - - PowerPoint PPT Presentation
CS 230 Introduction to Computers and Computer Systems Lecture 13 Pipeline Stages CS 230 - Spring 2020 3-1 System Layers Python/C/Racket Code Multiprocessing and Operating Systems Build and Runtime Environments Memory and Caching
System Layers
CS 230 - Spring 2020 0-2
Transistors and Electrical Properties Logic Gates Binary Signals & Number Representation CPU Instructions and Pipelining Memory and Caching Build and Runtime Environments Multiprocessing and Operating Systems Python/C/Racket Code CS 230 Finished! Finished! Here now!
CS 230 - Spring 2019 3-3
Clock
Clock cycle: beat of computer Clock signal Electrical signals propagate fast
but not infinitely fast: remember gate delays
Rising edge called a tick
like a drummer for a dragon boat, keeps things in sync
time voltage
tick tick tick
CS 230 - Spring 2019 3-4
CPU Clocking
Do work, update state, do work, update state… Split instruction into pipeline stages
One pipeline stage per clock cycle MIPS has 5 pipeline stages
Clock (cycles) Data transfer and computation Update state Clock period
CS 230 - Spring 2019 3-5
MIPS Pipeline Stages
IF: Instruction fetch
retrieve the instruction
ID: Instruction decode
decode the instruction and load the registers we need
EX: Execute
operate the arithmetic logic unit (ALU)
MEM: Memory access
access memory
WB: Write back
write results back to registers
CS 230 - Spring 2020 3-6
IF – Instruction Fetch
Look at address in memory stored in PC Load the 32-bit value from that address
this is the next instruction pass this value on to ID
Increment PC by 4
CS 230 - Spring 2020 3-7
ID – Instruction Decode
Get 32-bit binary instruction from IF Decode it
what instruction is it? what registers does it need? what immediate values does it need? if it is a branch:
is the branch condition met?
if so, update PC accordingly
MIPS Reference Sheet
CS 230 - Spring 2020 3-8
(also posted along with slides)
CS 230 - Spring 2020 3-9
Instruction Decode Example
Look at bits of instruction
00100000110000110000000000010001
CS 230 - Spring 2020 3-10
Instruction Decode Example
Look at bits of instruction
what instruction is it?
00100000110000110000000000010001 addi
CS 230 - Spring 2020 3-11
Instruction Decode Example
Look at bits of instruction
what instruction is it? what registers does it need?
00100000110000110000000000010001 addi $3, $6
CS 230 - Spring 2020 3-12
Instruction Decode Example
Look at bits of instruction
what instruction is it? what registers does it need? what immediate values does it contain?
two’s complement
except .word when using hexadecimal, which is unsigned binary
00100000110000110000000000010001 addi $3, $6, 17
Try it Yourself
What MIPS instructions are encoded as the following 32-bit binary numbers?
CS 230 - Spring 2020 3-13
00000000000000000110100000010000 00000000101010000011100000101010 10101100111001000000000000010000
Try it Yourself
What MIPS instructions are encoded as the following 32-bit binary numbers?
CS 230 - Spring 2020 3-14
00000000000000000110100000010000 mfhi 00000000101010000011100000101010 10101100111001000000000000010000
Try it Yourself
What MIPS instructions are encoded as the following 32-bit binary numbers?
CS 230 - Spring 2020 3-15
00000000000000000110100000010000 mfhi $13 00000000101010000011100000101010 10101100111001000000000000010000
Try it Yourself
What MIPS instructions are encoded as the following 32-bit binary numbers?
CS 230 - Spring 2020 3-16
00000000000000000110100000010000 mfhi $13 00000000101010000011100000101010 slt 10101100111001000000000000010000
Try it Yourself
What MIPS instructions are encoded as the following 32-bit binary numbers?
CS 230 - Spring 2020 3-17
00000000000000000110100000010000 mfhi $13 00000000101010000011100000101010 slt $7 10101100111001000000000000010000
Try it Yourself
What MIPS instructions are encoded as the following 32-bit binary numbers?
CS 230 - Spring 2020 3-18
00000000000000000110100000010000 mfhi $13 00000000101010000011100000101010 slt $7, $5 10101100111001000000000000010000
Try it Yourself
What MIPS instructions are encoded as the following 32-bit binary numbers?
CS 230 - Spring 2020 3-19
00000000000000000110100000010000 mfhi $13 00000000101010000011100000101010 slt $7, $5, $8 10101100111001000000000000010000
Try it Yourself
What MIPS instructions are encoded as the following 32-bit binary numbers?
CS 230 - Spring 2020 3-20
00000000000000000110100000010000 mfhi $13 00000000101010000011100000101010 slt $7, $5, $8 10101100111001000000000000010000 sw
Try it Yourself
What MIPS instructions are encoded as the following 32-bit binary numbers?
CS 230 - Spring 2020 3-21
00000000000000000110100000010000 mfhi $13 00000000101010000011100000101010 slt $7, $5, $8 10101100111001000000000000010000 sw $4
Try it Yourself
What MIPS instructions are encoded as the following 32-bit binary numbers?
CS 230 - Spring 2020 3-22
00000000000000000110100000010000 mfhi $13 00000000101010000011100000101010 slt $7, $5, $8 10101100111001000000000000010000 sw $4, ($7)
Try it Yourself
What MIPS instructions are encoded as the following 32-bit binary numbers?
CS 230 - Spring 2020 3-23
00000000000000000110100000010000 mfhi $13 00000000101010000011100000101010 slt $7, $5, $8 10101100111001000000000000010000 sw $4, 16($7)
Try it Yourself
What are the binary representations of the following MIPS instructions?
CS 230 - Spring 2020 3-24
add $2, $3, $1 beq $1, $0, 3
Try it Yourself
What are the binary representations of the following MIPS instructions?
CS 230 - Spring 2020 3-25
add $2, $3, $1 000000 00000100000 beq $1, $0, 3
Try it Yourself
What are the binary representations of the following MIPS instructions?
CS 230 - Spring 2020 3-26
add $2, $3, $1 000000 0001000000100000 beq $1, $0, 3
Try it Yourself
What are the binary representations of the following MIPS instructions?
CS 230 - Spring 2020 3-27
add $2, $3, $1 00000000011 0001000000100000 beq $1, $0, 3
Try it Yourself
What are the binary representations of the following MIPS instructions?
CS 230 - Spring 2020 3-28
add $2, $3, $1 00000000011000010001000000100000 beq $1, $0, 3
Try it Yourself
What are the binary representations of the following MIPS instructions?
CS 230 - Spring 2020 3-29
add $2, $3, $1 00000000011000010001000000100000 beq $1, $0, 3 000100
Try it Yourself
What are the binary representations of the following MIPS instructions?
CS 230 - Spring 2020 3-30
add $2, $3, $1 00000000011000010001000000100000 beq $1, $0, 3 00010000001
Try it Yourself
What are the binary representations of the following MIPS instructions?
CS 230 - Spring 2020 3-31
add $2, $3, $1 00000000011000010001000000100000 beq $1, $0, 3 0001000000100000
Try it Yourself
What are the binary representations of the following MIPS instructions?
CS 230 - Spring 2020 3-32
add $2, $3, $1 00000000011000010001000000100000 beq $1, $0, 3 00010000001000000000000000000011
CS 230 - Spring 2020 3-33
EX – Execute
Get from ID the:
32-bit input register contents instruction to do
for lw and sw this is an addition of the offset
destination register
Use the ALU to do the math for the instruction Pass on to MEM the:
32-bit result of the math destination register and instruction
CS 230 - Spring 2020 3-34
MEM – Memory Access
Get from EX the:
32-bit result of the math destination register and instruction
If instruction is lw or sw
load from or store to memory otherwise do nothing (just pass on values)
Pass on to WB the:
32-bit result, or value loaded from memory (for lw) destination register and instruction
CS 230 - Spring 2020 3-35
WB – Write Back
Get from MEM the:
32-bit result of the math or loaded value destination register and instruction
If instruction is not sw
put result or loaded value into destination register