From f4a9616adc4402dbca52491d93f35da525e85c16 Mon Sep 17 00:00:00 2001 From: Rushil Umaretiya Date: Wed, 10 Apr 2024 20:31:08 -0400 Subject: [PATCH] forgot to clang --- cache.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/cache.c b/cache.c index 0340454..d4ba76a 100644 --- a/cache.c +++ b/cache.c @@ -68,7 +68,8 @@ int cread(unsigned int cmf, unsigned int* hex_addr, bool* hit, bool* replace) { if ((cmf == DM) && ((*hex_addr) < exp2(addr_bits))) { tag = bit_select(*hex_addr, addr_bits - 1, addr_bits - NUM_TAG_BITS_DM); - line = bit_select(*hex_addr, addr_bits - NUM_TAG_BITS_DM - 1, NUM_BLOCK_OFFSET_BITS); + line = bit_select(*hex_addr, addr_bits - NUM_TAG_BITS_DM - 1, + NUM_BLOCK_OFFSET_BITS); block_offset = bit_select(*hex_addr, NUM_BLOCK_OFFSET_BITS - 1, 0); if (cache[line]->tag == tag) { @@ -82,10 +83,12 @@ int cread(unsigned int cmf, unsigned int* hex_addr, bool* hit, bool* replace) { cache[line]->tag = tag; cache[line]->hit_count = 1; - unsigned int mem_index = block_location[*hex_addr >> NUM_BLOCK_OFFSET_BITS]; + unsigned int mem_index = + block_location[*hex_addr >> NUM_BLOCK_OFFSET_BITS]; + + memcpy(cache[line]->block, phy_memory + mem_index, + sizeof(unsigned int) * (int)exp2(NUM_BLOCK_OFFSET_BITS)); - memcpy(cache[line]->block, phy_memory + mem_index, sizeof(unsigned int) * (int)exp2(NUM_BLOCK_OFFSET_BITS)); - ret_val = cache[line]->block[block_offset]; } @@ -100,16 +103,17 @@ int cread(unsigned int cmf, unsigned int* hex_addr, bool* hit, bool* replace) { } void print_binary(unsigned char num) { - // Start from the most significant bit (MSB) and move to the least significant bit (LSB) + // Start from the most significant bit (MSB) and move to the least + // significant bit (LSB) for (int i = 7; i >= 0; i--) { - // Use bitwise AND to isolate the specific bit and shift right to get 1 or 0 + // Use bitwise AND to isolate the specific bit and shift right to get 1 + // or 0 int bit = (num >> i) & 1; printf("%d", bit); } - printf("\n"); // Newline after printing the binary number + printf("\n"); // Newline after printing the binary number } - void cprint() { unsigned int line;