c# - How does a cache actually store data in the "offset"? -


so computer architecture class have simulate cache/memory relationship on c# , i'm not sure how cache stores data. concept of cache tag, don't offset.

so have ram holds 256 32bit integers. want have caching system have cache holds 8 32bit integers. in 32bit integers in cache need add tag , valid bit, makes sized down 26 bits or so. how can store 32 bit data in remaining 26 bits?

here code have right now, it's still work in progress

class memory {     public list<uint32> instructions = new list<uint32>();      const int directcachesize = 8;     ulong[] directcache = new ulong[directcachesize];      private int[] stack = new int[256];      public int this[int i]     {                 {             int directmapindex = % directcachesize;             if (directcache[directmapindex] == convert.touint64(stack[i]))             {                 return convert.toint32(directcache[directmapindex] - 18446744069414584320);             }             else             {                 directcache[directmapindex] = (convert.touint64(i) << 32) + convert.touint64(stack[i]);                 return stack[i];             }         }         set         {             stack[i] = value;         }     } } 

i've been trying understand incoherent question , think i've got it.

i thinking fundamental error bits used maintain cache data structure bits subtracted data size; doesn't make sense. added data size.

but realized no, fundamental error have confused bits bytes. subtracting 6 bits 32 bytes nonsensically 26, should adding 6 bits 32 x 8 bits.

the error plain confusing seem have confused offset data block data block itself. data block stores data. the offset identifies location of relevant data within data block. offset part of effective address, not cache line!

you seem have forgotten dirty bit throughout.

so single block in direct map cache this: [tag 5bit][data 32bit]

no. number of times 32 appears in problem has confused deeply:

  • eight 32 bit words 32 bytes
  • five bits can represent 32 possible tags
  • if have 32 tags , 1024 bytes each tag identifies 32 bytes

that's lot of 32s , you've confused them terribly.

start over.

suppose want single line 8 32 bit words in it, total of 32 bytes. has in single cache line?

  • the 32 bytes -- not bits
  • a tag identifying 32 bytes came from
  • one validity bit
  • one dirty bit

if assume 32 bytes can on 32-byte boundaries, , there 1024 / 32 = 32 such boundaries, tag need log2(32) = 5 bits, total cache line size be:

  • 32 bytes not bits of data
  • 5 bits of tag
  • one validity bit
  • one dirty bit

make sense?


Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -