Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

CS 354 - Machine Organization

Monday, October 10, 2016

Project p3 (6%) due 10 pm Monday, October 24th (exam week)


Homework hw4 (1.5%) due 10 pm Friday, October 14th
Last Time
Ordering Free Blocks by Address
Ordering Free Blocks by LIFO
Heap Caveats
Three Faces of Memory
Today
Three Faces of Memory (from last time)
Locality
Memory Hierarchies
Next Time
Read: B&O 6.4 intro - 6.4.2
Cache Memories

Copyright 2016 Jim Skrentny

CS 354 (F16): L15 - 1

Locality


Why?

Temporal Locality

Spatial Locality

Example
int sumArray(int a[], int size, int stride) {
int sum = 0;
for (int i = 0; i < size; i += stride)
sum += a[i];
return sum;
}

 List the variables that demonstrate spatial locality.

 List the variables that demonstrate temporal locality.

Copyright 2016 Jim Skrentny

CS 354 (F16): L15 - 2

Bad Locality
Why is this code bad?
int a[ROWS][COLS];
for (int c = 0; c < COLS; c++)
for (int r = 0; r < ROWS; r++)
a[r][c] = r * c;

Why is this code bad?


struct {
float rgb[3];
float hsl[3];
} image[HEIGHT][WIDTH];
for (int v = 0; v < 3; v++)
for (int c = 0; c < WIDTH; c++)
for (int r = 0; r < HEIGHT; r++) {
image[r][c].rgb[v] = 0;
image[r][c].hsl[v] = 0;
}

Good or bad locality?

 Instruction Flow:

 Searching Algorithms:

Copyright 2016 Jim Skrentny

CS 354 (F16): L15 - 3

Memory Hierarchies

L0:
Registers

L1: Cache

L2: Cache

L3: Cache

L4: Main Memory

L5: Local Secondary Storage

L6: Network Storage

Copyright 2016 Jim Skrentny

CS 354 (F16): L15 - 4

You might also like