Understanding RISC Architecture and MIPS
Understanding RISC Architecture and MIPS
RISC
Reduced Instruction Set Computers
MIPS
Dr. Eng. Amr T. Abdel-Hamid
Spring 2024
Before the RISC era
Compilers were hard to build especially for machines w
ith registers
Make machine do more work than software
Have instructions load and store directly to memory
(memory-to-memory operations)
Software costs were rising and hardware costs were dr
opping
Move as much functionality to hardware
Magnetic core memory was used as main memory
which was slow and expensive
Minimize assembly code
Dr. Amr Talaat
CSEN B302
Technology was advancing
Compilers were improving
Simple compilers found it difficult to use more
complex instructions
Optimizing compilers rarely needed more pow
erful instructions
Caches
allowed main memory to be accessed at simil
ar speeds to control memory
Semiconductor memory was replacing magnetic
core memory
Dr. Amr Talaat
CSEN B302
Inception of RISC
1974 – John Cocke (IBM) proved that 80% of work was done using only
20% of the instructions
Three RISC projects
IBM 801 machine (1974)
Berkeley’s RISC-I and RISC-II processors (1980)
Stanford’s MIPS processor (1981)
1986 – announcement of first commercial RISC chip
If 29 43 11 21 7 13
GoTo- 3 - - - -
Other 6 1 3 1 2 1
CSEN B302
RISC Approach
CSEN B302
Load/Store Architecture
CSEN B302
Pipelining
Sequential
IF ID OF OE OS
IF ID OF OE OS
Clock Cycle IF ID OF OE OS
Pipelined
IF ID OF OE OS
IF ID OF OE OS
IF – Instruction Fetch
ID – Instruction Decod
IF ID OF OE OS e
Clock Cycle
Dr. Amr Talaat
OF – Operand Fetch
OE – Operand Executio
n
OS – Operation Store
IF ID OF OE OS
IF ID OF OE OS IF – Instruction Fetch
ID – Instruction Deco
de
OF – Operand Fetch
OE – Operand Executi
IF ID OF OE OS on
OS – Operation Store
IF ID OF OE OS
Dr. Amr Talaat
IF ID OF OE OS
CSEN B302
Pipelining
CSEN B302
5 Steps of MIPS Datapath
Figure A.2, Page A-8
MUX
Adder
Next SEQ PC
4 RS1
Zero?
MUXMUX
RS2
Address
Memory
Reg File
Inst
ALU
L
Memory
RD
Data
M
MUX
D
Dr. Amr Talaat
Sign
Imm Extend
WB Data
CSEN B302
5 Steps of MIPS Datapath
Figure A.3, Page A-9
Instruction Instr. Decode Execute Memory Write
Fetch Reg. Fetch Addr. Calc Access Back
MUX
Next PC
Next SEQ PC Next SEQ PC
Adder
4 RS1
Zero?
MUXMUX
MEM/WB
Address
Memory
RS2
EX/MEM
Reg File
ID/EX
IF/ID
ALU
Memory
Data
MUX
WB Data
Sign
Dr. Amr Talaat
Extend
Imm
RD RD RD
CSEN B302
5 Steps of MIPS Datapath
Figure A.3, Page A-9
Instruction Instr. Decode Execute Memory Write
Fetch Reg. Fetch Addr. Calc Access Back
MUX
Next PC
Next SEQ PC Next SEQ PC
Adder
4 RS1
Zero?
MUXMUX
MEM/WB
Address
Memory
RS2
EX/MEM
Reg File
ID/EX
IF/ID
ALU
Memory
Data
MUX
WB Data
Sign
Dr. Amr Talaat
Extend
Imm
RD RD RD
ALU
n Ifetch Reg DMem Reg
s
t
ALU
r. Ifetch Reg DMem Reg
O
r
ALU
Ifetch Reg DMem Reg
d
e
Dr. Amr Talaat
ALU
Ifetch Reg DMem Reg
CSEN B302
Pipelining is not quite that easy!
CSEN B302
One Memory Port/Structural Hazards
Figure A.4, Page A-14
I Load Ifetch
ALU
Reg DMem Reg
n
s
ALU
t
Instr 1 Ifetch Reg DMem Reg
r.
ALU
Reg
Instr 2 Ifetch Reg DMem
O
r
Dr. Amr Talaat
ALU
d Instr 3 Ifetch Reg DMem Reg
e
r
ALU
Instr 4 Ifetch Reg DMem Reg
CSEN B302
One Memory Port/Structural Hazards
(Similar to Figure A.5, Page A-15)
ALU
Reg DMem Reg
n
s
ALU
t
Instr 1 Ifetch Reg DMem Reg
r.
ALU
Reg
Instr 2 Ifetch Reg DMem
O
r
d Stall BubbleBubbleBubbleBubbleBubble
Dr. Amr Talaat
e
r
ALU
Instr 3 Ifetch Reg DMem Reg
CSEN B302
Example: Dual-port vs. Single-port
IF ID/RF EX MEM WB
ALU
add r1,r2,r3 Ifetch Reg DMem Reg
n
s
t
ALU
Ifetch Reg DMem Reg
sub r4,r1,r3
r.
ALU
O
Reg
and r6,r1,r7 Ifetch Reg DMem
r
d
Dr. Amr Talaat
ALU
Ifetch Reg DMem Reg
e or r8,r1,r9
r
ALU
xor r10,r1,r11 Ifetch Reg DMem Reg
CSEN B302
Three Generic Data Hazards
I: add r1,r2,r3
J: sub r4,r1,r3
mmunication.
CSEN B302
Three Generic Data Hazards
Write After Read (WAR)
InstrJ writes operand before InstrI reads it
I: sub r4,r1,r3
J: add r1,r2,r3
K: mul r6,r1,r7
Called an “anti-dependence” by compiler writers.
This results from reuse of the name “r1”.
CSEN B302
Three Generic Data Hazards
Write After Write (WAW)
InstrJ writes operand before InstrI writes it.
I: sub r1,r4,r3
J: add r1,r2,r3
K: mul r6,r1,r7
ALU
Reg DMem Reg
s
t
r. sub r4,r1,r3
ALU
Ifetch Reg DMem Reg
O
r
ALU
Ifetch Reg DMem Reg
d and r6,r1,r7
e
r
ALU
Ifetch Reg DMem Reg
or r8,r1,r9
Dr. Amr Talaat
ALU
Ifetch Reg DMem Reg
xor r10,r1,r11
CSEN B302
HW Change for Forwarding
Figure A.23, Page A-37
NextPC
mux
Registers
MEM/WR
EX/MEM
ALU
ID/EX
Data
mux
Memory
mux
Immediate
Dr. Amr Talaat
ALU
Reg DMem Reg
s
t
r. lw r4, 0(r1)
ALU
Ifetch Reg DMem Reg
O
r
ALU
Ifetch Reg DMem Reg
d sw r4,12(r1)
e
r
ALU
Ifetch Reg DMem Reg
or r8,r6,r9
Dr. Amr Talaat
ALU
Ifetch Reg DMem Reg
xor r10,r9,r11
CSEN B302
25
Data Hazard Even with Forwarding
Figure A.9, Page A-21
ALU
Reg DMem Reg
n
s
t
ALU
sub r4,r1,r6 Ifetch Reg DMem Reg
r.
ALU
Ifetch Reg DMem Reg
Dr. Amr Talaat
and r6,r1,r7
r
d
e
ALU
Ifetch Reg DMem Reg
r
or r8,r1,r9
CSEN B302
Data Hazard Even with Forwarding
(Similar to Figure A.10, Page A-21)
ALU
s lw r1, 0(r2) Ifetch Reg DMem Reg
t
r.
ALU
Ifetch Reg Bubble DMem Reg
sub r4,r1,r6
O
r
d Bubble
ALU
Ifetch Reg DMem Reg
e and r6,r1,r7
Dr. Amr Talaat
r
Bubble
ALU
Ifetch Reg DMem
or r8,r1,r9
ALU
Ifetch Reg DMem Reg
ALU
Reg
14: and r2,r3,r5 Ifetch Reg DMem
ALU
Reg
18: or r6,r1,r7 Ifetch Reg DMem
ALU
Ifetch Reg DMem Reg
22: add r8,r1,r9
Dr. Amr Talaat
ALU
36: xor r10,r1,r11 Ifetch Reg DMem
MUX
EQ PC
Adder
Adder
Zero?
4 RS1
MEM/WB
Address
Memory
RS2
EX/MEM
Reg File
ID/EX
ALU
IF/ID
Memory
MUX
Data
MUX
WB Data
Sign
Dr. Amr Talaat
Extend
Imm
RD RD RD
CSEN B302
Use of RISC today
CISC and RISC architectures are nearly indistinguishable
CISC processors use pipelining and can complete multipl
e instructions per cycle
Transistor technology has allowed more room on chips al
lowing RISC to have more CISC like instruction
Dr. Amr Talaat
CSEN B302
Thanks & Good Luck
Dr. Amr Talaat
CSEN B302