SoSe25 Exam Overview

Aufgabe 7 · 15 points · hazard

Aufgabe 7 - Pipelined Prozessor

Original German, Korean translation, method, source-grounded solution, recall-answer audit, wrong-answer explanations, active recall, and source citations are separated below.

complete

Related Concepts and Current Sources

Weak-topic hook

No active weak-topic rows currently map to this Aufgabe.

Subproblem learning view

소문제별 1타 강사식 풀이 교실

문제를 읽은 직후 필요한 개념을 직관적으로 잡고, 같은 순서로 손풀이를 재현하도록 구성했습니다.

Teilaufgabe

7a

4 points

Original German

Der folgende RISC-V-Code wird auf einem Pipeline-Prozessor ausgefuehrt mit dem Parameter a0 = 2. Gehen Sie davon aus, dass alle Spruenge korrekt vorhergesagt werden und es keine Control Hazards gibt. In der Klausur war laut Recall eine Skizze des Pipeline-Prozessors aus der Vorlesung gegeben.

clog2:
   beqz a0, .Lret   #0
   li t0, 0         #1
.Lloop:
   srli a0, a0, 1   #2
   beqz a0, .Lend   #3
   addi t0, t0, 1   #4
   j .Lloop         #5
.Lend:
   mv a0, t0        #6
.Lret:
   ret              #7
  1. Zu welchem Zeitpunkt entsteht der erste Data Hazard? Tragen Sie die Nummer der entsprechenden Instruktion in die jeweilige Pipeline-Stufe ein.
  2. Welche Instruktionen sind am Hazard beteiligt?

Normalisierungsnotiz: Im Recall steht mv, a0, t0; das Komma nach mv ist ein Syntaxfehler. Gemeint ist der Pseudobefehl mv a0, t0.

한국어 문제

a0 = 2인 상태에서 아래 RISC-V 코드가 Pipeline-Prozessor에서 실행된다. 모든 Sprung/Branch는 올바르게 예측되어 Control Hazard는 없다고 가정한다. 첫 Data Hazard가 언제 생기는지 Pipeline-Stufe에 명령 번호를 적고, 어떤 두 명령이 그 Hazard에 관여하는지 답하라.

한 줄 핵심

dynamic instruction sequence를 먼저 펼친 뒤 producer와 consumer가 같은 register를 사용하는 최초 RAW hazard를 찾는다.

0. 초보자 개념 다리

hazard는 앞 instruction이 아직 쓰지 않은 답을 뒤 instruction이 읽으려는 상황이다.

1. 이 문제의 풀이 루틴

  1. branch 결과로 dynamic sequence를 펼친다.
  2. 각 instruction의 destination/source를 적는다.
  3. 같은 register의 최초 write→read 쌍을 찾는다.
  4. 생성 stage와 필요 stage를 표시한다.

2. 왜 이 방법이 맞을까?

RAW hazard는 값이 프로그램 순서로는 앞서지만 pipeline timing상 아직 준비되지 않을 때 생긴다.

3. 시험장 실수 방지

실행되지 않은 경로의 instruction은 세지 않는다.

최대 상세 해설 · 7a 깊이 학습: `clog2`의 첫 RAW Data Hazard 찾기

이 강의의 도착점

a0=2의 dynamic instruction 흐름을 먼저 만든 뒤 destination/source register를 비교하여 첫 RAW Hazard가 static #2 srli#3 beqz 사이의 a0 의존성임을 찾고, F/D/E/M/W snapshot에 번호를 배치한다.

0. 정말 아무것도 모른다면 여기서 시작

  • Pipeline Hazard를 찾을 때 code 전체를 한눈에 보며 register 이름을 세지 않는다. 실제 실행 순서에서 앞 instruction이 무엇을 쓰고 바로 뒤 instruction이 무엇을 읽는지를 한 쌍씩 검사한다.
  • srli a0,a0,1은 새 a0를 만들고, 바로 다음 beqz a0,.Lend는 그 새 값을 검사해야 한다. 뒤 instruction이 앞 instruction의 결과를 읽는 이 관계가 RAW(Read After Write)다.
  • 이 문제는 F/D/E/M/W 다섯 stage, correct prediction으로 Control Hazard penalty 없음, 현행 강의의 Execute forwarding 모델을 기준으로 설명한다. 첫 hazard를 보이는 cycle-5 snapshot은 F:#4, D:#3, E:#2, M:#1, W:#0이다.
  • SoSe25 원문은 공식 Klausur/Musterlösung이 아닌 Gedächtnisprotokoll이고 원래 pipeline sketch도 남아 있지 않다. 회상 답의 4,3,2,1,0은 현행 다섯-stage 순서로 해석하면 대조되지만, 당시 그림의 정확한 box 위치·branch comparison 위치·채점 표시는 공식 확인되지 않았다.

1. 문제에 나오는 말부터 하나씩

Pipeline-Stufe F/D/E/M/W
Fetch, Decode, Execute, Memory, Writeback의 다섯 단계. 여러 dynamic instruction이 같은 cycle에 서로 다른 stage에 놓인다.
RAW Data Hazard
나중 instruction이 먼저 instruction이 아직 만들어 전달하지 않은 register 값을 읽으려는 Read After Write 의존성.
Producer
의존값을 쓰는 older instruction. 첫 hazard에서는 #2 srli가 새 a0의 producer다.
Consumer
그 값을 읽어야 하는 younger instruction. 첫 hazard에서는 #3 beqz가 a0 consumer다.
dynamic instruction
실행 중 실제로 한 번 나타난 instruction instance. loop의 같은 static #2도 첫 번째와 두 번째 실행은 서로 다른 dynamic instance다.
Forwarding
결과를 Register File Writeback까지 기다리지 않고 뒤 stage에서 consumer의 Execute input으로 직접 전달하는 경로.
Control Hazard
branch/jump의 다음 PC가 불확실해서 생기는 문제. 이 recalled task는 모든 jump가 correctly predicted라고 가정해 이를 제외한다.

2. 선생님과 같이 한 칸씩 푸는 과정

  1. 번호 기준을 고정한다. 회상 code의 #0부터 #7까지 각 pseudo line을 이 문제에서는 instruction 하나로 취급한다. 실제 assembler expansion 수를 새로 만들어 세지 않는다.
  2. a0=2에서 첫 네 dynamic instruction만 값으로 trace한다: #0 beqz는 not taken, #1 li는 t0=0, #2 srli는 a0를 2에서 1로 만들고, #3 beqz는 그 1을 읽어 not taken을 결정한다.
  3. 각 줄의 write/read를 적는다. #2: read a0, write a0. #3: read a0, write register 없음. 따라서 #2→#3에 a0 RAW edge를 그린다.
  4. 더 이전 후보를 확인한다. #0은 a0를 읽기만 하고, #1은 t0를 쓰지만 #2는 t0를 읽지 않는다. 그러므로 #2→#3가 시간상 첫 producer-consumer register 의존성이다.
  5. Pipeline 표를 cycle 1부터 한 칸씩 민다. cycle 1은 F#0, cycle 2는 F#1/D#0, cycle 3은 F#2/D#1/E#0, cycle 4는 F#3/D#2/E#1/M#0이다.
  6. cycle 5에 F#4, D#3, E#2, M#1, W#0가 된다. #3이 a0를 해석/필요로 하는 동안 #2의 새 a0는 아직 normal Writeback에 도달하지 않아 RAW dependency가 드러난다.
  7. 현행 Execute-stage comparison/forwarding 모델에서는 다음 cycle에 #3이 E에 있고 #2가 M에 있을 때 #2의 ALU result를 forward할 수 있다. 그래서 dependency는 존재하지만 이 산술 producer 때문에 반드시 stall이 생기는 것은 아니다.
  8. 두 번째 loop에서도 같은 #2→#3 hazard가 다시 생기지만 문제는 첫 시점을 묻는다. static 번호가 같아도 첫 dynamic occurrence를 답으로 쓴다.
  9. 답에는 번호만 쓰지 말고 register와 방향을 붙인다: #2 (producer) → #3 (consumer), RAW on a0.
  10. 마지막 한계 문장을 붙인다. snapshot은 회상 순서와 현행 F/D/E/M/W pipeline을 대조한 것이며 원본 Klausur pipeline sketch는 확인되지 않았다.

3. 그래서 정답은 무엇인가?

첫 Data Hazard는 static instruction #2 srli a0,a0,1이 만든 새 a0를 바로 다음 #3 beqz a0,.Lend가 읽는 RAW Hazard다.

현행 다섯-stage F/D/E/M/W 순서로 cycle 5를 쓰면:

Cycle 5
Fetch:     #4  addi t0,t0,1
Decode:    #3  beqz a0,.Lend     <- consumer
Execute:   #2  srli a0,a0,1      <- producer
Memory:    #1  li t0,0
Writeback: #0  beqz a0,.Lret

즉 회상 답의 4,3,2,1,0은 stage order가 F,D,E,M,W일 때 이 snapshot으로 해석할 수 있다. 현행 Execute-forwarding 모델에서는 다음 cycle의 M→E forwarding으로 이 arithmetic-to-branch dependency를 공급할 수 있다. 다만 공식 SoSe25 그림은 남아 있지 않으므로 정확한 당시 box layout이나 branch decision stage를 공식 정답처럼 단정하지 않는다.

4. 이제 정확한 개념으로 한 단계 더 깊게

  • Hazard와 stall은 같은 말이 아니다. register dependency인 RAW Hazard가 있어도 필요한 시점까지 forwarding할 수 있으면 stall cycle은 0일 수 있다.
  • 첫 hazard는 static code의 가장 가까운 같은 register 이름만으로 정하지 않는다. dynamic execution order에서 producer가 실제로 consumer보다 먼저 실행되는지 확인한다.
  • beqz a0,label은 a0를 읽는 conditional branch다. destination register가 없더라도 source dependency의 consumer가 될 수 있다.
  • srli a0,a0,1은 a0를 읽고 다시 a0에 쓰므로 source와 destination을 둘 다 register-use 표에 적어야 한다.
  • cycle snapshot은 instruction 번호의 방향을 명시해야 한다. 4,3,2,1,0만 쓰면 어느 숫자가 Fetch인지 Writeback인지 알 수 없다.
  • correct prediction 가정은 wrong-path flush를 없애지만 Data Hazard를 없애지는 않는다. #2→#3의 값 dependency는 prediction 정확도와 별개다.
  • 원래 sketch가 없으면 branch가 Decode에서 비교되는 변형인지 Execute에서 비교되는 변형인지 임의로 꾸미지 않는다. 본 가이드는 현행 자료의 Execute forwarding을 기본으로 하고 차이를 명시한다.

5. 시험장에서 그대로 쓰는 단계별 풀이

  1. 각 static line 옆에 read register와 write register를 적는다.
  2. a0=2를 code에 넣고 branch taken 여부가 결정될 때까지 dynamic sequence를 쓴다.
  3. 각 adjacent pair에 대해 older write와 younger read의 교집합을 찾는다.
  4. 처음 교집합이 나온 #2와 #3 사이에 RAW(a0) 화살표를 그린다.
  5. F/D/E/M/W 다섯 열에 cycle 1부터 instruction을 한 칸씩 민다.
  6. #3이 D, #2가 E에 동시에 놓인 cycle 5에서 다섯 stage 번호를 완성한다.
  7. forwarding이 가능한 값과 필요한 stage를 확인하되 hazard identification과 stall 판단을 분리한다.
  8. 답 끝에 producer #2, consumer #3, register a0 세 요소와 recall source 한계를 쓴다.

6. 예시와 변형 문제 연결

  • a0=2이면 첫 #2 뒤 a0=1이다. #3이 old value 2를 검사해도 결과는 우연히 not taken으로 같지만, dependency 자체가 사라지는 것은 아니다. 두 번째 #2에서는 1→0이라 old/new 값이 branch 결과까지 바꾼다.
  • li t0,0인 #1과 addi t0,t0,1인 #4도 RAW 관계지만 #2→#3보다 나중에 consumer가 나타나므로 ‘첫 hazard’ 답은 아니다.
  • cycle 6에서 current model은 #2가 M, #3이 E에 있다. #2의 ALU result 1을 #3 compare input으로 forward하면 Register File에 old a0가 남아 있어도 올바른 branch 판단이 가능하다.
  • 초기 a0=0이라면 #0가 taken되어 곧바로 #7 ret로 가므로 #2와 #3은 실행되지 않는다. Hazard 분석은 주어진 input이 만드는 dynamic path에 의존한다.

7. 독일어 만점 답안 템플릿

Der erste RAW-Data-Hazard entsteht zwischen #2 srli a0,a0,1 als Producer und #3 beqz a0,.Lend als Consumer auf dem Register a0. Im aktuellen F/D/E/M/W-Modell lautet der relevante Schnappschuss in Zyklus 5: F:#4, D:#3, E:#2, M:#1, W:#0. Korrekte Sprungvorhersage beseitigt nur Control-Hazard-Strafen, nicht diese Datenabhängigkeit. Die originale SoSe25-Pipeline-Skizze ist im Gedächtnisprotokoll nicht erhalten; die Stufenzuordnung ist die mit aktuellen Unterlagen geprüfte Rekonstruktion.

8. 자주 나오는 오답과 교정

  • #1→#4의 t0 dependency를 첫 hazard라고 쓰기: 실제 dynamic 순서에서는 #2→#3의 a0 RAW가 먼저 나타난다.
  • beqz는 register를 쓰지 않으므로 Data Hazard와 무관하다고 생각하기: branch도 source register를 읽는 consumer다.
  • correct prediction이 모든 hazard를 없앤다고 쓰기: 제거되는 것은 Control Hazard penalty이고 RAW dependency는 남는다.
  • 4,3,2,1,0만 답하고 stage 방향을 쓰지 않기: F/D/E/M/W인지 반대인지 해석할 수 없다.
  • hazard가 있으면 무조건 stall 1개라고 쓰기: forwarding availability와 value-needed stage를 따로 검사해야 한다.
  • static #2와 #3이 두 번 실행된다는 사실을 무시하기: 첫 occurrence와 두 번째 occurrence는 별도 dynamic instances다.
  • 원래 pipeline sketch의 branch compare 위치를 상상해 공식 사실처럼 그리기: recall에는 sketch가 없으므로 current model 가정과 한계를 명시해야 한다.

9. 답을 보지 않고 확인하기

  1. RAW의 R, A, W는 각각 무엇을 뜻하는가?
  2. #2와 #3은 a0를 각각 어떻게 사용하는가?
  3. 왜 #1→#4가 dependency이면서도 첫 hazard 답은 아닌가?
  4. cycle 5의 F/D/E/M/W에는 각각 어떤 static 번호가 있는가?
  5. correct prediction 조건이 없애는 것과 없애지 않는 것은 무엇인가?
  6. 이 snapshot에서 공식 확인되지 않은 부분은 무엇인가?
확인문제 정답 보기
  1. Read After Write다. younger instruction의 read가 older instruction의 write 결과에 의존한다.
  2. #2는 old a0를 읽고 shifted result를 a0에 쓰는 producer이며, #3은 그 new a0를 읽어 zero인지 검사하는 consumer다.
  3. #4가 t0를 읽는 시점보다 #3이 a0를 읽는 시점이 먼저 오므로 #2→#3이 첫 dynamic RAW다.
  4. F:#4, D:#3, E:#2, M:#1, W:#0이다.
  5. correct prediction은 wrong-path fetch/flush에 따른 Control Hazard penalty를 없애지만 register RAW dependency는 없애지 않는다.
  6. 공식 SoSe25 원본 pipeline 그림의 정확한 box layout, branch comparison stage와 공식 채점 표시다.

Interactive practice

Dynamic instruction trace

a0=2에서 실제 실행되는 10개 instruction을 순서대로 재생하세요.

Teilaufgabe

7b

2 points

Original German

addi s0, a0, 5
addi s1, s0, 4

Wie lange muss Decode angehalten werden (stalling), wenn:

  1. kein forwarding vorhanden ist?
  2. forwarding vorhanden ist?

한국어 문제

addi s0, a0, 5 바로 다음에 addi s1, s0, 4가 온다. Forwarding이 없을 때와 있을 때 Decode를 몇 Takte 멈춰야 하는지 구하라.

한 줄 핵심

forwarding 가능 시 ALU result를 바로 전달하고, forwarding이 없으면 consumer가 register writeback까지 기다리는 stall을 센다.

0. 초보자 개념 다리

forwarding은 결과를 register file에 넣었다 꺼내지 않고 생산 라인에서 바로 건네는 우회로다.

1. 이 문제의 풀이 루틴

  1. 결과 생성 stage와 필요 stage를 표시한다.
  2. forwarding 경로가 연결하는지 본다.
  3. 없으면 writeback까지 stall을 센다.
  4. load-use를 별도로 계산한다.

2. 왜 이 방법이 맞을까?

ALU result는 EX 뒤, load data는 MEM 뒤에 나와 준비 시점이 다르다.

3. 시험장 실수 방지

