branch predic on
play

Branch Predic,on J. Nelson Amaral Why Branch Predic,on? - PowerPoint PPT Presentation

Branch Predic,on J. Nelson Amaral Why Branch Predic,on? Every 5-7 instruc,on of a program is a branch Not predic,ng, or miss-predic,ng, is


  1. Branch ¡Predic,on ¡ J. ¡Nelson ¡Amaral ¡

  2. Why ¡Branch ¡Predic,on? ¡ • Every ¡5-­‑7 ¡instruc,on ¡of ¡a ¡program ¡is ¡a ¡branch ¡ • Not ¡predic,ng, ¡or ¡miss-­‑predic,ng, ¡is ¡very ¡ costly ¡in ¡architectures ¡with ¡deep ¡pipelines ¡or ¡ with ¡many ¡func,onal ¡units. ¡ Baer ¡p. ¡129 ¡

  3. Anatomy ¡of ¡a ¡Predictor ¡ Baer ¡p. ¡130 ¡

  4. Anatomy ¡of ¡a ¡Branch ¡Predictor ¡ Prog. ¡Exec. ¡ • Event ¡Source : ¡the ¡execu,on ¡of ¡the ¡program ¡ – Predic,ve ¡informa,on: ¡ • Can ¡be ¡encoded ¡in ¡the ¡instruc,on ¡code ¡ ¡ – a ¡bit ¡indicates ¡most ¡likely ¡outcome ¡ – forward/backward ¡branch ¡ • Obtained ¡from ¡some ¡profiling ¡informa,on ¡ Baer ¡p. ¡130 ¡

  5. Anatomy ¡of ¡a ¡Branch ¡Predictor ¡(cont.) ¡ Event ¡Selec. ¡ • Event ¡Selec-on : ¡when ¡to ¡predict? ¡ – Simple ¡solu,on: ¡compute ¡the ¡predic,on ¡for ¡every ¡ instruc,on ¡(even ¡non-­‑branches) ¡ • Only ¡use ¡the ¡result ¡of ¡the ¡predic,on ¡for ¡branches ¡ Baer ¡p. ¡130 ¡

  6. Anatomy ¡of ¡a ¡Branch ¡Predictor ¡(cont.) ¡ Pred. ¡Index. ¡ • Predic-on ¡Indexing : ¡ – Use ¡part ¡of ¡the ¡PC ¡to ¡index ¡predic,on ¡tables: ¡ • history ¡of ¡outcome ¡of ¡previous ¡branches ¡at ¡this ¡PC ¡ • history ¡of ¡execu,on ¡path ¡leading ¡to ¡this ¡PC ¡ Baer ¡p. ¡130 ¡

  7. Anatomy ¡of ¡a ¡Branch ¡Predictor ¡(cont.) ¡ Pred. ¡Mechan. ¡ • Predictor ¡Mechanism : ¡ – Sta,c ¡(example): ¡ • forward: ¡always ¡not ¡taken ¡ • backward: ¡always ¡taken ¡ – Dynamic: ¡ • Finite ¡State ¡Machine ¡predictor: ¡satura,ng ¡counters ¡ • Markov ¡predictor: ¡correla,on ¡ Baer ¡p. ¡131 ¡

  8. Anatomy ¡of ¡a ¡Branch ¡Predictor ¡(cont.) ¡ Feedback ¡ • Feedback ¡and ¡Recovery : ¡ – Use ¡real ¡outcome ¡to ¡reinforce ¡predic,on ¡ – Must ¡recover ¡from ¡miss-­‑predic,ons ¡ Baer ¡p. ¡131 ¡

  9. Control ¡Flow ¡Sta,s,cs ¡ Applica'on ¡ % ¡control ¡ % ¡cond. ¡branches ¡ % ¡Uncond. ¡ % ¡calls ¡ % ¡returns ¡ flow ¡ ¡(% ¡taken) ¡ (% ¡direct) ¡ SPEC95int ¡ 20.4 ¡ 14.9 ¡(46) ¡ 1.1 ¡(77) ¡ 2.2 ¡ 2.1 ¡ Desktop ¡ 18.7 ¡ 13 ¡(39) ¡ 1.1 ¡(92) ¡ 2.4 ¡ 2.1 ¡ A ¡4-­‑way ¡superscalar ¡has ¡to ¡predict ¡a ¡branch, ¡on ¡average, ¡ every ¡other ¡cycle. ¡ ¡ Baer ¡p. ¡131 ¡

  10. Interbranch ¡Distances ¡ 40% ¡of ¡the ¡,me ¡there ¡is ¡1 ¡or ¡0 ¡cycles ¡between ¡ predic,ons ¡ ¡ Branch ¡resolu,on ¡takes ¡+/-­‑ ¡10 ¡cycles ¡ If ¡the ¡predic,on ¡is ¡wrong, ¡up ¡to ¡40 ¡wrong ¡ instruc,ons ¡are ¡in ¡flight ¡by ¡the ¡,me ¡the ¡ resolu,on ¡occurs. ¡ Simula,on ¡for ¡a ¡4-­‑way ¡out-­‑of-­‑order ¡architecture ¡ Baer ¡p. ¡131 ¡

  11. Sta,c ¡Predic,ons ¡ ¡ OR ¡ Always ¡Taken ¡ Always ¡Not ¡Taken ¡ Baer ¡p. ¡132 ¡

  12. Sta,c ¡Predic,ons ¡ ¡ • Early ¡studies ¡indicated ¡that ¡2/3 ¡ of ¡branches ¡are ¡taken ¡ – but ¡30% ¡of ¡those ¡branches ¡were ¡ uncondi,onal! ¡ • For ¡condi,onal ¡branches ¡there ¡ appears ¡to ¡be ¡no ¡preferred ¡ direc,on. ¡ Always ¡Taken ¡ Baer ¡p. ¡132 ¡

  13. Alterna,ve ¡Sta,c ¡Predic,ons ¡ ¡ Accuracy ¡improvements ¡ are ¡barely ¡no,ceable. ¡ Sta,c ¡predic,on ¡based ¡on ¡ profiling ¡is ¡slightly ¡beber. ¡ Sta,c ¡branch-­‑not-­‑taken ¡ has ¡no ¡implementa,on ¡ cost ¡on ¡pipeline. ¡ Forward ¡Always ¡Not ¡Taken ¡ Backward ¡Always ¡Taken ¡ Baer ¡p. ¡132 ¡

  14. Dynamic ¡Predictors ¡ • Predic,on ¡of ¡a ¡given ¡branch ¡changes ¡with ¡the ¡ execu,on ¡of ¡the ¡program. ¡ – Simple : ¡a ¡finite-­‑state ¡machine ¡encodes ¡the ¡ outcome ¡of ¡a ¡few ¡recent ¡execu,ons ¡of ¡the ¡branch. ¡ – Elaborate : ¡Not ¡only ¡early ¡branch ¡outcomes, ¡but ¡ other ¡correlated ¡parts ¡of ¡the ¡programs ¡are ¡ considered. ¡ ¡ Baer ¡p. ¡132 ¡

  15. When ¡to ¡predict? ¡ • Sta,c ¡predic,on: ¡at ¡the ¡ Instruc,on ¡Decode ¡stage ¡ – Know ¡that ¡the ¡instruc,on ¡ is ¡a ¡branch ¡ • Dynamic ¡predic,on: ¡at ¡the ¡ Instruc,on ¡Fetch ¡stage ¡ – Calculate ¡predic,on ¡for ¡ every ¡instruc,on, ¡even ¡ non-­‑branch ¡ones. ¡ Baer ¡p. ¡133 ¡

  16. What ¡to ¡Predict? ¡ • Branch ¡Direc'on : ¡Is ¡branch ¡taken ¡on ¡not? ¡ • Branch ¡Target : ¡Address ¡of ¡next ¡instruc,on ¡for ¡ a ¡taken ¡branch ¡ Baer ¡p. ¡133 ¡

  17. Predic,ng ¡Direc,on ¡ • Where ¡we ¡find ¡the ¡predic,on? ¡ Look ¡at ¡the ¡recent ¡past: ¡ What ¡was ¡the ¡direc,on ¡the ¡last ¡,me ¡this ¡same ¡ branch ¡was ¡executed? ¡ • How ¡to ¡encode ¡the ¡predic,on? ¡ A ¡single ¡bit ¡encodes ¡the ¡predic,on: ¡ Predic,on ¡bit ¡is ¡set ¡at ¡predic,on ¡,me. ¡ ¡ Baer ¡p. ¡133 ¡

  18. Predic,on ¡Hysteresis ¡ • Look ¡at ¡the ¡last ¡two ¡ resolu,ons ¡ – Two ¡wrong ¡predic,ons ¡ are ¡necessary ¡to ¡change ¡ the ¡predic,on ¡ – Mo,vated ¡by ¡wrong ¡ predic,ons ¡at ¡the ¡end ¡of ¡ inner ¡loops. ¡ Baer ¡p. ¡133 ¡

  19. 2-­‑Bit ¡Satura,ng ¡Counter ¡ Last ¡instance ¡ was ¡not ¡taken ¡but ¡the ¡ Last ¡two ¡instances ¡ previous ¡was ¡taken ¡ were ¡taken ¡ Last ¡instance ¡ Last ¡two ¡instances ¡ was ¡taken ¡but ¡the ¡ were ¡not ¡taken ¡ previous ¡was ¡not ¡ Baer ¡p. ¡134 ¡

  20. 2-­‑Bit ¡Satura,ng ¡Counter ¡(Example) ¡ for(i=0 ¡; ¡i ¡< ¡m ¡; ¡i++) ¡ m ¡≤ ¡0 ¡ ¡ ¡ ¡ ¡ ¡ ¡for(j=0; ¡j<n ¡; ¡j++) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡begin ¡S1; ¡S2; ¡…; ¡Sk ¡end; ¡ i ¡← ¡0 ¡ 1-­‑bit ¡ n ¡≥ ¡0 ¡ i ¡ j ¡ Pred ¡ Outc ¡ 0 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s ¡ first ¡execu,on ¡ Average ¡of ¡26 ¡traces ¡(IBM ¡379, ¡DEC ¡PDP-­‑11, ¡CDC ¡6400) ¡ Average ¡of ¡32 ¡traces ¡(MIPS ¡R2000, ¡Sun ¡SPARC, ¡DEC ¡VAX, ¡Motorola ¡68000) ¡ ¡ 3-­‑bit ¡counters ¡yield ¡only ¡ minor ¡improvements ¡ Fix ¡predic,on. ¡Determined ¡by ¡the ¡first ¡execu,on ¡of ¡the ¡branch. ¡ ¡ Baer ¡p. ¡135 ¡

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend