mirror of
https://github.com/Comp211-SP24/lab-05-Rushilwiz.git
synced 2025-04-09 14:50:19 -04:00
task1 for shits and giggles
This commit is contained in:
parent
719bb0e4df
commit
25e9b0edf8
27
cache.c
27
cache.c
|
@ -42,8 +42,6 @@ int initialize_cache(unsigned int number_of_lines) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int cread(unsigned int cmf, unsigned int* hex_addr, bool* hit, bool* replace) {
|
int cread(unsigned int cmf, unsigned int* hex_addr, bool* hit, bool* replace) {
|
||||||
// TODO:
|
|
||||||
|
|
||||||
// Either the value at the requested hexadecimal address or FAIL
|
// Either the value at the requested hexadecimal address or FAIL
|
||||||
int ret_val = FAIL;
|
int ret_val = FAIL;
|
||||||
|
|
||||||
|
@ -52,6 +50,15 @@ int cread(unsigned int cmf, unsigned int* hex_addr, bool* hit, bool* replace) {
|
||||||
// hex_addr
|
// hex_addr
|
||||||
unsigned int line, tag, block_offset;
|
unsigned int line, tag, block_offset;
|
||||||
|
|
||||||
|
if (cmf == DM) {
|
||||||
|
line = bit_select(*hex_addr, addr_bits - NUM_LINE_BITS, addr_bits - 1);
|
||||||
|
} else {
|
||||||
|
line = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
tag = bit_select(*hex_addr, 0, addr_bits - NUM_LINE_BITS - 1);
|
||||||
|
block_offset = bit_select(*hex_addr, 0, NUM_BLOCK_OFFSET_BITS - 1);
|
||||||
|
|
||||||
// (Optional) Indicates a line that is open and thus usable
|
// (Optional) Indicates a line that is open and thus usable
|
||||||
int open_line;
|
int open_line;
|
||||||
// (Optional) For DM, indicates the cache line that should be replaced
|
// (Optional) For DM, indicates the cache line that should be replaced
|
||||||
|
@ -69,7 +76,21 @@ int cread(unsigned int cmf, unsigned int* hex_addr, bool* hit, bool* replace) {
|
||||||
*replace = false;
|
*replace = false;
|
||||||
|
|
||||||
if ((cmf == DM) && ((*hex_addr) < exp2(addr_bits))) {
|
if ((cmf == DM) && ((*hex_addr) < exp2(addr_bits))) {
|
||||||
// TODO: Part 1
|
if (cache[line]->tag == tag) {
|
||||||
|
// hit
|
||||||
|
*hit = true;
|
||||||
|
cache[line]->hit_count++;
|
||||||
|
ret_val = cache[line]->block[block_offset];
|
||||||
|
} else {
|
||||||
|
// miss
|
||||||
|
*replace = true;
|
||||||
|
cache[line]->tag = tag;
|
||||||
|
cache[line]->hit_count = 1;
|
||||||
|
cache[line]->block[block_offset] =
|
||||||
|
phy_memory[block_location[*hex_addr]];
|
||||||
|
ret_val = cache[line]->block[block_offset];
|
||||||
|
}
|
||||||
|
|
||||||
} else if ((cmf == FA) && ((*hex_addr) < exp2(addr_bits))) {
|
} else if ((cmf == FA) && ((*hex_addr) < exp2(addr_bits))) {
|
||||||
// TODO: Part 2
|
// TODO: Part 2
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user