This preview shows page 1. Sign up to view the full content.
Unformatted text preview: s typically occur when programs access arrays whose sizes are a power of two. For example, consider a function that computes the dot product of two vectors:
1 2 3 4 5 6 7 8 9 float dotprod(float x[8], float y[8]) { float sum = 0.0; int i; for (i = 0; i < 8; i++) sum += x[i] * y[i]; return sum; } This function has good spatial locality with respect to x and y, and so we might expect it to enjoy a good number of cache hits. Unfortunately, this is not always true. Suppose that ﬂoats are 4 bytes, that x is loaded into the 32 bytes of contiguous memory starting at address 0, and that y starts immediately after x at address 32. For simplicity, suppose that a block is 16 bytes (big enough to hold four ﬂoats) and that the cache consists of two sets, for a total cache size of 32 bytes. We will assume that the variable sum is actually stored in a CPU register and thus doesn’t require a memory reference. Given these assumptions, each x[i] and y[i] will map to the identical cache set: Element x[0] x[1...
View Full
Document
 Spring '10
 Schultz
 The American

Click to edit the document details