C 1 2 3 4 5 6 7 333 codememmatmultmmc 1 2 3 4 5 6 7

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: on. This is minimized for ½, so the stride-1 references to v are indeed cache-friendly. For example, suppose that v is block-aligned, words are 4-bytes, cache blocks are 4 words, and the cache is initially empty (a cold cache). Then regardless of the cache organization, the references to v will result in the following pattern of hits and misses: 6.5. WRITING CACHE-FRIENDLY CODE v[i] Access order, [h]it or [m]iss ¼ ½ ¾ ¿ 323 1 [m] 2 [h] 3 [h] 4 [h] 5 [m] 6 [h] 7 [h] 8 [h] In this example, the reference to v[0] misses and the corresponding block, which contains v[0]–v[3], is loaded into the cache from memory. Thus, the next three references are all hits. The reference to v[4] causes another miss as a new block is loaded into the cache, the next three references are hits, and so on. In general, three out of four references will hit, which is the best we can do in this case with a cold cache. To summarize, our simple sumvec example illustrates two important points about writing cache-friendly code: ¯ ¯ Repeated references to local variables are good because the compiler can...
View Full Document

This note was uploaded on 09/02/2010 for the course ELECTRICAL 360 taught by Professor Schultz during the Spring '10 term at BYU.

Ask a homework question - tutors are online