Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void iplc_sim_LRU_replace_on_miss( int index, int tag )
- {
- int i=0, j=0;
- int temp;
- /* Note: item 0 is the least recently used cache slot -- so replace it */
- cache[index].assoc[cache[index].replacement[0]].tag = tag;
- /* percolate everything up */
- for (i = 0, j = 1; j < cache_assoc; i++, j++)
- {
- temp = cache[index].replacement[i];
- cache[index].replacement[i] = cache[index].replacement[j];
- cache[index].replacement[j] = temp;
- }
- }
- void iplc_sim_LRU_update_on_hit( int index, int assoc )
- {
- int i=0, j=0;
- int temp;
- for (i = 0; i < cache_assoc; i++)
- {
- if (cache[index].replacement[i] == assoc)
- {
- if (i == cache_assoc - 1) return;
- for (j = i + 1; j < cache_assoc; i++, j++)
- {
- temp = cache[index].replacement[i];
- cache[index].replacement[i] = cache[index].replacement[j];
- cache[index].replacement[j] = temp;
- }
- return;
- }
- }
- }
- int iplc_sim_trap_address( unsigned int address )
- {
- int i=0, index=0;
- int tag=0;
- int hit=0;
- index = (address >> cache_blockoffsetbits ) % (1 << cache_index);
- tag = (address >> (cache_index + cache_blockoffsetbits));
- for( i = 0; i < cache_assoc; i++ )
- {
- if(cache[index].assoc[i].tag == tag && cache[index].assoc[i].vb)
- {
- hit = 1;
- break;
- }
- }
- if(hit)
- iplc_sim_LRU_update_on_hit(index, i);
- else
- iplc_sim_LRU_replace_on_miss(index, tag);
- /* expects you to return 1 for hit, 0 for miss */
- return(hit);
- }
Add Comment
Please, Sign In to add comment