Why This Matters
Datapath 문제는 그림 암기가 아니라 data movement 추적입니다. `lw`, `sw`, `add`, `beq`가 같은 hardware 그림을 쓰지만 실제로 active한 path와 write destination은 다릅니다.
시험에서는 active components, mux choices, control signals, critical path를 함께 묻습니다. 신호 이름을 외워도 `rs1`, `rs2`, `rd`, immediate의 역할을 못 나누면 표가 틀립니다.
Performance 단원과도 연결됩니다. Single-cycle에서는 가장 긴 instruction path가 전체 Taktperiode를 정합니다.
Full beginner lecture
Single Cycle Datapath
Beginner Intuition
Single-cycle datapath(Ein-Takt Datenpfad)는 instruction 하나가 한 clock cycle 안에서 fetch, decode, execute, memory, writeback을 모두 끝내는 모델입니다. 처음 그림을 보면 box와 선이 많아서 복잡하지만, 시험에서 묻는 질문은 보통 같습니다. "이 instruction은 어디에서 값을 읽고, 어디에서 계산하고, 어디에 결과를 쓰는가?"
add, lw, sw, beq를 같은 그림 위에서 실행하지만 active path는 다릅니다. add는 register file과 ALU 중심입니다. lw는 ALU로 effective address를 만든 뒤 Data Memory를 읽고 rd에 씁니다. sw는 address 계산은 lw와 비슷하지만 memory에 쓰고 register writeback은 없습니다. beq는 register 두 값을 비교하고 PC source를 고릅니다.
Active Datapath Board
Common fetch:
PC -> Instruction Memory -> instruction bits
PC -> PC+4 adder -> PC mux
add rd, rs1, rs2:
Reg[rs1], Reg[rs2] -> ALU -> WB mux(ALU) -> Reg[rd]
lw rd, imm(rs1):
Reg[rs1] + SignExt(imm) -> ALU address
Data Memory[address] -> WB mux(memory) -> Reg[rd]
sw rs2, imm(rs1):
Reg[rs1] + SignExt(imm) -> ALU address
Reg[rs2] -> Data Memory[address]
no rd writeback
beq rs1, rs2, imm:
Reg[rs1] vs Reg[rs2] -> ALU compare
PC + branch immediate -> PC mux if condition true
Control-Signal Board
| Instruction | RegWrite | MemRead | MemWrite | ALUSrc | MemToReg/ResultSrc | Branch/PCSrc |
|---|
add rd, rs1, rs2 | 1 | 0 | 0 | 0 | ALU | 0 |
addi rd, rs1, imm | 1 | 0 | 0 | 1 | ALU | 0 |
lw rd, imm(rs1) | 1 | 1 | 0 | 1 | Memory | 0 |
sw rs2, imm(rs1) | 0 | 0 | 1 | 1 | X | 0 |
beq rs1, rs2, imm | 0 | 0 | 0 | 0 | X | condition-dependent |
이 표는 외우기보다 질문 순서로 채우세요.
- register에 쓰는가? 그러면
RegWrite=1. - Data Memory를 읽는가?
lw만 MemRead=1. - Data Memory에 쓰는가?
sw만 MemWrite=1. - ALU input B가 register
rs2인가 immediate인가? immediate면 ALUSrc=1. - register에 쓰는 값이 ALU result인가 memory data인가?
- PC가
PC+4가 아닌 target으로 갈 가능성이 있는가?
Worked Example 1: lw t0, 8(sp)
문제: sp = 0x1000, memory[0x1008] = 0xABCD1234일 때 active path와 control signal을 적으세요.
rs1 = sp, rd = t0, immediate = 8
ALU address = Reg[sp] + 8 = 0x1008
Data Memory read = memory[0x1008] = 0xABCD1234
Reg[t0] <- 0xABCD1234
Control:
RegWrite=1
MemRead=1
MemWrite=0
ALUSrc=1
MemToReg=1
Branch=0
검산: lw 답안에는 address calculation, memory read, rd writeback이 모두 있어야 합니다.
Worked Example 2: sw t0, 8(sp)
문제: sp = 0x1000, t0 = 0xABCD1234일 때 active path와 control signal을 적으세요.
rs1 = sp, rs2 = t0, immediate = 8
ALU address = Reg[sp] + 8 = 0x1008
memory[0x1008] <- Reg[t0] = 0xABCD1234
Register writeback: none
Control:
RegWrite=0
MemRead=0
MemWrite=1
ALUSrc=1
MemToReg=X
Branch=0
검산: sw에서 rd를 만들거나 RegWrite=1을 쓰면 store의 의미를 거꾸로 본 것입니다.
Worked Example 3: beq s1, s2, label
PC = 0x2000
s1 = 42
s2 = 42
branch immediate = 0x10
beq는 s1 == s2이면 taken입니다. 따라서 condition은 true이고 next PC는 0x2000 + 0x10 = 0x2010입니다. 이때 register writeback과 data memory access는 없습니다. 답안에는 condition comparison과 target calculation을 분리해서 적어야 합니다.
Critical Path
Single-cycle에서는 모든 instruction이 같은 clock을 씁니다. 그래서 clock period는 평균 instruction이 아니라 가장 느린 active path가 정합니다.
T_c >= max(path delay of add, addi, lw, sw, beq, ...)
보통 lw path가 깁니다.
PC -> Instruction Memory -> Register File
-> ALU address -> Data Memory -> WB mux -> Register File setup
Common Mistakes
MemRead를 Instruction Memory fetch로 착각합니다. control table의 MemRead는 보통 Data Memory read입니다.ALUSrc를 "ALU를 쓰는가?"로 해석합니다. 실제 의미는 ALU의 두 번째 input source입니다.sw에 RegWrite=1을 켭니다. store는 memory write이지 register result가 아닙니다.- branch target 계산과 branch condition 비교를 한 줄로 섞습니다. 둘은 다른 hardware path입니다.
Active Recall
lw와 sw가 공통으로 사용하는 datapath 구간은 무엇인가요?add에서 Data Memory가 active하지 않은 이유는 무엇인가요?ALUSrc=1이 되는 대표 instruction 세 개를 말해 보세요.- Single-cycle에서
add도 lw가 정한 긴 clock을 쓰는 이유는 무엇인가요?
Source Grounding
current:Vorlesung\Rechnerorganisation - Teil 2.pdf: Ein-Takt processor, control signals, datapath components, critical path.current:Uebung\Übung 5.pdf: performance와 single-cycle basics.current:Uebung\Übung 6.pdf, current:Uebung\Lösung 6.pdf: single-cycle control table, critical path, delay calculation.