title: Return address prediction stack buffer vs stack-stored return address?
body: <p>Have been reading Agner Fog's "The microarchitecture of Intel, AMD and VIA CPUs" and on page 34 he describes "return address prediction":</p>
  
  <p><a href="http://www.agner.org/optimize/microarchitecture.pdf" rel="noreferrer">http://www.agner.org/optimize/microarchitecture.pdf</a></p>
  
  <blockquote>
    <p>3.15 Returns (all processors except P1) </p>
    
    <p>A better method is used for returns. A Last-In-First-Out buffer,
    called the return stack buffer,remembers the return address every time
    a call instruction is executed, and it uses this for predicting where
    the corresponding return will go. This mechanism makes sure that
    return instructions are correctly predicted when the same subroutine
    is called from several  different locations.</p>
  </blockquote>
  
  <p>I am a little unclear what the need for this is, given that the return addresses are stored on the stack anyway?</p>
  
  <p>So what is the purpose of storing return addresses on the stack if there is also this technique? Is the stack-stored value only used if this prediction technique doesnt work?</p>