forwarding이 있어도 바로 뒤 load-use에는 보통 1 stall이 필요하다.

최대 상세 해설 · 7b 깊이 학습: arithmetic RAW의 stall을 forwarding 유무로 계산하기

이 강의의 도착점

연속된 두 addi의 producer/consumer timing을 F/D/E/M/W 표로 추적하여 현행 강의 모델에서 forwarding 없이는 Decode 2 Takte stall, forwarding 있으면 0 Takte임을 근거와 함께 설명한다.

0. 정말 아무것도 모른다면 여기서 시작

  • 첫 instruction은 s0를 만들고 바로 다음 instruction은 s0를 읽는다. 질문은 dependency가 있는지가 아니라 consumer가 필요한 순간에 값을 어디에서 받을 수 있는지다.
  • forwarding이 없으면 consumer는 Register File에 정식으로 writeback된 s0만 읽을 수 있다. 현행 Übung 모델은 producer의 W cycle에서 write와 consumer의 D read를 같은 cycle에 허용하므로 Decode를 두 cycle 붙잡는다.
  • forwarding이 있으면 producer의 ALU result를 다음 cycle consumer의 Execute input으로 직접 보낸다. Decode에서 읽은 old value가 있어도 E-stage mux가 forwarded value를 사용하므로 arithmetic pair에는 stall이 없다.
  • 회상 답 2 / 0은 현행 Übung 10 모델과 일치하지만 공식 SoSe25 solution은 아니다. Register File write/read timing이나 forwarding target stage가 다른 pipeline variant에는 숫자가 달라질 수 있으므로 이 문제의 course model 가정을 답에 적는다.

1. 문제에 나오는 말부터 하나씩

producer instruction
addi s0,a0,5; ALU가 새 s0를 만들고 W에서 Register File에 기록한다.
consumer instruction
addi s1,s0,4; source operand로 producer의 새 s0가 필요하다.
stall
consumer가 안전하게 진행할 수 있을 때까지 Decode와 보통 Fetch를 같은 instruction/state에 유지하는 cycle.
forwarding / bypassing
producer 결과를 Register File round trip 없이 M/W 쪽에서 consumer E input으로 전달하는 hardware 경로.
Writeback
pipeline의 W stage에서 결과를 Register File destination에 기록하는 단계.
same-cycle write/read assumption
현행 course timing에서 producer가 W에 쓰는 cycle에 consumer가 D에서 그 값을 읽을 수 있다고 보는 가정.

2. 선생님과 같이 한 칸씩 푸는 과정

  1. 두 instruction에 역할을 붙인다: I1=addi s0,a0,5는 write s0, I2=addi s1,s0,4는 read s0, write s1이다. 따라서 I1→I2 RAW(s0)다.
  2. 기본 stage를 쓴다. I1은 cycle 1 F, 2 D, 3 E, 4 M, 5 W다. I2는 dependency가 없다면 cycle 2 F, 3 D, 4 E로 진행하려 한다.
  3. forwarding이 없다고 가정한다. cycle 3 D의 I2가 읽을 새 s0는 아직 I1 E 결과일 뿐 Register File에 없다. 첫 stall이다.
  4. cycle 4에도 I1은 M이고 Register File write는 아직 하지 않았다. I2를 D에 유지해야 하므로 둘째 stall이다.
  5. cycle 5에 I1이 W에서 s0를 쓴다. course의 same-cycle write/read 가정으로 I2는 이 cycle D에서 새 s0를 읽고 다음 cycle E로 갈 수 있다.
  6. 따라서 without forwarding의 추가 정지 cycle은 2다. Decode에 처음 들어간 cycle 자체를 stall 하나로 세는 것이 아니라 정상 진행 대비 반복된 D cycle 두 개를 센다.
  7. 이제 forwarding을 켠다. I1의 ALU result는 cycle 3 E 끝에 준비되고 cycle 4에 M 쪽 forwarding source에서 I2의 E input으로 전달할 수 있다.
  8. I2는 cycle 3 D에서 정상 진행하고 cycle 4 E에서 forwarded s0를 사용한다. pipeline register의 stale operand보다 forwarding mux가 새 값을 선택하므로 stall은 0이다.
  9. load-use와 구분한다. lw result는 memory stage 끝에야 나오므로 바로 다음 consumer에는 forwarding이 있어도 보통 1 stall이 필요하지만, 여기 producer는 ALU addi라 더 일찍 나온다.
  10. 마지막으로 숫자 옆에 모델을 쓴다: ohne Forwarding: 2, mit EX-Forwarding: 0, current Übung timing 기준.

3. 그래서 정답은 무엇인가?

현행 F/D/E/M/W course model과 W-stage write / D-stage same-cycle read 가정에서:

addi s0,a0,5   # producer, writes s0
addi s1,s0,4   # consumer, reads s0
  • ohne Forwarding: Decode 2 Takte stall — consumer는 producer가 cycle 5의 W에서 s0를 쓸 때까지 D에 머문다.
  • mit Forwarding: 0 Takte stall — producer의 arithmetic ALU result를 다음 cycle consumer의 E input으로 bypass할 수 있다.

Gedächtnisprotokoll 회상 답의 2 / 0은 현행 Übung 10 timing과 일치하지만 공식 SoSe25 Musterlösung은 아니다. 다른 Register-File timing이나 forwarding 구조에는 숫자를 그대로 일반화하지 않는다.

4. 이제 정확한 개념으로 한 단계 더 깊게

  • dependency distance가 1인 ALU→ALU pair는 forwarding의 대표적인 성공 사례다. producer E 결과를 consumer E에 맞춰 전달한다.
  • Decode stall 수는 producer가 전체 instruction을 끝낼 때까지 기다린 cycle 수가 아니라 consumer가 정상 E 진입을 미룬 추가 cycle 수다.
  • without forwarding에서 W와 D가 같은 cycle에 가능한 것은 Register File의 write/read phase에 대한 course assumption이다. 이것이 불가능한 설계라면 한 cycle이 더 필요할 수 있다.
  • forwarding은 destination/source register 번호가 같고 RegWrite가 유효한지 비교하는 Hazard Unit과 ALU input mux를 필요로 한다.
  • consumer가 Decode에서 old s0를 읽었다는 사실만으로 오답은 아니다. Execute 직전에 forwarding mux가 올바른 값을 덮어 선택할 수 있다.
  • ALU-result forwarding과 load-use forwarding을 구분한다. memory data는 ALU result보다 늦게 준비되어 direct successor가 한 cycle 기다려야 할 수 있다.
  • 회상 숫자를 사용할 때는 ‘current Übung model’이라는 assumption을 명시해야 source fidelity를 지킬 수 있다.

5. 시험장에서 그대로 쓰는 단계별 풀이

  1. I1의 destination과 I2의 sources를 표시해 RAW(s0)를 확인한다.
  2. I1의 F/D/E/M/W를 cycle 1–5에 쓴다.
  3. I2가 정상이라면 D와 E에 언제 도착하는지 그린다.
  4. without forwarding에서는 s0가 Register File에 쓰이는 W까지 I2의 D를 반복해 두 stall을 센다.
  5. W write와 D read가 같은 cycle이라는 course timing을 주석으로 적는다.
  6. with forwarding에서는 I1 E 결과가 I2 E에 도착하는 M→E bypass를 그린다.
  7. producer가 lw인지 ALU instruction인지 마지막으로 구분한다.
  8. 2 stalls / 0 stalls 옆에 각각 이유 한 문장을 쓴다.

6. 예시와 변형 문제 연결

  • without forwarding의 stage trace는 I1=F1 D2 E3 M4 W5, I2=F2 D3 D4 D5 E6 M7 W8로 쓸 수 있다. 정상 D3 뒤 D4·D5 두 추가 hold가 stall 2개다.
  • with forwarding이면 I1=F1 D2 E3 M4 W5, I2=F2 D3 E4 M5 W6이다. cycle 4의 I2 E가 I1의 새 s0를 forwarding input으로 받는다.
  • lw s0,0(a0); addi s1,s0,4로 producer를 바꾸면 현행 model에서 loaded data가 늦어 direct load-use stall 1개가 필요하다. 따라서 ‘forwarding이면 항상 0’은 틀리다.
  • 두 번째 instruction이 addi s1,s2,4라면 s0를 읽지 않으므로 register number match가 없고 RAW도 stall도 없다.

7. 독일어 만점 답안 템플릿

