title: Cache friendly C code
body: <p>I want to calculate the cache miss rate per loop iteration of using this code-snippet:</p>
  
  <pre><code>int x[2][256];
  int i;
  int sum = 0;
  
  for(i = 1;i &lt; 256; i++) {
      sum += x[0][i] * x[1][i];
  }
  </code></pre>
  
  <p>Assumptions:</p>
  
  <ol>
  <li>Array x starts at 0x0</li>
  <li>Cache is empty</li>
  <li>Direct mapped cache with size 1024 byte and blocksize 32 byte</li>
  </ol>
  
  <p>I would say we have a miss rate of one miss per loop iteration because we are also going through the colums of x. Is it right?</p>
  
  <p>Next question: What is the miss rate if the cache size is 2048 byte?</p>