title: Hit / Miss rate counting by array caching
body: <p>I'm reading Computer Systems book from Bryant &amp; O'Hallaron, there is an exercises the solution of which seems to be incorrect. So I'd like to make it sure</p>
  
  <p>given </p>
  
  <pre><code>struct point {
    int x; 
    int y;  };
  
  
  struct array[32][32];
  
  for(i = 31; i &gt;= 0; i--) {
     for(j = 31; j &gt;= 0; j--) {
        sum_x += array[j][i].x;
        sum_y += array[j][i].y; }}
  </code></pre>
  
  <p><code>sizeof(int) = 4;</code></p>
  
  <p>we have 4096 byte cache with block (line) size 32 byte. 
  The hit rate is asked.  </p>
  
  <p>My reasoning was, we have <code>4096/32 = 128</code> blocks, each block can store 4 points (<code>2*4*4 = 32</code>), therefore the cache can store 1/2 of the array, i.e. 512 points (total 32*32 = 1024). Since the code accesses array in column major order, access to each point is miss. So we have <code>array[j][i].x</code> is always miss, while <code>array[j][i].y</code> is hit. Finally <em>miss rate = hit rate = 1/2</em>. </p>
  
  <p><strong>Problem:</strong> The solution says the hit rate is 3/4 because the cache can store the whole array. </p>
  
  <p>But according to my reasoning the cache can store only half points</p>
  
  <p>Did I miss something? </p>