|
|
|
@ -46,7 +46,7 @@ void print_usage(void);
@@ -46,7 +46,7 @@ void print_usage(void);
|
|
|
|
|
void bad_usage_error(void); |
|
|
|
|
long parse_int_arg(char *arg, char opt); |
|
|
|
|
long bits_to_size(int bits); |
|
|
|
|
linked_line** make_cache(long set_indices, long num_lines); |
|
|
|
|
linked_line** make_cache(long num_sets, long num_lines); |
|
|
|
|
linked_line* make_set(linked_line* newer, long num_lines); |
|
|
|
|
void free_cache(linked_line** cache, long num_sets); |
|
|
|
|
void free_set(linked_line* line); |
|
|
|
@ -65,7 +65,7 @@ int main(int argc, char* argv[])
@@ -65,7 +65,7 @@ int main(int argc, char* argv[])
|
|
|
|
|
results score; |
|
|
|
|
char buffer[20]; |
|
|
|
|
int set_index_bits = 0, block_bits = 0; // Not-useful input variables.
|
|
|
|
|
long set_indices = 0, num_lines = 0, block_size = 0; //Useful variables
|
|
|
|
|
long num_sets = 0, num_lines = 0, block_size = 0; //Useful variables
|
|
|
|
|
char *filename = NULL; |
|
|
|
|
int opt = 0; |
|
|
|
|
|
|
|
|
@ -81,7 +81,7 @@ int main(int argc, char* argv[])
@@ -81,7 +81,7 @@ int main(int argc, char* argv[])
|
|
|
|
|
break; |
|
|
|
|
case 's': // 2^s = number of sets
|
|
|
|
|
set_index_bits = (uint8_t)parse_int_arg(optarg, 's'); |
|
|
|
|
set_indices = bits_to_size(set_index_bits); |
|
|
|
|
num_sets = bits_to_size(set_index_bits); |
|
|
|
|
break; |
|
|
|
|
case 'E': // associativity - lines per set
|
|
|
|
|
num_lines = parse_int_arg(optarg, 'E'); |
|
|
|
@ -101,13 +101,13 @@ int main(int argc, char* argv[])
@@ -101,13 +101,13 @@ int main(int argc, char* argv[])
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
/* If any required arguments were not provided. (argflags != 0b1111) */ |
|
|
|
|
if (!set_indices || !num_lines || !block_size || !filename) { |
|
|
|
|
if (!num_sets || !num_lines || !block_size || !filename) { |
|
|
|
|
bad_usage_error(); |
|
|
|
|
} |
|
|
|
|
/* End of argument parsing. */ |
|
|
|
|
//probably broken: printf("Arguments: s=%hhu, E=%u, b=%hhu, t=%s, v=%hhu, 2^s=%d, 2^b=%u\n", set_index_bits, num_lines, block_bits, filename, VERBOSE, set_indices, block_size);
|
|
|
|
|
//probably broken: printf("Arguments: s=%hhu, E=%u, b=%hhu, t=%s, v=%hhu, 2^s=%d, 2^b=%u\n", set_index_bits, num_lines, block_bits, filename, VERBOSE, num_sets, block_size);
|
|
|
|
|
|
|
|
|
|
linked_line** cache = make_cache(set_indices, num_lines); |
|
|
|
|
linked_line** cache = make_cache(num_sets, num_lines); |
|
|
|
|
|
|
|
|
|
/* FILE READING */ |
|
|
|
|
FILE* f = fopen(filename, "r"); |
|
|
|
@ -131,8 +131,8 @@ int main(int argc, char* argv[])
@@ -131,8 +131,8 @@ int main(int argc, char* argv[])
|
|
|
|
|
return -1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if(VERBOSE) |
|
|
|
|
print_cache(cache, set_indices); |
|
|
|
|
/* if(VERBOSE) */ |
|
|
|
|
/* print_cache(cache, num_sets); */ |
|
|
|
|
|
|
|
|
|
char r = cache_access(cache, address, set_index_bits, block_bits, num_lines); |
|
|
|
|
mprintf(" %c %lx,%lx %c\n", op, address, size, r); |
|
|
|
@ -159,11 +159,11 @@ void increment_result_counters(char result, results* score)
@@ -159,11 +159,11 @@ void increment_result_counters(char result, results* score)
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
linked_line** make_cache(long set_indices, long num_lines) |
|
|
|
|
linked_line** make_cache(long num_sets, long num_lines) |
|
|
|
|
{ |
|
|
|
|
linked_line** cache = (linked_line**)calloc(set_indices, sizeof(linked_line*)); |
|
|
|
|
linked_line** cache = (linked_line**)calloc(num_sets, sizeof(linked_line*)); |
|
|
|
|
long ii; |
|
|
|
|
for (ii = 0; ii < set_indices; ii++) { |
|
|
|
|
for (ii = 0; ii < num_sets; ii++) { |
|
|
|
|
cache[ii] = make_set(NULL, num_lines); |
|
|
|
|
} |
|
|
|
|
return cache; |
|
|
|
|