Die erste Instruktion produziert s0, die direkt folgende Instruktion konsumiert s0; es liegt also ein RAW-Hazard vor. Ohne Forwarding bleibt die zweite Instruktion im aktuellen Kursmodell zwei zusätzliche Takte in Decode, bis s0 im Writeback-Zyklus ins Registerfile geschrieben und im selben Zyklus gelesen werden kann. Mit ALU-Forwarding wird das Ergebnis zur Execute-Stufe weitergeleitet, daher sind es 0 Stall-Takte. 2/0 ist die gegen aktuelle Übungsunterlagen geprüfte Recall-Antwort, keine offizielle SoSe25-Musterlösung.

8. 자주 나오는 오답과 교정

  • without forwarding을 3 stall이라고 쓰기: 이 course model에서는 producer W와 consumer D read가 같은 cycle에 가능하다.
  • with forwarding도 Register File write까지 기다리기: ALU result가 consumer E로 직접 bypass된다.
  • forwarding이면 모든 dependency가 0 stall이라고 일반화하기: direct load-use는 현행 model에서도 1 stall이 필요하다.
  • 첫 D cycle 자체를 stall로 세기: 정상 schedule보다 추가로 유지된 D cycles만 센다.
  • s0가 callee-saved라는 ABI 이름을 pipeline hazard와 연결하기: saver convention과 hardware RAW timing은 별개다.
  • 회상 답 2/0을 모든 processor에 적용하기: register-file phase와 forwarding topology를 명시해야 한다.

9. 답을 보지 않고 확인하기

  1. 두 instruction 중 producer와 consumer는 각각 무엇이며 의존 register는 무엇인가?
  2. without forwarding에서 producer가 s0를 Register File에 쓰는 stage는 어디인가?
  3. 왜 current model에서는 stall이 3이 아니라 2인가?
  4. with forwarding에서 값은 어느 producer/consumer stage 사이로 전달되는가?
  5. lw→addi direct dependency와 이 addi→addi dependency의 차이는 무엇인가?
확인문제 정답 보기
  1. addi s0,a0,5가 producer, 둘째 addi s1,s0,4가 consumer이고 register는 s0다.
  2. cycle 5의 Writeback(W) stage다.
  3. producer W의 write와 consumer D의 read를 같은 cycle에 허용하므로 D를 추가로 hold하는 cycle은 3과 4의 두 번이다.
  4. producer의 ALU result가 producer M 쪽에서 consumer E의 ALU input으로 forwarding된다.
  5. addi result는 E 뒤 준비되어 바로 다음 E로 forwarding 가능하지만 lw data는 M 끝에 준비되어 direct consumer가 보통 1 stall 기다려야 한다.

Interactive practice

Forwarding/Stall timing chart

forwarding을 전환해 producer/consumer의 stall 차이를 확인하세요.

Teilaufgabe

7c

3 points

Original German

Bestimmen Sie die Anzahl der ausgefuehrten Instruktionen des Programms aus 7a. Geben Sie auch an, wie viele Spruenge bzw. Verzweigungen es gab.

한국어 문제

7a의 프로그램에서 실제로 실행되는 Instruktion 수와 Sprung/Verzweigung 수를 구하라.

한 줄 핵심

static code 줄 수가 아니라 실제 실행된 instruction을 세며 conditional branch, jump, ret의 집계 기준을 명시한다.

0. 초보자 개념 다리

static code는 지도이고 dynamic instruction count는 실제로 걸은 발걸음 수다.

1. 이 문제의 풀이 루틴

  1. loop iteration 수를 확정한다.
  2. iteration별 실행 instruction을 센다.
  3. 초기화·마지막 branch·ret를 포함한다.
  4. jump/branch 포함 기준을 명시한다.

2. 왜 이 방법이 맞을까?

성능과 pipeline cycles는 실제 실행 횟수로 결정된다.

3. 시험장 실수 방지

코드 줄 번호 개수를 총 실행 instruction 수로 쓰지 않는다.

최대 상세 해설 · 7c 깊이 학습: dynamic instruction과 Sprung count를 convention별로 세기

이 강의의 도착점

a0=2의 register 값을 직접 trace하여 10개 dynamic instruction sequence를 만들고, conditional branches, jumps, taken transfers를 서로 다른 counting convention으로 구분해 모호하지 않은 답을 작성한다.

0. 정말 아무것도 모른다면 여기서 시작

  • code에 줄이 8개라고 실행 instruction도 8개인 것은 아니다. loop에서 #2#3이 두 번 실행되므로 먼저 dynamic sequence를 적어야 한다.
  • 두 번째 함정은 독일어 Sprünge의 범위다. branch instruction을 실행한 횟수, 실제 taken transfer 수, j만의 횟수, ret 포함 여부가 서로 다른 숫자를 만든다.
  • 따라서 답은 10 instructions, 2 jumps처럼 숫자 두 개만 쓰지 않는다. conditional branch 실행 3회, unconditional/indirect jump 실행 2회, taken control transfer 3회처럼 기준과 수를 함께 쓴다.
  • 회상 Lösung의 ‘10 Schritte, 2 Sprünge(einmal j, einmal beq)’는 특정 convention에서는 설명 가능하지만 공식 채점 기준이 아니다. 이 가이드는 dynamic trace로 확정되는 사실과 해석이 필요한 Sprung count를 분리한다.

1. 문제에 나오는 말부터 하나씩

static instruction
program listing에 한 번 적힌 instruction line. #0–#7의 여덟 줄이다.
dynamic instruction
실행 중 실제로 발생한 instruction instance. loop에서 같은 static line이 반복되면 매번 하나씩 센다.
conditional branch
조건에 따라 target으로 갈지 결정하는 instruction. 여기서는 #0 beqz 한 번과 #3 beqz 두 번이 실행된다.
unconditional jump
조건 없이 target으로 이동하는 instruction. 여기서는 #5 j .Lloop가 한 번 실행된다.
indirect jump / ret
ret은 보통 jalr x0,ra,0으로 확장되는 control transfer다. jump count에서 포함 여부를 밝혀야 한다.
taken transfer
실행 결과 PC가 순차 next address가 아니라 target으로 실제 바뀐 control instruction instance.
counting convention
어떤 pseudo line과 어떤 control instruction을 수에 포함하는지 미리 정한 규칙.

2. 선생님과 같이 한 칸씩 푸는 과정

  1. 이 문제에서는 recall의 번호가 붙은 pseudo line 하나를 counted instruction 하나로 둔다. li, mv, j, ret, beqz를 실제 assembler expansion 수로 다시 세지 않는다.
  2. 초기 a0=2. step 1에서 #0 beqz a0,.Lret은 false라 not taken이고, step 2에서 #1이 t0=0을 만든다.
  3. step 3에서 #2가 a0=2>>1=1; step 4에서 #3은 a0=1이라 not taken이다.
  4. step 5에서 #4가 t0=1; step 6에서 #5 j .Lloop가 taken되어 #2로 돌아간다.
  5. step 7에서 두 번째 #2가 a0=1>>1=0; step 8에서 두 번째 #3은 taken되어 .Lend로 간다.
  6. step 9에서 #6 mv a0,t0가 a0=1을 만들고, step 10에서 #7 ret이 caller로 control을 넘긴다.
  7. dynamic sequence를 한 줄로 쓴다: #0,#1,#2,#3,#4,#5,#2,#3,#6,#7. 항목 수는 10이다.
  8. conditional branch instruction 실행을 센다. #0 한 번 + #3 두 번 = 3회이고, 그중 taken conditional branch는 두 번째 #3 한 번이다.
  9. unconditional/indirect jump 실행은 #5 j 한 번과 #7 ret 한 번으로 2회다. 따라서 branch와 jump를 모두 포함한 executed control-flow instructions는 5회다.
  10. 실제로 taken된 control transfer는 #5, 두 번째 #3, #7의 3회다. 만약 회상 Lösung처럼 ret을 빼고 loop 내부에서 실제 경로를 바꾼 j와 taken beqz만 ‘Sprünge’라 부르면 2회다.
  11. 최종 답에는 주 숫자 10과 함께 최소 두 convention을 적어 ambiguity를 제거한다. examiner가 무엇을 원하는지 모호하면 ‘ohne ret’와 ‘inklusive ret’ 모두 쓴다.

3. 그래서 정답은 무엇인가?

dynamic sequence는 다음과 같다.

#0, #1, #2, #3, #4, #5, #2, #3, #6, #7

따라서 실행된 dynamic instructions는 10개다. Control-flow count는 기준을 밝혀야 한다.

  • executed conditional branches: 3 (#0 1회, #3 2회)
  • taken conditional branches: 1 (두 번째 #3)
  • executed unconditional/indirect jumps: 2 (#5 j, #7 ret)
  • branches와 jumps를 모두 포함한 executed control-flow instructions: 5
  • ret까지 포함한 taken control transfers: 3 (#5, taken #3, #7)
  • Gedächtnisprotokoll의 회상 Lösung처럼 ret을 제외하고 loop 안의 taken j와 taken beqz만 ‘Sprünge’로 세면 2

공식 SoSe25 채점 convention은 확인되지 않았으므로 답안에는 포함 기준과 숫자를 함께 쓴다.

4. 이제 정확한 개념으로 한 단계 더 깊게

  • dynamic count는 input에 의존한다. a0가 달라지면 #2/#3 반복 수가 달라지고 총 instruction 수도 달라진다.
  • static label과 instruction은 다르다. .Lloop, .Lend, .Lret label 자체는 실행 instruction으로 세지 않는다.
  • not-taken branch도 instruction으로 실행되었으므로 dynamic instruction count와 executed branch count에는 포함한다.
  • taken count는 branch execution count보다 작을 수 있다. 여기 #3은 두 번 실행되지만 한 번만 taken이다.
  • ret은 Assembly syntax상 return이지만 machine-level에서는 indirect control transfer다. problem wording에 따라 jump count에 포함할 수 있다.
  • correct branch prediction은 count를 바꾸지 않는다. penalty를 없앨 뿐 실제 semantic path에서 branch/jump instruction은 여전히 실행된다.
  • pseudoinstruction expansion을 세는 문제라면 li immediate 크기 등에 따라 count가 달라질 수 있다. 이 recalled task는 번호 붙은 line을 하나씩 세는 convention을 사용한다.

5. 시험장에서 그대로 쓰는 단계별 풀이

  1. counting unit을 한 numbered pseudo line=한 instruction으로 선언한다.
  2. a0와 t0의 초기값을 표 머리에 쓴다.
  3. 각 branch에서 condition을 계산하고 taken/not taken을 표시한다.
  4. PC path를 따라 static 번호를 dynamic sequence에 하나씩 추가한다.
  5. a0가 0이 되어 .Lend로 갈 때까지 loop를 반복한다.
  6. 마지막 mv와 ret까지 포함한 뒤 sequence 항목을 세어 10을 얻는다.
  7. control instruction들을 conditional, unconditional, indirect로 색을 나눠 센다.
  8. executed와 taken, ret 포함/제외를 구분한 숫자를 독일어 문장으로 쓴다.

6. 예시와 변형 문제 연결

  • 첫 loop pass 뒤에는 a0=1, t0=1이라 #5가 #2로 돌아간다. 둘째 #2가 a0=0을 만들기 때문에 둘째 #3은 taken되고 #4/#5를 다시 실행하지 않는다.
  • static line 수만 세면 8이지만 dynamic sequence에는 #2와 #3이 각각 한 번씩 추가되어 10이다.
  • #0은 not taken이어도 executed conditional branch 1회다. taken branch만 묻는 질문에는 포함하지 않지만 instruction count에는 반드시 포함한다.
  • 초기 a0=0이면 sequence는 #0,#7 두 개뿐이다. #0가 즉시 .Lret로 branch해 loop initialization과 body를 모두 건너뛴다.

7. 독일어 만점 답안 템플릿

Für a0=2 lautet die dynamische Folge #0,#1,#2,#3,#4,#5,#2,#3,#6,#7; damit werden 10 Instruktionen ausgeführt. Es gibt drei ausgeführte bedingte Branches (#0 einmal, #3 zweimal), davon einen genommenen. Zusätzlich werden j und ret je einmal ausgeführt. Somit sind es fünf ausgeführte Kontrollflussinstruktionen bzw. drei genommene Kontrolltransfers inklusive ret. Zählt man wie in der Recall-Lösung nur den genommenen Schleifen-j und den genommenen beqz ohne ret, erhält man zwei Sprünge. Die Zählkonvention muss angegeben werden, da keine offizielle SoSe25-Lösung vorliegt.

8. 자주 나오는 오답과 교정

  • listing의 #0–#7만 보고 8개라고 답하기: #2와 #3이 두 번 실행된다.
  • not-taken #0/#3을 branch count에서 제외하기: executed count에는 결과와 관계없이 포함된다.
  • branch 3회와 taken branch 1회를 같은 숫자로 쓰기: 실행 여부와 taken 여부는 별도 기준이다.
  • ret은 control flow가 아니라고 단정하기: machine-level에서는 jalr 기반 indirect jump다.
  • 회상 답의 2 Sprünge를 유일한 정의로 쓰기: 이는 ret 제외·taken loop transfer convention이다.
  • label을 instruction으로 세기: .Lloop, .Lend, .Lret는 address 이름이지 실행 명령이 아니다.
  • pseudo expansion을 임의로 늘리기: 이 문제의 numbered-line count convention을 먼저 지켜야 한다.

9. 답을 보지 않고 확인하기

  1. a0=2일 때 dynamic static-number sequence를 쓰라.
  2. 왜 static 8줄인데 dynamic instruction은 10개인가?
  3. conditional branch는 총 몇 번 실행되고 몇 번 taken되는가?
  4. jret은 각각 몇 번 실행되는가?
  5. taken control transfer를 ret 포함과 제외로 각각 어떻게 셀 수 있는가?
  6. correct prediction은 이 count들에 어떤 영향을 주는가?
확인문제 정답 보기
  1. #0,#1,#2,#3,#4,#5,#2,#3,#6,#7이다.
  2. loop 때문에 #2와 #3이 각각 두 번 실행되어 static listing보다 dynamic instance가 두 개 더 많기 때문이다.
  3. #0 1회와 #3 2회로 총 3회 실행되고, 두 번째 #3 한 번만 taken된다.
  4. #5 j가 1회, #7 ret이 1회 실행된다.
  5. ret 포함 taken transfers는 #5, taken #3, #7로 3회다. 회상 convention처럼 ret을 제외하고 loop 안의 taken j/beqz만 세면 2회다.
  6. prediction은 flush penalty를 바꾸지만 semantic dynamic path와 실제 실행 instruction/control transfer count는 바꾸지 않는다.

Interactive practice

Dynamic count checker

집계 기준에 맞는 실행 횟수를 입력하세요.

Teilaufgabe

7d

6 points

Original German

Bestimmen Sie die Ausfuehrungszeit in Takten des Programms aus 7a fuer den Eintakt-Prozessor und fuer den Pipeline-Prozessor.

한국어 문제

같은 프로그램의 실행 시간을 Eintakt-Prozessor와 Pipeline-Prozessor 기준으로 Takte 단위로 계산하라.

한 줄 핵심

single-cycle은 실행 instruction 수, pipeline은 fill/drain과 실제 stall·flush를 더해 cycle 수를 계산한다.

0. 초보자 개념 다리

Pipeline은 여러 작업을 겹치지만 처음 채우고 마지막을 빼는 시간과 막힘이 있다.

1. 이 문제의 풀이 루틴

  1. dynamic count N을 가져온다.
  2. single-cycle은 N cycles로 둔다.
  3. k-stage pipeline을 N+k-1로 시작한다.
  4. stall과 flush penalty를 더한다.
  5. branch resolution/forwarding 가정을 적는다.

2. 왜 이 방법이 맞을까?

fill/drain은 고정 비용이고 hazard penalty는 실행 경로에 따라 추가된다.

3. 시험장 실수 방지

CPI≈1만 보고 k-1 fill/drain을 빼먹지 않는다.

최대 상세 해설 · 7d 깊이 학습: Eintakt와 Pipeline cycle 수를 가정별로 계산하기

이 강의의 도착점

7c의 dynamic count 10을 출발점으로 Eintakt N, 이상적 5-stage Pipeline N+4, 실제 +stalls+flushes 공식을 적용하고, 현행 forwarding·correct prediction 모델의 14 cycles와 recall의 미검증 15 cycles를 구분한다.

0. 정말 아무것도 모른다면 여기서 시작

  • cycle 계산은 code 줄 수가 아니라 7c에서 만든 dynamic instruction 수 N=10에서 시작한다. trace가 틀리면 Eintakt와 Pipeline 답이 함께 틀린다.
  • Eintakt-Prozessor는 한 instruction을 한 긴 cycle에 끝내므로 이 문제의 count convention에서는 10 instructions=10 cycles다. ‘긴 cycle’의 실제 ps는 묻지 않는다.
  • 5-stage Pipeline은 첫 instruction을 채우고 마지막 instruction을 비워 내는 fill/drain 4 cycles가 필요하다. 아무 stall/flush가 없어도 N이 아니라 N+4다.
  • 회상 Lösung에는 Pipeline 15 Takte라고만 쓰였지만 extra 1 cycle의 근거가 없다. 현행 Übung 10의 Execute forwarding, correct prediction, 이 code에 load-use 없음이라는 기본 가정에서는 10+4=14. 원래 SoSe25 sketch의 branch-data path가 달라 1 stall을 요구했다면 15가 가능하지만 공식 그림·해설이 없어 이를 확정하지 않는다.

1. 문제에 나오는 말부터 하나씩

Eintakt cycle count
각 dynamic instruction이 정확히 한 processor cycle을 차지하므로 instruction 수 N과 같은 count.
Pipeline fill/drain
첫 instruction이 5 stages를 채우고 마지막 instruction이 끝날 때까지 필요한 시작·마무리 overhead. 5-stage에서는 4 cycles.
ideal Pipeline formula
stall과 flush가 없을 때 cycles=N+(stages-1)=N+4.
stall penalty
Data Hazard 등으로 stage 진행을 멈춘 추가 cycle. dependency가 있다는 이유만이 아니라 forwarding이 제시간에 못 줄 때만 더한다.
flush penalty
잘못 fetch한 instruction을 버리는 추가 cycle. 이 문제는 correct prediction이라 0으로 둔다.
CPI
instruction당 평균 cycle 수. 긴 sequence에서 ideal pipeline은 1에 가까워지지만 finite N의 전체 cycles가 N과 같다는 뜻은 아니다.
model assumption
branch decision stage, forwarding destination, Register File timing처럼 cycle count를 결정하는 datapath 조건.

2. 선생님과 같이 한 칸씩 푸는 과정

  1. 7c dynamic sequence를 다시 적고 항목 수를 센다: #0,#1,#2,#3,#4,#5,#2,#3,#6,#7, 따라서 N=10.
  2. Eintakt부터 계산한다. 한 dynamic instruction당 one cycle이므로 T_Eintakt=10×1=10 cycles다.
  3. Pipeline stage 수를 확인한다: F,D,E,M,W의 5 stages. ideal fill/drain overhead는 5-1=4다.
  4. 기본식을 쓴다: T_Pipe=N+4+stalls+flushes.
  5. Control Hazard 항을 넣는다. 문제는 모든 Sprung가 correctly predicted되고 Control Hazards가 없다고 명시하므로 flushes=0이다.
  6. Data Hazard 항을 넣는다. #2→#3의 a0 RAW와 #1→#4 등의 dependency는 있지만, 현행 Execute-forwarding 모델에서 ALU result는 consumer E에 전달된다. 이 code에는 direct lw consumer가 없어 default stalls=0이다.
  7. 대입하면 T_Pipe=10+4+0+0=14 cycles다. 한 instruction이면 5 cycles가 된다는 1+4=5 sanity check로 formula를 확인한다.
  8. 회상 답 15를 audit한다. 15는 10+4+1이므로 branch consumer가 Decode에서 값을 요구해 forwarding이 제때 도달하지 않는 등 extra stall 1개를 전제로 해야 한다.
  9. 하지만 원본 SoSe25 pipeline sketch가 없어 그 variant를 확인할 수 없다. 따라서 main answer는 current-source model의 14이고, recall 15는 ‘한 extra stall을 가정할 때 가능한 미검증 값’으로 별도 표기한다.
  10. 마지막으로 cycles와 실제 execution time을 구분한다. 문제는 Takte 수를 묻고 clock period 정보가 없으므로 seconds나 speedup을 임의로 계산하지 않는다.

3. 그래서 정답은 무엇인가?

7c의 dynamic count는 N=10이다.

Eintakt cycles = N = 10

Pipeline cycles = N + (5-1) + stalls + flushes
                = 10 + 4 + 0 + 0
                = 14

여기서 14 cycles는 현행 Übung/Vorlesung의 5-stage F/D/E/M/W, ALU-result forwarding to Execute, correct branch prediction, load-use 없음이라는 source-verified 기본 모델의 답이다. Correct prediction 때문에 flush=0이고, #2→#3 RAW는 forwarding되어 default stall=0이다.

Gedächtnisprotokoll의 recall Lösung은 15 cycles라고 적지만 extra cycle의 근거를 제시하지 않는다. branch comparison/forwarding 구조가 달라 1 stall이 필요한 별도 pipeline이면 10+4+1=15가 가능하다. 공식 SoSe25 sketch와 solution이 없으므로 15를 보편적·공식 정답으로 단정하지 말고, 답안에 사용한 model assumption을 명시해야 한다.

4. 이제 정확한 개념으로 한 단계 더 깊게

  • ideal CPI≈1은 steady state throughput 설명이다. finite sequence의 첫 결과와 마지막 완료까지는 fill/drain 때문에 N+4 cycles가 든다.
  • Eintakt의 10 cycles와 Pipeline의 14 cycles만 보고 Pipeline이 느리다고 결론내릴 수 없다. 두 processor의 clock period가 다르며 Pipeline cycle은 보통 더 짧다.
  • stall과 flush는 실제로 발생한 추가 cycles만 더한다. dependency 목록의 개수나 branch instruction 수를 자동 penalty로 넣지 않는다.
  • correct prediction 조건은 control-flow instruction 자체를 없애지 않고 wrong-path penalty만 0으로 만든다.
  • forwarding이 있더라도 load-use는 한 stall이 남을 수 있다. 이 code에는 load가 없어 그 예외가 적용되지 않는다.
  • branch가 E에서 compare되고 forwarding을 받는 current model과 D에서 일찍 compare하는 alternate model은 stall 수가 다를 수 있다. original sketch 부재는 cycle answer의 핵심 uncertainty다.
  • recall answer audit에서는 숫자를 버리거나 맹신하지 않는다. 15 = N+4+1로 숨은 assumption을 역산하고 근거 자료가 있는지 확인한다.
  • Takte 수를 시간(ns)으로 바꾸려면 각 architecture의 clock period가 추가로 필요하다. 이 subpart에는 그 수치가 없다.

5. 시험장에서 그대로 쓰는 단계별 풀이

  1. 7c의 dynamic sequence와 N=10을 답안 첫 줄에 다시 쓴다.
  2. Eintakt에 cycles=N을 적용한다.
  3. stage 수 5를 적고 fill/drain overhead 5-1=4를 계산한다.
  4. N+4+stalls+flushes symbolic formula를 먼저 쓴다.
  5. correct prediction 조건 옆에 flushes=0을 표시한다.
  6. 각 RAW producer type을 확인하고 current forwarding model에서 stalls=0인지 판단한다.
  7. 14를 계산한 뒤 recall 15가 요구하는 extra stall 1의 가정을 별도 문장으로 쓴다.
  8. clock period가 없으므로 cycles 외의 실제 시간·speedup은 계산하지 않는다.

6. 예시와 변형 문제 연결

  • 5-stage Pipeline에서 N=1이면 1+4=5 cycles다. 이 작은 예가 fill/drain 항을 빼먹지 않는 가장 빠른 검산이다.
  • 현재 code에 direct lw→consumer pair가 하나 추가되어 1 stall이 생긴다면, 다른 조건이 같을 때 cycles는 11+4+1=16이다. instruction 증가와 stall 증가를 각각 더해야 한다.
  • correct prediction이 없고 misprediction flush가 총 2 cycles 발생한다면 current N=10 sequence의 formula는 10+4+stalls+2다. branch 개수 전체를 penalty로 더하지 않는다.
  • Recall의 15는 10+4+1로 분해된다. 따라서 이를 쓰려면 ‘branch-data RAW가 이 제공 pipeline에서 one stall’ 같은 구체 datapath 근거가 필요하며, 현재 남은 recall text만으로는 그 근거를 확인할 수 없다.

7. 독일어 만점 답안 템플릿

Für a0=2 werden dynamisch N=10 Instruktionen ausgeführt. Der Eintakt-Prozessor benötigt daher 10 Takte. Im aktuellen Fünfstufenmodell mit Forwarding, korrekter Sprungvorhersage, keinen Flushes und keinem Load-Use-Stall gilt T_Pipe=N+4+Stalls+Flushes=10+4+0+0=14 Takte. Im Gedächtnisprotokoll steht 15; das entspräche einem zusätzlichen Stall, dessen Ursache ohne die originale SoSe25-Pipeline-Skizze nicht offiziell verifiziert ist. Deshalb nenne ich die verwendete Pipeline-Annahme ausdrücklich.

8. 자주 나오는 오답과 교정

  • Pipeline도 10 cycles라고 쓰기: ideal CPI 1을 전체 finite sequence에 적용해 fill/drain 4를 빼먹었다.
  • 모든 branch 5개에 penalty를 더하기: 문제는 correct prediction과 no Control Hazard를 명시한다.
  • RAW가 두 번 보인다는 이유로 stall 2개 더하기: current forwarding이 제시간에 값을 제공하면 stall은 0이다.
  • forwarding이 있으므로 공식적으로 무조건 14라고 단정하기: original SoSe25 branch datapath sketch가 없어 alternate 1-stall model 가능성을 밝혀야 한다.
  • 회상 답 15를 이유 없이 복사하기: +1이 어떤 stall/flush인지 설명하지 못한다.
  • 10 cycles와 14 cycles만으로 실제 seconds 성능을 비교하기: architecture별 clock period가 없다.
  • static instruction 8개를 N으로 사용하기: loop dynamic sequence는 10개다.

9. 답을 보지 않고 확인하기

  1. 이 계산에서 dynamic instruction 수 N은 얼마이며 어디서 오는가?
  2. 5-stage no-stall Pipeline의 일반 cycle 식은 무엇인가?
  3. 왜 Eintakt는 10 cycles인가?
  4. 왜 current default Pipeline 계산에서 flushes와 stalls가 각각 0인가?
  5. Recall의 15 cycles는 formula상 어떤 추가 가정을 뜻하는가?
  6. 14 cycles만으로 Pipeline이 Eintakt보다 실제 시간이 느리다고 결론낼 수 없는 이유는 무엇인가?
확인문제 정답 보기
  1. N=10이며 7c의 dynamic sequence #0,#1,#2,#3,#4,#5,#2,#3,#6,#7에서 나온다.
  2. cycles=N+(stages-1)+stalls+flushes, 5-stage에서는 N+4+stalls+flushes다.
  3. Eintakt는 각 dynamic instruction을 한 긴 cycle에 완료하므로 10 instructions×1 cycle=10이다.
  4. 문제가 correct prediction/no Control Hazard를 주어 flush=0이고, current Execute-forwarding model이 ALU dependencies를 처리하며 direct load-use가 없어 stall=0이다.
  5. 15=10+4+1이므로 branch-data dependency 등으로 extra stall 1개가 필요하다는 alternate datapath assumption을 뜻한다.
  6. 실제 시간은 cycle count×clock period이고 Eintakt와 Pipeline의 clock period가 다를 수 있는데 이 subpart에는 그 수치가 없기 때문이다.

Interactive practice

Pipeline cycle calculator

N, stage 수, stall, flush를 바꿔 total cycles를 확인하세요.

Intro

Metadata

FeldInhalt
Aufgabe7
TitelPipelined Prozessor
Punkte15
Empfohlene Zeit15 Minuten
Tutor modehazard
KonzeptePipeline, RAW Data Hazard, forwarding, stall, branch prediction, Eintakt vs. Pipeline cycles
Recall-source confidencemittel: Code und Teilfragen sind klar, aber die recalled answers sind not official und teilweise unvollstaendig
Verification sourcesGedächtnisprotokoll Rechnerorganisation SoSe25.md#aufgabe-7; Uebung\Lösung 9.pdf pages 1-7; Uebung\Lösung 10.pdf pages 1-5; Uebung\Übung 10.pdf pages 1-2; Vorlesung\Rechnerorganisation - Teil 2.pdf pages 82-108, 115-117
Visual statusOriginale Klausur-Skizze ist nicht vorhanden; gleichwertige Pipeline-Folien aus Vorlesung\Rechnerorganisation - Teil 2.pdf pages 82-105 werden als Referenz genutzt.

Wichtig: Das Gedächtnisprotokoll ist eine rekonstruierte Erinnerung, not official exam material and not official solution. Die Zahlen 10 / 2 / 15 aus der Recall-Loesung werden unten geprueft, nicht blind uebernommen.

Original German

7a) (ca. 4 Punkte)

Der folgende RISC-V-Code wird auf einem Pipeline-Prozessor ausgefuehrt mit dem Parameter a0 = 2. Gehen Sie davon aus, dass alle Spruenge korrekt vorhergesagt werden und es keine Control Hazards gibt. In der Klausur war laut Recall eine Skizze des Pipeline-Prozessors aus der Vorlesung gegeben.

clog2:
   beqz a0, .Lret   #0
   li t0, 0         #1
.Lloop:
   srli a0, a0, 1   #2
   beqz a0, .Lend   #3
   addi t0, t0, 1   #4
   j .Lloop         #5
.Lend:
   mv a0, t0        #6
.Lret:
   ret              #7
  1. Zu welchem Zeitpunkt entsteht der erste Data Hazard? Tragen Sie die Nummer der entsprechenden Instruktion in die jeweilige Pipeline-Stufe ein.
  2. Welche Instruktionen sind am Hazard beteiligt?

Normalisierungsnotiz: Im Recall steht mv, a0, t0; das Komma nach mv ist ein Syntaxfehler. Gemeint ist der Pseudobefehl mv a0, t0.

7b) (ca. 2 Punkte)

addi s0, a0, 5
addi s1, s0, 4

Wie lange muss Decode angehalten werden (stalling), wenn:

  1. kein forwarding vorhanden ist?
  2. forwarding vorhanden ist?

7c) (ca. 3 Punkte)

Bestimmen Sie die Anzahl der ausgefuehrten Instruktionen des Programms aus 7a. Geben Sie auch an, wie viele Spruenge bzw. Verzweigungen es gab.

7d) (ca. 6 Punkte)

