Lec-1-To-10 19ECE349-RISC Processor Design Using HDL
Lec-1-To-10 19ECE349-RISC Processor Design Using HDL
• CO2: Able to design circuits using Verilog and understand concept of timing analysis
• Fundamental techniques of computer design – RISC and CISC architectures - computer arithmetic, - comparison of
RISC and CISC architectures - Introduction to superscalar and super pipelined architectures - Verilog Introduction
and review of basic designs using Verilog - Static timing analysis – Introduction - setup and hold time constraints -
processor timing issues - design examples.
• Unit II:
• MIPS Processor- Introduction to MIPS features and MIPS instruction set, logical design of MIPS datapath - control
unit and instruction decode - Design of single cycle - multi-cycle and pipelined architectures of MIPS - Hazards-
data and control hazards - Verilog designs of single cycle and multi-cycle MIPS processor.
• Unit III:
• Verilog design of pipelined MIPS processor - Introduction to memory hierarchy cache memory fundamentals -
memory systems for superscalar processors.
Textbook(s) and References:
Textbook(s):
• 1.Patterson, David A., and John L. Hennessy, “Computer Organization and Design: The Hardware Software
Interface”, Morgan kaufmann, First edition 2005.
• 2. Sarah L Harris, David Money Harris “, Digital Design and Computer Architecture RISC-V Edition
• 2. Palnitkar, Samir. “Verilog HDL: a guide to digital design and synthesis”, Edition 1, Prentice Hall
Professional, 2003.
Reference(s)
• 1.Hamacher, V. Carl, et al. “Computer organization”, Fifth edition. New York et al. McGraw-Hill, 1984.
• 2.Dandamudi, Sivarama P, “Guide to RISC processors: for programmers and engineers”, First edition, Springer
Science & Business Media, 2005.
Simple RISC Processor?
compute
jump/branch
targets
A
memory register
alu
D
file
B
+4
addr
PC control din dout
inst
M
B
memory
extend Forward
new
imm
unit
Detect
pc hazard
ctrl
ctrl
Fetch Decode Memory Back
IF/ID ID/EX EX/MEM MEM/WB
5
Fundamental Techniques of Computer Design
• Computer Architecture Basics
• Von Neumann vs. Harvard Architecture
• Microarchitecture vs. Architecture
• Performance Metrics: Throughput, Latency, CPI, MIPS, FLOPS
• Instruction Set Architecture (ISA)
• Types of Instructions: Data movement, Arithmetic, Logical, Control, etc.
• RISC vs. CISC: Characteristics and differences
• Addressing Modes
• Instruction Formats
Fundamental Techniques of Computer Design
• Pipeline Design
• Pipeline Stages: Fetch, Decode, Execute, Memory, Write-back
• Memory Hierarchy
• Cache Memory: Cache organization, mapping techniques, replacement
policies
• Main Memory: DRAM, SRAM, Virtual Memory
• Memory Access Techniques: Direct Memory Access (DMA)
Simple RISC Processor?
compute
jump/branch
targets
A
memory register
alu
D
file
B
+4
addr
PC control din dout
inst
M
B
memory
extend Forward
new
imm
unit
Detect
pc hazard
ctrl
ctrl
Fetch Decode Memory Back
IF/ID ID/EX EX/MEM MEM/WB
8
Memory Hierarchy
Computer Architecture Basics - Von Neumann
• Single memory
• Instructions
• Data
Computer Architecture Basics - Harvard Architecture
• Two memories
• One for Instructions
• One for Data
Computer Architecture Basics - Harvard Architecture
Computer Architecture Basics - Von Neumann
Basis for Comparison Von Neumann Architecture Harvard Architecture
Basic Data and instructions reside within a single Data and instruction are provided 2
memory unit. different memory units.
Clock cycle Single instruction is executed in minimum two Single instruction is executed in one clock
clock cycles. cycle.
Computer Architecture:
Computer Architecture:
• Definition: Refers to a computer system's abstract,
high-level design. It defines a computer's capabilities
and programming model but does not specify how
these are implemented.
• Key Aspects:
• Pipeline Design: Specific stages and handling of data hazards, control hazards,
and structural hazards.
• Cache Organization: Details on cache size, levels, associativity, and replacement
policies.
• Branch Prediction: Techniques used to guess the outcome of branches and
improve pipeline efficiency.
• Execution Units: The detailed design of units like ALUs, FPUs, load/store units,
and how they execute instructions.
• Control Unit: How the processor manages and sequences operations, whether
using a hardwired approach or microprogramming.
A micro-architecture organized around a single bus processor
Microarchitecture Vs. Architecture
• In electronics, computer science and computer
engineering, microarchitecture, also called computer
organization and sometimes abbreviated as μarch or uarch, is
the way a given instruction set architecture (ISA) is
implemented in a particular processor.
• A given ISA may be implemented with different
microarchitectures; implementations may vary due to different
goals of a given design or due to shifts in technology.
RISC-V
x86
RISC-V X86
Reduced Instruction Set Computer Complex Instruction Set Computer
(RlSC) (ClSC)
• ≈ 200 instructions, • > 1000 instructions,
• 1 to 15 bytes each
• 32 bits each, 4 formats
• operands in dedicated registers,
• all operands in registers general purpose registers, memory,
• almost all are 32 bits each on stack, …
• can be 1, 2, 4, 8 bytes, signed or
unsigned
• ≈ 1 addressing mode: Mem[reg + • 10s of addressing modes
imm] • e.g. Mem[segment + reg + reg*scale +
offset]
24
Comparison of RISC and CISC (x86)
Parameter RISC CISC
Instruction Set Size ≈ 200 instructions > 1000 instructions
Instruction Length 32 bits each 1 to 15 bytes each
Instruction Formats 4 formats N/A (variable-length instructions)
Operands in dedicated registers,
Operand Location All operands in registers general purpose registers, memory,
on stack, etc.
Can be 1, 2, 4, 8 bytes, signed or
Operand Size Almost all are 32 bits each
unsigned
10s of addressing modes (e.g.,
≈ 1 addressing mode (Mem[reg +
Addressing Modes Mem[segment + reg + reg*scale +
imm])
offset])
Example Comparison of RISC and CISC instructions
Example of RISC: ADD R1, R2, R3 Example of CISC: ADD A, [M]
• Opcode Rd, Rs1, Rs2 • Opcode Rd/Rs1, [m]
• Read source 1 operand from • Read source 1 operand from
register Rs1, register Rs1,
• Read source 2 operand from • Read source 2 operand from
register Rs2, Memory location M, which has
• Perform Arithmetic operation on many sub-operations
source 1 and source 2 data • Perform Arithmetic operation on
• Write arithmetic result into register source 1 and source 2 data
Rd • Write arithmetic result into register
• No, memory read operation Rd
• only arithmetic operation • Both, memory read operation and
arithmetic operation
Example Comparison of RISC and CISC instructions
Example of RISC: ADD R1, R2, R3 Example of CISC: ADD A, [M]
• Opcode Rd, Rs1, Rs2 • Opcode Rd/Rs1, [m]
• Read source 1 operand from • Read source 1 operand from
register Rs1, register Rs1,
• Read source 2 operand from • Read source 2 operand from
register Rs2, Memory location M, which has
• Perform Arithmetic operation on many sub-operations
source 1 and source 2 data • Perform Arithmetic operation on
• Write arithmetic result into register source 1 and source 2 data
Rd • Write arithmetic result into register
• No, memory read operation Rd
• only arithmetic operation • Both, memory read operation and
arithmetic operation
Example Comparison of RISC and CISC instructions
Example of RISC: ADD R1, R2, R3 Example of SISC: ADD A, [M]
• Opcode Rd, Rs1, Rs2 • Opcode Rd/Rs1, [m]
• Read source 1 operand from • Read source 1 operand from
register Rs1, register Rs1,
• Read source 2 operand from • Read source 2 operand from
register Rs2, Memory location M, which has
• Perform Arithmetic operation on many sub-operations
source 1 and source 2 data • Perform Arithmetic operation on
• Write arithmetic result into register source 1 and source 2 data
Rd • Write arithmetic result into register
• No, memory read operation Rd
• only arithmetic operation • Both, memory read operation and
arithmetic operation
Example Comparison of RISC and CISC instructions
Example of RISC: ADD R1, R2, R3 Example of SISC: ADD A, [M]
• Opcode Rd, Rs1, Rs2 • Opcode Rd/Rs1, [m]
• Read source 1 operand from • Read source 1 operand from
register Rs1, register Rs1,
• Read source 2 operand from • Read source 2 operand from
register Rs2, Memory location M, which has
• Perform Arithmetic operation on many sub-operations
source 1 and source 2 data • Perform Arithmetic operation on
• Write arithmetic result into register source 1 and source 2 data
Rd • Write arithmetic result into register
• No, memory read operation Rd
• only arithmetic operation • Both, memory read operation and
arithmetic operation
Example Comparison of RISC and CISC instructions
Example of RISC: ADD R1, R2, R3 Example of SISC: ADD A, [M]
• Opcode Rd, Rs1, Rs2 • Opcode Rd/Rs1, [m]
• Read source 1 operand from • Read source 1 operand from
register Rs1, register Rs1,
• Read source 2 operand from • Read source 2 operand from
register Rs2, Memory location M, which has
• Perform Arithmetic operation on many sub-operations
source 1 and source 2 data • Perform Arithmetic operation on
• Write arithmetic result into register source 1 and source 2 data
Rd • Write arithmetic result into register
• No, memory read operation Rd
• only arithmetic operation • Both, memory read operation and
arithmetic operation
Example Comparison of RISC and CISC instructions
Example of RISC: ADD R1, R2, R3 Example of SISC: ADD A, [M]
• Opcode Rd, Rs1, Rs2 • Opcode Rd/Rs1, [m]
• Read source 1 operand from • Read source 1 operand from
register Rs1, register Rs1,
• Read source 2 operand from • Read source 2 operand from
register Rs2, Memory location M, which has
• Perform Arithmetic operation on many sub-operations
source 1 and source 2 data • Perform Arithmetic operation on
• Write arithmetic result into register source 1 and source 2 data
Rd • Write arithmetic result into register
• No, memory read operation Rd
• only arithmetic operation • Both, memory read operation and
arithmetic operation
RISC Processor Architecture
Single and Multi Cycle
Simple
RISC
Processor
:
Lecture
Single and Multi-stage Processor
Date: 07-August 2024
Single-Cycle RISC-V Datapath
Big Picture: Building a Processor
memory inst
register
alu
file
+4 +4
addr
=?
PC din dout
offset control cmp
memory
new target
imm
pc extend
37 37
RISC-V Register File
memory inst
register
alu
file
+4 +4
addr
=?
PC din dout
offset control cmp
memory
new target
imm
pc extend
39
RISC-V Register File
• RISC-V register file
• 32 registers, 32-bits each 32 W x0 A 32
• x0 wired to zero x1
• Write port indexed via RW … B 32
• on falling edge when WE=1
• Read ports indexed via RA, RB x31
WE RW R A RB
• RISC-V register file 1 5 5 5
• Numbered from 0 to 31
• Can be referred by number: x0, x1, x2, … x31
• Convention, each register also has a name:
• x10 – x17 a0 – a7, x28 – x31 t3 – t6
8
RISC-V Memory
memory inst
register
alu
file
+4 +4
addr
=?
PC din dout
offset control cmp
memory
new target
imm
pc extend
memory inst
register
alu
file
+4 +4
addr
=?
PC din dout
offset control cmp
memory
new target
imm
pc extend
48
Stage 1: Instruction Fetch
inst
Prog.
Reg. ALU
Mem Data
File
Mem
+4
5 5 5
PC
control
Circuits
Gates
Transistors
73
Silicon
Big Picture: Where are we going?
HDL int x = 10;
compiler x = 2 * x + 15; High Level
addi x5, x0, 10 Languages
RISC-V
muli x5, x5, 2
assembly addi x5, x5, 15
assembler
00000000101000000000001010010011
machine 00000000001000101000001010000000
code 00000000111100101000001010010011
Instruction Set
CPU Architecture (ISA)
Circuits
Gates
Transistors
74
Silicon
RISC-V Instruction Types
RISC-V Instruction Types
• Arithmetic/Logical
• R-type: result and two source registers, shift amount in register
• I-type: result and source register, shift amount in 12-bit immediate with sign/zero
extension
• U-type: result register, 20-bit immediate with sign/zero extension
• S-type: result register (5-bit immediate), source register, 12-bit immediate
• Memory Access
• I-type for loads and S-type for stores
• load/store between registers and memory
• word, half-word and byte operations
• Control flow
• U-type: jump-and-link
• I-type: jump-and-link register
• S-type: conditional branches: pc-relative addresses
76
RISC-V instruction formats
All RISC-V instructions are 32 bits long, have 4
formats
• R-type funct7 rs2 rs1 funct3 rd op
7 bits 5 bits 5 bits 3 bits 5 bits 7 bits
• U-type imm rd op
20 bits 5 bits 7 bits 77
R-Type (1): Arithmetic and Logic
00000000011001000100001000110011
funct7 rs2 rs1 funct3 rd op
7 bits 5 bits 5 bits 3 bits 5 bits 7 bits
78
Arithmetic and Logic
Prog.
Reg. ALU
Mem
File
+4
55 5
PC
control
skip
79
R-Type (2): Shift Instructions
0000000001100010000101000011011
funct7 rs2 rs1 funct3 rd op
7 bits 5 bits 5 bits 3 bits 5 bits 7 bits
80
Shift
Prog.
Reg. ALU
Mem
File
+4
55 5
PC
control
skip
81
I-Type (1): Arithmetic immediates
00000000010100101000001010010011
imm rs1 funct3 rd op
12 bits 5 bits 3 bits 5 bits 7 bits
82
Arithmetic w/ immediates
Prog.
Reg. ALU
Mem
File
+4
55 5
PC
control
imm
extend
16 12
shamt
83
“ ”
U-Type (1): Load Upper Immediate
00000000000000000101001010110111
imm rd op
20 bits 5 bits 7 bits
op mnemonic description
0110111 LUI rd, imm R[rd] = imm << 16
84
Load Upper Immediate
Prog.
Reg. ALU
Mem
File
0x50000
+4
55 5
PC
control 16
imm
extend
16 12
shamt
85
Multiplication
86
RISC-V Instruction Types
• Arithmetic/Logical
• R-type: result and two source registers, shift amount
• I-type: result and source register, shift amount in 16-bit immediate with sign/zero
extension
• U-type: result register, 16-bit immediate with sign/zero extension
• Memory Access
• I-type for loads and S-type for stores
• load/store between registers and memory
• word, half-word and byte operations
• Control flow
• U-type: jump-and-link
• I-type: jump-and-link register
• S-type: conditional branches: pc-relative addresses
87
RISC-V instruction formats
All RISC-V instructions are 32 bits long, have 4
formats
• R-type funct7 rs2 rs1 funct3 rd op
7 bits 5 bits 5 bits 3 bits 5 bits 7 bits
• U-type imm rd op
20 bits 5 bits 7 bits 88
R-Type (1): Arithmetic and Logic
00000000011001000100001000110011
funct7 rs2 rs1 funct3 rd op
7 bits 5 bits 5 bits 3 bits 5 bits 7 bits
89
R-Type (2): Shift Instructions
0000000001100010000101000011011
funct7 rs2 rs1 funct3 rd op
7 bits 5 bits 5 bits 3 bits 5 bits 7 bits
90
Thank You
Additional Slides
Intel 80826 Micro-architecture
Intel Core 2 Architecture
Example Cell Phone Processor (OMAP 2420) from TI