SysIntro
Insturctions
Arithmetic/Logistic Instructions
add x1,x2,x3 等价于 x1 = x2 + x3
subi x1,x1,1 等价于 x1 = x1 - 1
xor x1,x1,x1 等价于 x1 = 0
Data Transfer Insturctions
Load a 32-bit word: lw rd, offset(rs1) # offset访问数组元素
Save a 32-bit word: sw rs2, offset(rs1)
Address is given by a base register and a signed offset immediate
Effective address is a byte address = register value + offset
* a = b + c[2] # assume all are 32-bit int value/pointer/array
lw x28 , 8(x3) # 从c2加载数据到x28 , 8(x3) 中 x3是存储c的地址,8意味着跳过c中c[0]c[1]两个数,一共是62bit = 8 byte
add x28 , x2, x28 # c[2]+b
sw x28 , 0(x1) # 存入a(x1)
struct Student { int id; int score;#偏移4字节 } sturct Student s; int y = s.score
lw x6,4(x7)
Accessing Arrays
a[i] = x ; i++;
slli x28,x1,2 # x28 = i*4 左移2位=乘以4(2的2次方)
add x29,x2,x28 # x29 = a+4*i
sw x3,0(29) # a[i] = x
addi x1 , x1 ,1 # i++
Changing Program Control Flow
beq rs1 , rs2, label
rs1,rs2是要比较的两个寄存器,label表示如果rs1==rs2要跳转到的地方
bne rs1 , rs2, lanel
rs1,rs2是要比较的两个寄存器,label表示如果rs1!=rs2要跳转到的地方
j L
跳转到L标签
Two Memories
Primary storage
a.k.a., main memory, or simply memory
o Fast but volatile (断电了会丢失内容)
o Used to temporarily store data during program execution
o Accessed through load and store instructions issued by processor (hardware)
o Implemented with DRAMand optimized bySRAMcaches
### DRAM
内存小但更快
cache
### SRAM
内存大但更慢、
main memory
Secondary storage
a.k.a., external storage (treated as I/O devices)
o Slowbutnon-volatile (断电不会丢失内容)
o Used to permanently keep data required/generated (input/output) by programs
o Accessed through and managed byfile systems in OS (software)
o Implemented with disks and/or SSD
Locality
Temporal locality(locality in time)
如果某个数据或指令最近被访问过,那么它在短时间内可能会再次被访问。
Spatial locality(locality in space)
如果某个数据或指令被访问过,那么它附近的数据或指令很可能在不久后也会被访问。
Not Always Locality
Pointer chasing
上一个节点的地址与下一个节点的地址在物理上是不相关的
Cache
Access Miss
❑ Compulsory/cold – the first time the block is referenced
一开始啥也没有
❑ Capacity – not enough room in the cache to hold all blocks
o I.e., this miss would disappear if the cache were big enough
❑ Conflict – item was replaced because of a location conflict with others
o I.e., this miss would disappear with higher associativity