A compulsory miss occurs when the CPU accesses a memory block for the first time and that block is not yet present in the cache. Fetching the block into a cache line can make nearby accesses cache hits. section 12.1.2
Walking through 16 int64 elements
When sum first accesses s[0], the CPU fetches its memory block, producing a compulsory miss. Accesses to s[1] through s[7] hit the same cache line. Accessing s[8] fetches another block and causes a second compulsory miss; s[9] through s[15] then hit. The complete iteration therefore produces two compulsory misses and fourteen cache hits. section 12.1.2
func sum(s []int64) int64 {
var total int64
length := len(s)
for i := 0; i < length; i++ {
total += s[i]
}
return total
}
Use the sequential sum function to relate array traversal to cache-line fetching; the accompanying figures show the blocks fetched by s[0] and s[8]. section 12.1.2
