title: How does Next line prediction Branch target predictor work?
body: <p>In the question <a href="https://stackoverflow.com/questions/11227809/">Why is it faster to process a sorted array than an unsorted array?</a> the answer had to do with branch predicting being bad with random order data and good with sorted data. BUT the thing is the data is the same, just the ordering was different.</p>
  
  <p>That confused me, I pretty much assumed the prediction is compile in. Its either always assume true or always assume false but apparently its dynamic. Since its dynamic how does it know which to predict? Is there data on it in the cache somewhere? I heard of code execution cache and ram cache, is there data in the cpu cache? is it only L1? </p>
  
  <p>How exactly does branch prediction adjust its prediction and where is its data to make that dynamic decision its doing?</p>