Bestimmen Sie die Ausfuehrungszeit in Takten des Programms aus 7a fuer den Eintakt-Prozessor und fuer den Pipeline-Prozessor.

Korean Translation

7a)

a0 = 2인 상태에서 아래 RISC-V 코드가 Pipeline-Prozessor에서 실행된다. 모든 Sprung/Branch는 올바르게 예측되어 Control Hazard는 없다고 가정한다. 첫 Data Hazard가 언제 생기는지 Pipeline-Stufe에 명령 번호를 적고, 어떤 두 명령이 그 Hazard에 관여하는지 답하라.

7b)

addi s0, a0, 5 바로 다음에 addi s1, s0, 4가 온다. Forwarding이 없을 때와 있을 때 Decode를 몇 Takte 멈춰야 하는지 구하라.

7c)

7a의 프로그램에서 실제로 실행되는 Instruktion 수와 Sprung/Verzweigung 수를 구하라.

7d)

같은 프로그램의 실행 시간을 Eintakt-Prozessor와 Pipeline-Prozessor 기준으로 Takte 단위로 계산하라.

Concept Lesson

Pipeline은 한 Instruktion을 Fetch, Decode, Execute, Memory, Writeback의 다섯 Stufen으로 나누고, 여러 Instruktionen을 동시에 다른 Stufe에 올려 처리한다. Vorlesung Teil 2 pages 82-87과 Lösung 9 pages 1-3, Lösung 10 pages 1-3이 같은 다섯 Stufen을 사용한다.

