Lec 7 part2 · Lec 8 · pipelined control 과 data hazard·stall
정밀 정리 · 검증 2026-09-24 16:16
1개요
1.1전반부(Lec7 part2): pipeline register 내용, write register ID 를 WB 까지 전달하는 수정, pipeline 표현 세 가지, pipelined control 전달 방식.
1.2후반부(Lec8): data dependence RAW·WAR·WAW, in-order pipeline 에서는 RAW 만 hazard (ISA 의 순차·atomic semantics 와 pipeline 겹침의 불일치).
1.3RAW hazard 조건 dist(I_OLD, I_YOUNG) ≤ dist(ID, WB) = 3, memory data hazard 는 없음.
1.4해결책 pipeline stall: upstream 정지·downstream drain, PC·IR latch 비활성, bubble 의 RegWrite·MemWrite = 0, stall condition 식(use_rs 의 x0 제외).
2섹션별 정리 상황·문제 → 원인 → 해결
2.10:03–2:29시작 (캠퍼스 네트워크 장애 안내)
상황·문제campus 대상 virus attack 으로 Zoom 이 끊길 수 있어 연구실에서 강의, 녹화본은 PLMS 에 올린다고 안내.
2.22:29–6:35pipelined datapath 복습: 5 stage 와 pipeline register
상황·문제single-cycle CPU 를 IF·ID·EX·MEM·WB 5 stage 로 나누고 stage 사이에 pipeline register(IF/ID, ID/EX, EX/MEM, MEM/WB)를 둔다.
원인다음 stage 가 쓸 값은 모두 pipeline register 로 넘겨야 한다.
해결IF/ID: PC, IR / ID/EX: A, B, imm, PC / EX/MEM: ALUOut, B, next PC / MEM/WB: memory data, ALUOut. LD 를 stage 별로 따라가며 확인.
- IF/ID 에는 PC 와 instruction register
- ID 에서 imm 생성·register read, EX 에서 address 계산, MEM read, WB 로 register file 기록
2.2.r.1Classic RISC pipeline (Wikipedia) ↗ · IF·ID·EX·MEM·WB 5-stage pipeline, bypassing(forwarding), load 뒤 stall
2.2.r.2Harvard architecture (Wikipedia) ↗ · instruction/data memory 분리 → 같은 cycle 에 fetch 와 data access
2.36:35–9:00write register ID 문제와 수정
상황·문제LD 의 WB 에서 register file 의 write register ID 가 IF/ID 의 instruction(다른, 더 젊은 instruction)에서 온다.
원인rd 를 decode 시점에 바로 쓰면 WB 시점에는 이미 다른 instruction 의 필드가 된다.
해결destination register ID 를 ID stage 에서 pipeline register 에 넣어 WB 까지 전달한 뒤 register file 에 준다.
- write register ID 도 data 처럼 pipeline 을 따라 전달
2.3.r.1Classic RISC pipeline (Wikipedia) ↗ · IF·ID·EX·MEM·WB 5-stage pipeline, bypassing(forwarding), load 뒤 stall
2.49:00–13:15두 instruction 예와 pipeline 표현 세 가지
상황·문제lw 뒤 sub 가 한 cycle 씩 겹쳐 진행되는 clock 1~6 예를 본 뒤, pipeline 동작을 나타내는 diagram 을 소개.
해결graphical view(x=clock cycle, y=program 순서), 단순화된 stage 이름 표, resource view(y=stage, 칸에 instruction)를 이후 hazard 설명에 사용.
- resource view: 각 cycle 에 어느 stage 에 어느 instruction 이 있는지 표시
2.513:15–18:36pipelined control
상황·문제control signal 은 single-cycle 과 같지만, ID 에서 만든 값이 EX·MEM·WB 등 각기 다른 stage·cycle 에 쓰인다.
원인생성 시점과 사용 시점이 달라 제때 해당 stage 에 전달해야 한다.
해결(1) ID 에서 한 번 decode 해 EX·M·WB control 을 pipeline register 로 전달, 또는 (2) instruction(필요한 field 만)을 전달해 stage 별 local decode. cost 가 낮은 쪽 선택.
- register read 관련 control 은 ID 에서 바로 사용
- WB control 은 ID/EX → EX/MEM → MEM/WB 를 따라 전달
2.5.r.1Classic RISC pipeline (Wikipedia) ↗ · IF·ID·EX·MEM·WB 5-stage pipeline, bypassing(forwarding), load 뒤 stall
2.618:36–21:36pipelining 의 현실 다시 보기
상황·문제이상적 pipeline 조건(동일 연산, 균일 sub-operation, 독립 연산)이 instruction pipelining 에선 성립하지 않는다.
원인instruction 마다 하는 일이 다르고, memory read 와 addition 의 시간이 다르며, instruction 사이 dependence 가 있다.
해결instruction type 을 묶어 모든 stage 를 multi-function 으로, stage latency 를 균형 있게, dependence 는 검출·해결 (오늘의 주제).
- dependence 처리가 CPU 정확성을 위한 핵심
2.6.r.1Hazard (computer architecture) (Wikipedia) ↗ · RAW·WAR·WAW data hazard 와 bubble·forwarding 해결
2.721:36–27:41출석·Q&A (한국어 보충)
상황·문제출석 확인 후 한국어로 보충: instruction type 을 묶는 것은 pipeline 구현 복잡도를 줄이려는 ISA 설계이며, stage 마다 일의 양이 달라도 clock cycle 은 같아 가장 긴 stage 에 맞춘다.
- 세탁 예: 세탁 50분·건조 55분이어도 cycle 은 하나로 맞춤
2.827:41–37:13Lec8 · data dependence 세 가지
상황·문제Lec8(Pipelined CPU – Data Hazard) 시작. pipeline 안의 instruction 들 사이에 dependence 가 있다.
원인RAW(true dependence): 뒤 instruction 이 앞 instruction 이 쓴 r3 를 읽음. WAR(anti), WAW(output) 는 같은 register ID 를 쓰는 것뿐 true dependence 아님.
해결RAW 가 오늘 주제: 뒤 instruction 의 ID(register read)가 앞 instruction 의 WB 보다 먼저 올 수 있다. WAR·WAW 는 out-of-order 실행에서만 문제.
- control dependence 는 이후 강의
- in-order pipeline 에서는 WAR·WAW 문제 없음
2.937:13–42:53RAW hazard 예와 원인: 순차·atomic semantics 불일치
상황·문제addi 가 ra 에 쓰고 뒤따르는 addi 들이 ra 를 읽는 예: 첫 instruction 의 WB 는 t4 인데 둘째는 t2 에 읽어 옛 값을 얻는다.
원인ISA 는 instruction 이 순차적·atomic 하게 실행된다고 정의하지만, pipeline 은 sub-operation 을 겹쳐 실행해 순서가 보존되지 않는다.
해결뒤 3개(2~4번째)만 문제, 5번째부터는 WB 이후 읽으므로 안전. architecture 와 microarchitecture 의 불일치가 hazard 의 원인.
- i1 의 WB 가 i2 의 ID 보다 먼저여야 함
- true dependence 는 특정 sub-operation 의 순서만 요구
2.9.r.1Hazard (computer architecture) (Wikipedia) ↗ · RAW·WAR·WAW data hazard 와 bubble·forwarding 해결
2.1042:53–49:34register data hazard 조건 분석
상황·문제instruction type 별로 register read(ID)·write(WB) 가 언제 일어나는지 표로 정리하고, hazard 발생 조건을 찾는다.
원인dependence type, 관련 instruction type, instruction 사이 거리가 hazard 여부를 결정한다.
해결I_YOUNG(R/I, LD, SD, Bxx, JALR)이 I_OLD(R/I, LD, JAL, JALR)가 쓰는 register 를 읽고 dist(I_OLD, I_YOUNG) ≤ dist(ID, WB) = 3 이면 RAW hazard.
- SD·Bxx 는 write 없음, JAL 은 read 없음
- dist(i,j) > dist(X,Y) 면 안전
2.10.r.1Hazard (computer architecture) (Wikipedia) ↗ · RAW·WAR·WAW data hazard 와 bubble·forwarding 해결
2.1149:34–50:53memory data hazard 는 없다
상황·문제load·store 사이에 memory 를 통한 hazard 가 생길 수 있는지 질문.
원인memory read·write 가 모두 같은 MEM stage 에서 일어나 stage 거리가 0.
해결현재 pipeline 에서는 memory data hazard 불가능.
2.1250:53–56:11pipeline stall: 기본 해결책
상황·문제dist(i,j)=1, dist(ID,WB)=3 인 예: j 는 t3 에 register 를 읽지만 i 의 WB 는 t5.
원인i 의 WB 전에 j 가 ID 를 하면 옛 값을 읽는다.
해결j 의 ID 를 늦추며 bubble 을 넣어 dist 를 4 로 만들면(bubble 3개) WB 이후 최신 값을 읽는다. 앞선 instruction 은 계속 진행.
- stall 은 CPU 전체 정지가 아님
- stall 된 instruction 뒤의 instruction 도 함께 멈춤
2.1356:11–1:01:36how to stall: upstream 정지, downstream drain
상황·문제stall 을 실제 hardware control 로 어떻게 구현하나.
원인bubble 이 만드는 쓰레기 값이 architectural state(memory, register file)를 바꾸면 안 된다.
해결IF·ID(upstream)는 PC·IR latching 을 끄고, EX·MEM·WB(downstream)는 계속 진행(drain). bubble 의 RegWrite·MemWrite 를 0 으로 넣어 pipeline register 로 전달.
- PC 가 그대로면 같은 instruction 을 다시 fetch
- bubble 이 MEM·WB 에 도달해도 memory·register file 변경 없음
2.141:01:36–1:11:15Q&A: out-of-order, drain, stall 구현 (한국어 보충)
상황·문제의존 없는 더 젊은 instruction 을 먼저 실행하면? → 그것이 out-of-order execution, 이후 간단히 다룸. drain 은 막힌 지점 뒤(downstream)의 물이 계속 흘러 나가는 것.
해결IR·PC register 의 enable 을 막아 j·k 를 유지하고, bubble 의 write enable 을 0 으로 두면 control signal pipeline 이 알아서 전달한다고 한국어로 재설명.
2.14.r.1Out-of-order execution (Wikipedia) ↗ · OoO 실행에서 WAR·WAW false dependency 와 register renaming
2.151:11:15–1:17:32when to stall: stall condition 식
상황·문제ID 의 I_YOUNG 이 EX·MEM·WB 에 있을 수 있는 I_OLD 가 쓸 register 를 읽으려 하면 ID 에서 stall 해야 한다.
원인rs1·rs2 각각이 EX·MEM·WB stage 의 rd 와 같고 그 stage 가 RegWrite 이면 RAW hazard.
해결stall = OR of (rs{1,2}_ID == rd_{EX,MEM,WB}) && use_rs{1,2}(IR_ID) && RegWrite_{EX,MEM,WB}. use_rs1(I) 는 rs1 을 쓰고 rs1 != x0 일 때 참 (x0 는 항상 0).
- stall 동안 EX·MEM·WB 는 정상 진행(drain)
- 다음 강의에서 계속
2.15.r.2Hazard (computer architecture) (Wikipedia) ↗ · RAW·WAR·WAW data hazard 와 bubble·forwarding 해결
3핵심 개념
3.1pipeline register(파이프라인 레지스터)
IF/ID, ID/EX, EX/MEM, MEM/WB. 다음 stage 에 필요한 data·control·rd 를 보관.
3.1.r.1Classic RISC pipeline (Wikipedia) ↗ · IF·ID·EX·MEM·WB 5-stage pipeline, bypassing(forwarding), load 뒤 stall
3.2pipelined control(파이프라인 제어)
ID 에서 decode 한 EX·M·WB control 을 pipeline register 로 전달하거나 instruction field 를 넘겨 stage 별 decode.
3.2.r.1Classic RISC pipeline (Wikipedia) ↗ · IF·ID·EX·MEM·WB 5-stage pipeline, bypassing(forwarding), load 뒤 stall
3.3true dependence / RAW(진정한 의존성)
뒤 instruction 이 앞 instruction 이 쓴 register 를 읽음. in-order pipeline 에서 hazard 를 만든다.
3.4anti / output dependence(WAR / WAW)
같은 register ID 를 써서 생기는 dependence. out-of-order 실행에서만 문제.
3.5RAW hazard 조건
I_YOUNG 이 I_OLD 가 쓰는 register 를 읽고 dist(I_OLD, I_YOUNG) ≤ dist(ID, WB) = 3.
3.5.r.1Hazard (computer architecture) (Wikipedia) ↗ · RAW·WAR·WAW data hazard 와 bubble·forwarding 해결
3.6pipeline stall / bubble(파이프라인 스톨 / 버블)
hazard 가 사라질 때까지 뒤 instruction 을 멈추고 빈 slot(bubble)을 흘림.
3.7drain(드레인)
stall 중 downstream(EX·MEM·WB) instruction 은 계속 진행해 pipeline 을 빠져나감.
3.8stall condition(스톨 조건)
(rs_ID == rd_EX/MEM/WB) && use_rs(IR_ID) && RegWrite_EX/MEM/WB 를 rs1·rs2 에 대해 OR. use_rs 는 x0 제외.
3.8.r.1Hazard (computer architecture) (Wikipedia) ↗ · RAW·WAR·WAW data hazard 와 bubble·forwarding 해결
4스스로 확인
4.1LD 의 WB 에서 write register ID 를 IF/ID 의 instruction 에서 가져오면 왜 틀리나?
답
그 시점 IF/ID 에는 다른(더 젊은) instruction 이 있다. rd 를 pipeline register 로 WB 까지 전달해야 한다.
4.2WAR·WAW dependence 가 5-stage in-order pipeline 에서 문제가 안 되는 이유는?
답
앞 instruction 이 이미 register 를 읽거나 쓴 뒤에 뒤 instruction 이 쓰기 때문. out-of-order 실행에서만 순서가 바뀐다.
4.3dist(i,j)=1 인 RAW hazard 에서 bubble 은 몇 개 필요한가?
답
dist(ID,WB)=3 이므로 dist 를 4 로 만들 bubble 3개.
4.4memory data hazard 가 이 pipeline 에서 생기지 않는 이유는?
답
memory read·write 가 모두 MEM stage 에서 일어나 stage 거리가 0 이다.
4.5stall 시 bubble 이 architectural state 를 바꾸지 않게 하려면?
답
PC·IR latch 를 끄고, bubble 의 RegWrite·MemWrite control 을 0 으로 pipeline register 에 넣는다.
4.6use_rs1(I) 가 rs1 != x0 를 확인하는 이유는?
답
x0 는 항상 0 이라 write 가 영향을 주지 않으므로 dependence 가 없다.
5참고 자료
5.1Computer Organization and Design RISC-V Edition (Elsevier) ↗ · P&H 교재 (Ch 4.7 pipelined datapath·control, Ch 4.8 data hazard 읽기 과제)
5.2Classic RISC pipeline (Wikipedia) ↗ · IF·ID·EX·MEM·WB 5-stage pipeline, bypassing(forwarding), load 뒤 stall



























