Data Hazard (RAW) ADD R 1, R 2, R 3 SUB R 4, R 1, R 5 IF ID R IF EX MEM ID EX R Time WB W MEM WB W
Data Hazard 해결 n Freezing the Pipeline n (Internal) Operand Forwarding n Compiler Scheduling
(Internal) Forwarding
Compiler Scheduling n 지연된 로드 (delayed load) n n 컴파일러를 통해서 충돌문제를 해결하는 것으로 데이타 충돌을 감지하고 충돌된 데이터의 참조가 지연되도록 명 령어들을 재배치 (ex) LW LW ADD Naive Code SW LW LW SUB SW a = b + c; d = e - f; Rb, b Rc, c Ra, Rb, Rc a, Ra Re, e Rf, f Rd, Re, Rf d, Rd Scheduled Code LW LW LW ADD LW SW SUB SW Rb, b Rc, c Re, e Ra, Rb, Rc Rf, f a, Ra Rd, Re, Rf d, Rd
Data Hazard 종류 실행 순서: Task(i) Task(j) n n n RAW n j tries to read a source before i writes it n So j incorrectly gets the old value WAR n j tries to write a destination before it is read by i n So i incorrectly gets the new value WAW n j tries to write an operand before it is written by i n The write being performed in the wrong order
Control Hazard n 원인: PC 레지스터 값의 변화 (instruction 수행순서 변화) n Branch, Jump, Call/Return For 5 -stage pipeline, 3 cycle penalty 15% branch frequency. CPI = 1. 45
Control Hazard 해결 n Optimized branch processing n Branch prediction (분기 예측) n Delayed branch (지연된 분기)
Optimized Branch 1. Find out branch taken or not early -> simplified branch condition 2. Compute branch target address early -> extra hardware 3. Read both addresses (taken or not)