Data Hazard는 뒤의 Instruktion이 앞 Instruktion의 아직 Writeback되지 않은 결과를 읽으려고 할 때 생긴다. 여기서는 대부분 RAW, 즉 Read After Write이다. Lösung 10 pages 1-3은 add t0,... 다음 addi ...,t0,... 같은 예를 들고, Forwarding은 뒤쪽 Pipeline-Stufe의 결과를 Execute-Stufe로 바로 넘겨 nop을 줄이는 방법이라고 설명한다.

시험에서 많이 틀리는 지점은 세 가지다.

이 Aufgabe에서는 Recall의 번호 #0-#7이 사실상 각 Pseudobefehl을 한 Instruktion으로 세는 기준이다. li t0, 0, mv a0, t0, beqz, j, ret은 각각 한 줄짜리 기본 명령으로 해석한다. Lösung 4 pages 1-3은 Pseudobefehl이 하나 또는 여러 Basisinstruktionen으로 바뀔 수 있음을 보여 주므로, 시험에서는 반드시 이 가정을 적어야 한다.

Problem Interpretation

Given:

Find:

Traps:

Useful formula:

Pipeline cycles without stalls/flushes = dynamic instruction count + (number of stages - 1)
                                       = N + 4

This N + 4 rule is stated in Uebung\Übung 10.pdf pages 1-2 and applied in Uebung\Lösung 10.pdf pages 4-5.

Solving Procedure

  1. Normalize each Pseudobefehl only as far as the task needs: here each numbered line remains one counted instruction.
  2. Trace the register values before any Pipeline table.
  3. Write the dynamic instruction sequence, not the static listing.
  4. Mark every producer-consumer pair: destination register of older instruction vs. source register of younger instruction.
  5. Build the five-stage Pipeline table until the first consumer reaches Decode/Execute.
  6. Decide forwarding/stall from the course rule: arithmetic result can be forwarded to Execute; lw directly followed by a consumer needs one stall.
  7. Count cycles: Eintakt = dynamic instructions; Pipeline = dynamic instructions + 4 + stalls + flushes.
