-
Notifications
You must be signed in to change notification settings - Fork 0
/
AddressTrace.c
74 lines (60 loc) · 2.4 KB
/
AddressTrace.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*
============================================================================
Name : AddressTrace.c
Author : Jesse Bannon
Class : TCSS 372 - Computer Architecture
School : University of Washington Tacoma
Copyright : Use only for educational purposes and do not modify file.
Description : Contains all enums address structs used throughout the program
and conversions functions from unsigned integers to cache and
trace addresses.
============================================================================
*/
#include <stdio.h>
#include <stdlib.h>
unsigned int getTag(unsigned int address, const int indexSize, const int offsetSize) {
return (address >> (indexSize + offsetSize) & ~1);
}
unsigned int getIndex(unsigned int address, const int indexSize, const int offsetSize) {
unsigned int tempAddress = address >> offsetSize;
switch(indexSize) {
case 0: return 0;
case 1: return (tempAddress & 0x1);
case 2: return (tempAddress & 0x3);
case 3: return (tempAddress & 0x7);
case 4: return (tempAddress & 0xF);
case 5: return (tempAddress & 0x1F);
case 6: return (tempAddress & 0x3F);
case 7: return (tempAddress & 0x7F);
case 8: return (tempAddress & 0xFF);
case 9: return (tempAddress & 0x1FF);
case 10: return (tempAddress & 0x3FF);
case 11: return (tempAddress & 0x7FF);
case 12: return (tempAddress & 0xFFF);
case 13: return (tempAddress & 0x1FFF);
case 14: return (tempAddress & 0x3FFF);
case 15: return (tempAddress & 0x7FFF);
case 16: return (tempAddress & 0xFFFF);
case 17: return (tempAddress & 0x1FFFF);
case 18: return (tempAddress & 0x3FFFF);
case 19: return (tempAddress & 0x7FFFF);
case 20: return (tempAddress & 0xFFFFF);
default: printf("*** ERROR: Index should not be greater than 20 (Index size = %d). Returning 0.\n", indexSize);
return 0;
}
}
unsigned int getOffset(unsigned int address, const int offsetSize) {
switch(offsetSize) {
case 0: return 0;
case 1: return (address & 0x1);
case 2: return (address & 0x3);
case 3: return (address & 0x7);
case 4: return (address & 0xF);
case 5: return (address & 0x1F);
case 6: return (address & 0x3F);
case 7: return (address & 0x7F);
case 8: return (address & 0xFF);
default: printf("*** Offset should not be greater than 8. Returning 0.\n");
return 0;
}
}