Memory caching question

Gamingphreek

Lifer
Mar 31, 2003
11,679
0
81
Hey Guys,

I am studying for my exam which I am taking early tomorrow; however, I still don't understand one concept that I know will show up on the test.

When mapping to a direct mapped 8-block, 1-word/block cache, the high 2 bits are the tag and the low 3 bits are the index. So for example, 22 (10110) would get mapped to index 110 with the tag 10.

Later on there is an example of a direct mapped 64-block, 16-bytes/block cache. The low 4 bits are ignored and bits [31:10] are the tag, bits [9:4] are the index, and then it says offset for bits [4:0].

We are then given a diagram where the low 2 bits are ignored for what it says is byte offset.

The only thing the book says on this matter is "In the MIPS architecture, since words are aligned to multiples of four bytes, the least significant two bits of every address specify a byte within a word. hence, the least significant two bits are ignored when selecting a word in the block".

Can ANYONE help me understand when to ignore the low x number of bits and why I do that?

Thanks,
-Kevin


----
Moved from OT
At Mod Evadman
 

RedArmy

Platinum Member
Mar 1, 2005
2,648
0
0
I'm taking the exact same type of exam later this week. I have no idea what I'm doing...worst class I ever took.
 

Leros

Lifer
Jul 11, 2004
21,867
7
81
Are we talking about computer architecture?

I'm taking that next semester. Its supposed to be horribly hard and have an extreme workload.
 

Gamingphreek

Lifer
Mar 31, 2003
11,679
0
81
I understand everything else and am extremely confident about this exam. I just am trying to understand when to use the byte offset and when not to. I understand that since MIPS word size is 4 bytes, the low 2 bits are useless - but I still don't know when to use them. The best I have come up with is to offset only when they specify the block size in bytes and not words (Because they could say 8 bytes/block, in which case you need the low 2 bits)

I'm just not 100% sure.

As for the class - it is tough, but very interesting. You learn a ton. OS is where it is extremely hard.

-Kevin
 

smack Down

Diamond Member
Sep 10, 2005
4,507
0
0
Originally posted by: Gamingphreek
I understand everything else and am extremely confident about this exam. I just am trying to understand when to use the byte offset and when not to. I understand that since MIPS word size is 4 bytes, the low 2 bits are useless - but I still don't know when to use them. The best I have come up with is to offset only when they specify the block size in bytes and not words (Because they could say 8 bytes/block, in which case you need the low 2 bits)

I'm just not 100% sure.

As for the class - it is tough, but very interesting. You learn a ton. OS is where it is extremely hard.

-Kevin

I think you have the right idea.

You use the offset when the block of cache contains more then 1 bit.
 

Chris27

Member
Sep 19, 2005
140
0
0
I don't think think you should be ignoring any of the bits (unless your block size is 1 byte then you wouldn't need a block offset)

The cache has a number of sets denoted by S = 2^s where s is the number of bits required to address the set (in your case, 8 blocks so S = 8 and s = 3)
E is the number of lines per set (your cache is direct map so E = 1)
The block size is B = 2^b (in your case B = 1 word = 4 bytes (usually) => b = 2)

M = 2^m is the size of your physical address space (for a 32 bit system M = 2^32, m = 32)

The physical address has the form of:
t bits, s bits, b bits, where the t bits correspond to the cache tag, the s bits correspond to the set index, and the b bits correspond to the block offset (note t = m - s + b, its just the remainder of the address bits)

So for a 64-block, 16-bytes/block cache
s = 6, b = 4, (so t = 22 on a 32 bit system).

So to find something in the cache: take the value of the s bits. This is your set index. take the value of your b bits. This is your block offset. Look at the corresponding set. If the valid bit is set and the tag matches with your t bits then you have a match. Index into the cache block with the value taken from the b bits. You have your value.

these slides might explain it a bit better
http://www.cs.cmu.edu/~213/lectures/12-caches-opt.pdf

Originally posted by: smack Down


You use the offset when the block of cache contains more then 1 bit.

Memory is typically byte addressable so you wouldn't have a block size other then n-bytes. The block offset gives you a byte offset not a bit offset.