Detailed Solution

7a) Dynamic Trace for a0 = 2

Initial state: a0 = 2, t0 irrelevant.

Dyn. stepStatic #InstruktionCondition / effecta0 aftert0 afterControl result
1#0beqz a0, .Lreta0 == 0 is false2-not taken
2#1li t0, 0t0 = 020sequential
3#2srli a0, a0, 12 >> 1 = 110sequential
4#3beqz a0, .Lenda0 == 0 is false10not taken
5#4addi t0, t0, 10 + 1 = 111sequential
6#5j .Lloopunconditional11taken to .Lloop
7#2srli a0, a0, 11 >> 1 = 001sequential
8#3beqz a0, .Lenda0 == 0 is true01taken to .Lend
9#6mv a0, t0a0 = t0 = 111sequential
10#7retreturn via ra11taken indirect jump

The first RAW Data Hazard is between static instruction #2 and static instruction #3 on register a0.

First-hazard Pipeline snapshot:

CycleFetchDecodeExecuteMemoryWritebackNote
1#0----start
2#1#0---
3#2#1#0--
4#3#2#1#0-#3 has been fetched
5#4#3#2#1#0first RAW visible: #3 needs a0 from #2
6#5#4#3#2#1with forwarding, #2 result is forwarded to #3 Execute

If the stage boxes are written in the common left-to-right order F D E M W, the cycle-5 entries are:

F: #4, D: #3, E: #2, M: #1, W: #0

That matches the useful part of the Recall answer 4, 3, 2, 1, 0, but the important interpretation is the #2 -> #3 RAW on a0.

7b) Stall Cycles With and Without Forwarding

Code:

addi s0, a0, 5   # producer: writes s0
addi s1, s0, 4   # consumer: reads s0

Without forwarding:

CycleProducer addi s0,...Consumer addi s1,...Explanation
1F-
2DF
3ED (stall)consumer would read old s0
4MD (stall)still not in register file
5WDwrite/read in same cycle is accepted in the course model
6-Econsumer can proceed
7-M
8-W

Answer without forwarding: Decode must be held for 2 stall cycles.

With forwarding:

CycleProducer addi s0,...Consumer addi s1,...Explanation
1F-
2DF
3EDconsumer reads stale value in D, but actual ALU operand is needed in E
4MEproducer result is forwarded to consumer Execute
5WM
6-W

Answer with forwarding: 0 stall cycles for this arithmetic RAW. Lösung 10 pages 1-5 explicitly says arithmetic dependencies can be handled by forwarding; only the direct lw -> consumer case needs one stall because the loaded data is not early enough.

7c) Instruction and Branch/Jump Count

Dynamic instruction sequence:

#0, #1, #2, #3, #4, #5, #2, #3, #6, #7

Therefore:

If an examiner informally says "Spruenge" and excludes ret, then the loop-internal taken transfers are 2: j .Lloop and the taken beqz .Lend. For a rigorous answer, write both the counting convention and the number.

7d) Single-Cycle and Pipeline Cycles

Eintakt-Prozessor:

10 dynamic instructions * 1 cycle/instruction = 10 cycles

Pipeline-Prozessor with current Übung/Vorlesung assumptions:

Pipeline cycles = N + 4 + stalls + flushes
                = 10 + 4 + 0 + 0
                = 14 cycles

Full no-stall Pipeline table:

Dyn. instr.Static #1234567891011121314
I1#0FDEMW
I2#1FDEMW
I3#2FDEMW
I4#3FDEMW
I5#4FDEMW
I6#5FDEMW
I7#2FDEMW
I8#3FDEMW
I9#6FDEMW
I10#7FDEMW

Second occurrence of the same RAW:

Why not 15? The Recall answer 15 would require one extra stall. Under the current Lösung 10 rule, arithmetic dependencies are solved by forwarding and only a direct load-use dependency requires one stall. Since the task additionally removes Control Hazards by correct prediction, the source-verified cycle count is 14. If a different datapath variant resolves branch comparison in Decode with only M/W-to-D forwarding, then the #2 -> #3 branch-data dependency can cost one stall and give 15; that is a variant assumption, not the default current Übung 10 calculation.

Recall-Answer Audit

Recall claimCorrect?Audit
First pipeline snapshot is 4,3,2,1,0.Mostly correctCorrect if interpreted as cycle 5 in stage order F,D,E,M,W: #4,#3,#2,#1,#0.
First hazard is between #2 and #3.Correct#2 writes a0; #3 tests a0.
7b without forwarding = 2 stalls.CorrectMatches register writeback timing used in Übung 10.
7b with forwarding = 0 stalls.CorrectArithmetic RAW can be forwarded to Execute.
Program needs 10 steps/instructions.CorrectDynamic trace has 10 numbered instructions.
There are 2 jumps.PartialLoop-internal taken transfers excluding ret are 2. Total executed control-flow instructions are 5; total taken control transfers including ret are 3.
Eintakt = 10 cycles.CorrectOne instruction per cycle.
Pipeline = 15 cycles.Not verified under current defaultCurrent Übung 10 model gives 10 + 4 = 14 with forwarding and correct prediction.

First error in the recalled solution: it does not state the branch/jump counting convention and then uses 15 Pipeline cycles without justifying an extra stall. Violated rule: cycle formulas must include only actually present stalls/flushes (Lösung 10 pages 4-5).

Wrong-Answer Explanations

Wrong answer 1: "The first hazard is #1 -> #4 on t0."

Why students choose it: #1 writes t0, and #4 later increments t0.

Why wrong: It is a RAW dependency, but not the first one in time. The #2 -> #3 dependency on a0 appears earlier in the first loop iteration.

Fast check: Build the cycle table up to cycle 5. #3 is already in Decode while #2 is in Execute.

Correct approach: Always inspect dynamic adjacency first, not just register names in the static code.

Wrong answer 2: "Pipeline cycles are 10 because ideal CPI is 1."

Why students choose it: They remember "Pipeline has CPI about 1".

Why wrong: A five-stage Pipeline must be filled and drained. Even with no stalls, N instructions need N + 4 cycles.

Fast check: One instruction alone still needs F/D/E/M/W = 5 cycles, not 1 cycle.

Correct approach: Use N + stages - 1, then add stalls/flushes.

Wrong answer 3: "There are only 8 instructions because the listing has #0 to #7."

Why students choose it: They count static instructions.

Why wrong: The loop executes #2 and #3 twice. Dynamic count is 10.

Fast check: Trace a0: 2 -> 1 -> 0; this requires two executions of srli.

Correct approach: Write the dynamic sequence before counting.

Wrong answer 4: "With forwarding, every hazard disappears, including load-use."

Why students choose it: They overgeneralize forwarding.

Why wrong: Lösung 10 pages 1-5 explicitly says a direct lw -> consumer still needs one stall because loaded data is available too late. This Aufgabe has no lw, so zero stalls here, but that is not a universal rule.

Fast check: Ask whether the producer result is an ALU result or memory-loaded data.

Correct approach: ALU-to-ALU or ALU-to-branch in Execute can usually forward; direct load-use needs one stall.

Exam-Room Method

Time budget:

First table to write:

step:  1   2   3   4   5   6   7   8   9   10
instr: #0  #1  #2  #3  #4  #5  #2  #3  #6  #7
a0:    2   2   1   1   1   1   0   0   1   1
t0:    -   0   0   0   1   1   1   1   1   1

Partial credit:

Last check:

Active Recall

Questions

  1. Concept check: What is a RAW Data Hazard in a five-stage Pipeline?
  2. Hand trace: For a0 = 2, write the dynamic instruction sequence of the clog2 code.
  3. Cycle table: At the first #2 -> #3 hazard, which static instruction is in each stage F/D/E/M/W?
  4. Transfer: If the initial value were a0 = 4, how many times would #2 srli execute before .Lend?
  5. Transfer: In lw t0, 0(a0); addi t1, t0, 1, how many stalls are needed with forwarding in the current Übung 10 model?

Answers

  1. A RAW Data Hazard occurs when a younger instruction reads a register before the older instruction has produced/written the value it must read.
  2. #0, #1, #2, #3, #4, #5, #2, #3, #6, #7.
  3. Cycle 5: F #4, D #3, E #2, M #1, W #0.
  4. a0 = 4 -> 2 -> 1 -> 0, so #2 executes three times.
  5. One stall. Direct load-use still needs one stall even with forwarding.

Sources

Completion Check