Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Let's assume it's accessed sequentially: </p> <pre><code>for (int i=0; i&lt;1024; ++i) read(A[i]); </code></pre> <p>In that case, you'll fill the first 64 elements (<code>A[0]</code> through <code>A[63]</code>) into the 32 cache blocks in adjacent pairs like MSalters said. </p> <p>The next access would have to kick out the least recently used line, which, since you access the array in sequential order is A[64]. It would have to pick a victim to kick out, and since you're using LRU that would be the first block (way 0). You therefore replace <code>A[0]</code> and <code>A[1]</code> with <code>A[64]</code> and <code>A[65]</code> and so on, so in general you'll have element <code>i</code> mapped into way <code>floor(i/2)%32</code>.</p> <p>Now computing the hit rate requires an additional assumption - each memory line fetched is the size of a full block (8 bytes), since you can't fill half blocks (actually there are ways using mask bits, but let's assume the simple case). We therefore get each second element "for free" - fetching <code>A[0]</code> would also fetch <code>A[1]</code> and so on. In theory this means that the hit rate could be 50% (miss even elements, hit odds, in reality most CPUs would perform the accesses in parallel so you won't really have that hit rate, but let's say the accesses are serialized here).</p> <p>Note that each new block fetched after the first 64 elements would have to evict a block from the cache, if processing the elements also modifies them you'll have to write them back too.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload