title: How to write instruction cache friendly program in c++?
body: <p>Recently Herb Sutter gave a great talk on <a href="http://channel9.msdn.com/Events/Build/2014/2-661" rel="noreferrer">"Modern C++: What You Need to Know"</a>. The main theme of this talk was efficiency and how data locality and accessing the memory matters.
  He has also explained how linear access of memory(array/vector) would be loved by CPU. He has taken one example from another classical reference <a href="http://gameprogrammingpatterns.com/data-locality.html" rel="noreferrer">"Game performance by Bob Nystrom"</a> on this topic.</p>
  
  <p>After reading these articles, I got that there is two type of cache which impact the program performance:</p>
  
  <ol>
  <li>Data Cache</li>
  <li>Instruction Cache</li>
  </ol>
  
  <p><a href="http://valgrind.org/docs/manual/cg-manual.html" rel="noreferrer">Cachegrind</a> tool also measures both cache type instrumentation information of our program. The first points has been explained by many article/blog and how to achieve the good data cache efficiency(data locality).</p>
  
  <p>However I did not get much information on topic <strong>Instruction Cache</strong> and what sort of thing we should take care in our program to achieve the better performance?. As per my understanding, we(programmer) do not have much control on which instruction or what order would be executing. </p>
  
  <p>It would be really nice if small c++ programs explains how this counter(.i.e instruction cache) would vary with our style of writing program. What are the best practice programmer should follow to achieve better performance with respect to this point?</p>
  
  <p>I mean we can understand about data cache topics if our program does(vector vs list) in similar way does it possible to explain about 2nd point. The main intention of this question is to understand this topic as much as possible.</p>