RVSoC Ch2riscv
RVSoC Ch2riscv
System-on-Chip Design
Harris, Stine, Thompson & Harris
Chapters 2:
RISC-V Introduction
Chapter 2 :: Topics
RISC-V Introduction
2.1 RISC-V Assembly Language
2.2 RISC-V Machine Language
2.3 Have a Hart
2.4 Memory Map
2.5 RISC-V Extensions & Profiles
2.6 Comparison with other Architectures
2.7 RISC-V Microarchitecture
2.8 Wally SoC
2.9 RISC-V Market
RISC-V Intro
RISC-V
!"#" &%%&
• Developed by Krste Asanovic, Andrew
!"$% '(')!!
Waterman, Yunsup Lee, David Patterson
!"$$ +HH-.I00
and their colleagues at UC Berkeley in
2010. !"*! 012I'3
!"*4)I
5063
• First widely accepted open-source !"*#
+-H78I
computer architecture !""4
4!%#&
!""9 '.:;<=>
• Called RISC-V (pronounced “risk five”) !""&) 2?@I
because it was the 5th generation RISC 4%%# A8BC
4%!% 5063)E
“RISC-V is envitable”
– Krste Asanovic
Assembly Language
RISC-V Assembly Language
• RV32I:
– Integer operations
– 40 instructions
• RV64I adds instructions:
– For 64-bit (double-word) loads/stores
– To operate on bottom 32 bits of 64-bit register
Examples:
beq s0, s1, L1 # if (s0 == s1), goto L1
blt t0, t1, L3 # if (t0 < t1), goto L3
Registers &
Conventions
RISC-V Register
Name Register Number Usage
zero x0 Constant value 0
ra x1 Return address
sp x2 Stack pointer
gp x3 Global pointer
tp x4 Thread pointer
t0-2 x5-7 Temporaries
s0/fp x8 Saved register / Frame pointer
s1 x9 Saved register
a0-1 x10-11 Function arguments / return values
a2-7 x12-17 Function arguments
s2-11 x18-27 Saved registers
t3-6 x28-31 Temporaries
#42*5)EE'*++*+
77 88 99 AA 77 88 99 AA
C D E F C F E D C
12 34 F0 E0 12 34 F0 E0
8 9 A B 8 B A 9 8
FF EE DD CC FF EE DD CC
4 5 6 7 4 7 6 5 4
AB CD EF 00 AB CD EF 00
0 1 2 3 0 3 2 1 0
!"# A"# !"# A"#
24 RISC-V System-on-Chip Design Chapter 2 RISC-V
Big-Endian & Little-Endian Example
• Suppose 0x23456789 is stored at address 0x3C.
• What value is in s0 after this instruction executes in a
big-endian system? lb s0, 0x3D(zero)
• In a little-endian system?
Pseudoinstructions
Pseudoinstructions
• Pseudoinstructions: instructions that are
convenient for the programmer that can be
implemented with existing RISC-V instructions.
• Assembler converts them to real RISC-V instructions.
C to Assembly
Examples
C to Assembly Examples: Variables
• For the following programs, assume these variables
have been declared and are kept in these registers:
int a, b, c; // in s0, s1, s2, respectively
int i, j; // in s3, s4
int grades[100]; // base address in s5
char name[80]; // base address in s6
# t0 = t0 + 17
addi t0, t0, 17
# grades[1] = t0
sw t0, 4(s5)
RISC-V Machine
Language
RISC-V Instruction Formats
&./0%( 1./0%( 1./0%( 2./0%( 1./0%( &./0%(
!"#$%& '() '(* !"#$%2 '+ ,- !"#$B&
033**45 '(* !"#$%2 '+ ,- '"#$B&
033**41 '() '(* !"#$%2 033645 ,- ("#$B&
033*)7*541 '() '(* !"#$%2 03364*7** ,- )"#$B&
0332*4*) '+ ,- *"#$B&
033)57*54*7**7*84*) '+ ,- +"#$B&
)5./0%( 1./0%( &./0%(
I!"#$%
31:20 19:15 14:12 11:7 6:0
!""##$% &'# 2345.0 &( )*
#+,-!.' /,-!.' 0,-!.' /,-!.' 1,-!.'
%&#$' !!#+ * S
!""#$$' !""#$%&%'
%! * %&#$' !!#+ ! (
!""#$(' !""#$$&$'
%! %&#$& !"#!$ ! )
!""#)$&$('
%! !"#!$ $& %&#$' $,#$! ! J
!""#(%' !""#$*&$'
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
!II-.$*+E$
46 RISC-V System-on-Chip Design Chapter 2 RISC-V
Assembly to Machine Code
Convert to machine language:
sub x3, x4, x5
Solution:
• Write in binary: 0000 0011 1110 1001 0000 0101 0010 0011
• Start with op: tells how to parse rest: 010 0011 = S-type
• Extract fields:
imm11:5 rs2 rs1 funct3 imm4:0 op
0000001 11110 10010 000 01010 0100011
• op = 0100011, funct3 = 00: sb
• rs2 = 11110 (x30), rs1 = 10010 (x18)
• imm = 000000101010 = 42
sb x30, 42(x18)
48 RISC-V System-on-Chip Design Chapter 2 RISC-V
RISC-V Integer Instruction Summary
RISC-V Hart
RISC-V Hart
• A hart is an abstraction of a hardware thread, but
harts may be physical (in hardware), virtual, or
simulated.
• Each hart:
– Has a PC (program counter) and registers
– Executes independently of other harts
• Example: a hart may correspond to a physical core or
an operating system (OS) may time-multiplex many
user-level virtual harts onto a smaller number of
physical harts.
!"#$%C
,- .! -/.+ !"#$%C'#(F
*#C%+
'()*H,-.%/-#0%C
!"#$%1
,- .! -/.+ !"#$%C'#(F
*#C%+
'()*H,-.%/-#0%1
!"#$%2
,- .! -/.+ !"#$%C'#(F
*#C%+
'()*H,-.%/-#0%2
!"#$%P
,- .! -/.+ !"#$%C'#(F
*#C%+
'()*H,-.%/-#0%P
4 Cores
4 Physical Harts
'()*H,-.%/-#0%1 !"#$%2
<%<%<
'()*H,-.%/-#0%1
!"#$%2 !" #$ "%#C $'(F*+,(-. !" #$ "%#C $'(F*+,(-.
'()*H,-.%/-#0%4 /(+*C '()*H,-.%/-#M%4 /(+*C
,- .! -/.+ !"#$%C'#(F
*#C%+ !" #$ "%#C !" #$ "%#C
'()*H,-.%/-#0%5 '()*H,-.%/-#M%5
'()*H,-.%/-#0%2
!"#$%P !"#$%P
!"#$%P
!" #$ "%#C $'(F*+,(-. !" #$ "%#C $'(F*+,(-.
,- .! -/.+ !"#$%C'#(F
'()*H,-.%/-#0%6 /(+*C !" #$ "%#C '()*H,-.%/-#M%6 /(+*C
*#C%+
8H#MV-.%/-#M%=>N
'()*H,-.%/-#0%P !" #$ "%#C !" #$ "%#C
'()*H,-.%/-#0%7 !"#"$%&'()'*+ '()*H,-.%/-#M%7
00001FFF
!""#$%&G
00001000
RISC-V
Microarchitecture
Simplified Example
• Simplified RV32I core that supports following subset
of instructions:
– ALU Instructions: add, sub, and, or, slt,
addi, andi, ori, slti
– Memory Instructions: lw, sw
– Branch Instructions: beq, jal
RISC-V Single-Cycle
Processor
Single-Cycle Processor
OP;S. !T#
D>U?LB;S.
A>"DI
34*FI4MMDI C=4D>U?LB;S.
g9N
eI C=4Pd7BSdL*9N
*F9*-
a?7.B+ C=4;S.*9N
+N
a?7.BWE !"";S.*9N
!"# .LM aL@BU D>BISCB>
#c
* OPM>AB
N OP .LM
*K9*E D*
C* I#+ DE* N ;S.C
!7UBS
C DE 34RS * C=4D>U?LB
!"#
-F9-N
N !#4D>U?LB
C- DE- N ;S.< !#4CRS N
D- *
!$%&
**9W
C+ * *
IE+ ID-.LMD
D>@RE@B@
.LM U9#
C I#
IE DE
+*9W !""#AB
DEFD*+ 1O!&
OPOL?UF
i
F *F9*- a?7.B+
D>U?LB
%&#$' !!#+ * S
!""#$$' !""#$%&%'
%! * %&#$' !!#+ ! (
!""#$(' !""#$$&$'
%! %&#$& !"#!$ ! )
!""#)$&$('
%! !"#!$ $& %&#$' $,#$! ! J
!""#(%' !""#$*&$'
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
!II-.$*+E$
76 RISC-V System-on-Chip Design Chapter 2 RISC-V
ALU Operations
ALUControl[1] ALUControl[0] Funct3 ALUResult
(Sub) (ALUOp)
0 0 x add
0 1 000 add
0 1 110 or
0 1 111 and
1 1 000 sub
1 1 010 slt
cM7OI
?O]+IA G*SB
!"#U9W*PJ7OI
U9W*PJ7OI
!"#A ;9S<O=J9
ABC'E %&D()&* !"#7OI
aCE
RSS7OI4'E
U9[<O=J9
!"#AB
+,-
F*+IJ.L'E !"#M1+JO1P4'E
%&D()&*
F*+IJBC
!"#$%"&&'%
RISC-V Pipelined
Processor
Pipelined Processor
!9? @A? *>BLSCB>L
OP;SC# CDE CDE CDE
*>BLSCB># *>BLSCB>A
*>U?DB;SC# *>U?DB;SCA *>U?DB;SCL
A>"*L# A>"*LA
1OED*O..%* F=4*>U?DB;SC#
g9N
eI F=4Pc7BScD#
-I9-M
a?7CB. F=4;SC#
.N
a?7CBWE !"";SC+
aD@BU
aD@BU#
!U? OP CDE
CDE CDE
-h9-E
F- L#. *+- NN a;SCF#
- OPd>ABa !7UBS+ N- N ;SCF#
F *+ -N
N -
#d
1O34 F=4*>U?DB#
!"#
MI9MN
FM *+M NN N !#4*>U?DBA
N- !#4FRS# N
--9W N ;SC<# -
!"#$ F. -N
-
a;SC<#
-
L+. *%+I-.%
CDE
*>@R+@B@L
F L#
L+ *+
.-9W !""#AB#
%&D%EF
LM!$
i
P=*
#d
P=*
P=*
#d
#d
#d
!9?
*>U?DBL
acSM@SRF#
acSM@SR<#
aD?UkL
aD?UkA
aD?Uk+
aD?Uk#
;B@DDL
;B@DDA
;B@DD+
;B@DD#
;B@DDa
RSTS*F
"?#
cTd.
FC
TU D(I
RR#
?T
RR#
D(F*+$I >9#
!C HBD*AW
!4$
!"#
!$# !"#$%C A-<
HM;
RF#
$4$ BIBD-CM*@a-@MCb
$T#
CL2W
WLM;M<B=BH U94
E2S2LH
RISC-V Market
Rapidly Changing Market
• 2010: RISC-V developed at Berkeley
• 2011: First RISC-V chip fabricated in 28 nm
• 2015: RISC-V Foundation launched
• 2015: SiFive founded by RISC-V inventors
• 2021: 12 billion RISC-V cores shipped in commercial products
• 2022: Seimco Research forecasts 40% annual growth through
2030