【正文】
MEM/ ← Mem[EX/]。 EX/ ← ID/ 。 多個(gè)定向源 : EX/DF, DF/DS, DS/TC, TC/WB – MIPS R4000的浮點(diǎn)數(shù)操作 中國(guó)科學(xué)技術(shù)大學(xué) ALU輸入端的定向源 中國(guó)科學(xué)技術(shù)大學(xué) 中國(guó)科學(xué)技術(shù)大學(xué) MIPS R4000 浮點(diǎn)數(shù)操作 ? 3個(gè)功能部件組成: FP Adder, FP Multiplier, FP Divider ? 在乘 /除操作的最后一步要 使用 FP Adder ? FP操作需要 2( negate) 112個(gè)( square root) cycles ? 8 種類型的 FP units: Stage Functional unit Description A FP adder Mantissa ADD stage D FP divider Divide pipeline stage E FP multiplier Exception test stage M FP multiplier First stage of multiplier N FP multiplier Second stage of multiplier R FP adder Rounding stage S FP adder Operand shift stage U Unpack FP numbers 中國(guó)科學(xué)技術(shù)大學(xué) 雙精度浮點(diǎn)數(shù)操作延遲及初始化間隔 中國(guó)科學(xué)技術(shù)大學(xué) 浮點(diǎn)指令 延 遲 初始化 間隔 使用的流水段 加、減 4 3 U,S+A,A+R,R+S 乘 8 4 U,E+M,M,M,M,N,N+A,R 除 36 35 U,A,R,D28,D+A,D+R,D+A,D+R,A,R 求平方根 112 111 U,E,(A+R) 108,A,R 取反 2 1 U,S 求絕對(duì)值 2 1 U,S 浮點(diǎn)比較 3 2 U,A,R 中國(guó)科學(xué)技術(shù)大學(xué) MIPS FP 流水段 FP Instr 1 2 3 4 5 6 7 8 … Add, Subtract U S+A A+R R+S Multiply U E+M M M M N N+A R Divide U A R D28 … D+A, D+R, D+R, D+A, D+R, A, R Square root U E (A+R)108 … AR Negate U S Absolute value U S FP pare U A R Stages: M First stage of multiplier N Second stage of multiplier R Rounding stage S Operand shift stage U Unpack FP numbers A Mantissa ADD stage D Divide pipeline stage E Exception test stage 中國(guó)科學(xué)技術(shù)大學(xué) 注: Multiply Issue U M M U E+M M 中國(guó)科學(xué)技術(shù)大學(xué) 注: Multiply 的 第 2 拍的 M 〉 E+M 中國(guó)科學(xué)技術(shù)大學(xué) 中國(guó)科學(xué)技術(shù)大學(xué) 中國(guó)科學(xué)技術(shù)大學(xué) R4000性能( 1) 中國(guó)科學(xué)技術(shù)大學(xué) R4000 性能( 2) 中國(guó)科學(xué)技術(shù)大學(xué) 基本流水線小結(jié) ? 流水線提高的是指令帶寬(吞吐率),而不是單條指令的執(zhí)行速度 ? 相關(guān)限制了流水線性能的發(fā)揮 – 結(jié)構(gòu)相關(guān):需要更多的硬件資源 – 數(shù)據(jù)相關(guān):需要定向,編譯器調(diào)度 – 控制相關(guān):盡早檢測(cè)條件,計(jì)算目標(biāo)地址,延遲轉(zhuǎn)移,預(yù)測(cè) ? 增加流水線的級(jí)數(shù)會(huì)增加相關(guān)產(chǎn)生的可能性 ? 異常,浮點(diǎn)運(yùn)算使得流水線控制更加復(fù)雜 ? 編譯器可降低數(shù)據(jù)相關(guān)和控制相關(guān)的開(kāi)銷 – Load 延遲槽 – Branch 延遲槽 – Branch預(yù)測(cè) Acknowledgements ? These slides contain material developed and copyright by: – John Kubiatowicz (UCB) – Krste Asanovic (UCB) – David Patterson (UCB) – Chenxi Zhang (Tongji) ? UCB material derived from course CS15CS25 CS61C ? KFUPM material derived from course COE50COE502 116 中國(guó)科學(xué)技術(shù)大學(xué) 中國(guó)科學(xué)技術(shù)大學(xué) Review ? 流水線技術(shù)并不能提高單個(gè)任務(wù)的執(zhí)行效率,它可以提高整個(gè)系統(tǒng)的吞吐率 – 多個(gè)任務(wù)同時(shí)執(zhí)行,但使用不同的資源 ? 流水線性能分析:吞吐率、加速比、效率 – 流水線中的瓶頸 ——最慢的那一段 – 其潛在的加速比=流水線的級(jí)數(shù) – 流水段所需時(shí)間不均衡將降低加速比 – 流水線存在裝入時(shí)間和排空時(shí)間,使得加速比降低 ? 由于存在相關(guān)問(wèn)題,會(huì)導(dǎo)致流水線停頓 – 結(jié)構(gòu)相關(guān)、數(shù)據(jù)相關(guān)和控制相關(guān) 中國(guó)科學(xué)技術(shù)大學(xué) Quiz 流水線的成本( cost)可以用 c+k*h估算,其中 c為所有功能段本身的總成本, h為段間鎖存器成本, k為段數(shù)。 不發(fā)射那些目的寄存器與待寫(xiě)寄存器列表中的指令有 WAW沖突的指令,延遲 1個(gè) cycle發(fā)射 。 Unconditional = 14%, 65% change PC P i p e l i n e s p e ed u p = P i p e l i n e d ep t h1 + B r a n c h f r e q u en cy ? B r a n c h p en al t y中國(guó)科學(xué)技術(shù)大學(xué) 03/08Review:流水線性能分析 流水線技術(shù)應(yīng)用的難度何在 ? :相關(guān)問(wèn)題 相關(guān)的類型: 結(jié)構(gòu)相關(guān),控制相關(guān),以及 數(shù)據(jù)相關(guān)( RAW, WAR, WAW) 吞吐率、加速比、效率之間的關(guān)系 ktTPEtntktnEtnttnStntnTPtTPkiikijikijkijikiikijii?????????????????????????????????????111111ma x])1([)1()1(}m a x {1中國(guó)科學(xué)技術(shù)大學(xué) ? 指令流水線: CPU執(zhí)行大量的指令,指令吞吐率非常重要 ? MIPS 的 ISA: RISC 03/08Review: MIPS的基本流水線 中國(guó)科學(xué)技術(shù)大學(xué) 03/08Review ? 相關(guān)會(huì)影響流水線性能 ? 結(jié)構(gòu)相關(guān) : 由于爭(zhēng)用資源而引起的 – 解決辦法 : 等待 增加(或拆分)資源 ? 數(shù)據(jù)相關(guān):兩條指令訪問(wèn)相同的數(shù)據(jù)而引起的 – 解決辦法: 187。 優(yōu)點(diǎn): 簡(jiǎn)單。 kSE?當(dāng) E=1時(shí), S=k,實(shí)際加速比達(dá)到最大?!?t Tk 流水線技術(shù)提高系統(tǒng)的任務(wù)吞吐率 中國(guó)科學(xué)技術(shù)大學(xué) – 流水線完成 n個(gè)連續(xù)任務(wù)所需要的總時(shí)間為 (假設(shè)一條 k段 線性流水線) Tk= kΔ t+ (n1)Δ t= (k+ n1)Δ t – 流水線的 實(shí)際吞吐率 tnknTP???? )1(? ? ttnknTPn ????????11l i mm a x? 最大吞吐率 :流水線在連續(xù)流動(dòng)達(dá)到穩(wěn)定狀態(tài)后所得到的吞吐率。缺點(diǎn): 控制邏輯比較復(fù)雜,所需的硬件增加了。 當(dāng)前指令的執(zhí)行需要上一條指令的結(jié)果 ? 使用等待策略總是可以解決相關(guān) – 流水線控制必須能檢測(cè)相關(guān),否則由軟件設(shè)計(jì)來(lái)避免 – 采用相應(yīng)操作解決相關(guān) (or 等待 ) 中國(guó)科學(xué)技術(shù)大學(xué) Mem 單個(gè)存儲(chǔ)器引起的結(jié)構(gòu)相關(guān) I n s t r. O r d e r Time (clock cycles) Load Instr 1 Instr 2 Instr 3 Instr 4 ALU Mem Reg Mem Reg ALU Mem Reg Mem Reg ALU Mem Reg Mem Reg ALU Reg Mem Reg ALU Mem Reg Mem Reg Detection is easy in this case! (right half highlight means read, left half write) 中國(guó)科學(xué)技術(shù)大學(xué) 消除結(jié)構(gòu)相關(guān) I n s t r. O r d e r Time (clock cycles) Load Instr 1 Instr 2 Stall Instr 3 Reg ALU DMem Ifetch Reg Reg ALU DMem Ifetch Reg Reg ALU DMem Ifetch Reg Cycle 1 Cycle 2 Cycle 3 Cycle 4 Cycle 6 Cycle 7 Cycle 5 Reg ALU DMem Ifetch Reg Bubble Bubble Bubble Bubble Bubble 中國(guó)科學(xué)技術(shù)大學(xué) 結(jié)構(gòu)相關(guān)對(duì)性能的影響 ? 例如 : 如果每條指令平均訪存 次,而每個(gè)時(shí)鐘周期只能訪存一次,那么 – 在其他資源 100%利用的前提下,平均 CPI ? 中國(guó)科學(xué)技術(shù)大學(xué) 流水線的加速比計(jì)算 p ip el in eddu n p ip el in e T i m eC ycle T i m eC ycle C P I s tall P i p e lin e C P I I d e a ld e p th P i p e lin e C P I I d e a l S p e e d u p ????p ip el in eddu n p ip el in e T i m eC ycle T i m eC ycle C P I s tall P i p e lin e 1d e p th P i p e lin e S p e e d u p ???I n s tp e r cy cl e s S t al l A v e r ag e C P I I d e al C P I p ip el in ed ??For simple RISC pipeline, CPI = 1: 中國(guó)科學(xué)技術(shù)大學(xué) 例如: Dualport vs. Singleport ? 機(jī)器 A: Dual ported memory (―Harvard Architecture‖) ? 機(jī)器 B: Single ported memory ? 存在結(jié)構(gòu)相關(guān)的機(jī)器 B的時(shí)鐘頻率是機(jī)器 A的時(shí)鐘頻率的 ? Ideal CPI = 1 ? 在機(jī)器 B中 load指令會(huì)引起結(jié)構(gòu)相關(guān),所執(zhí)行的指令中 Loads指令占 40% Average instruction time = CPI * Clock