-
Notifications
You must be signed in to change notification settings - Fork 5
/
InstructionCache.cpp
67 lines (59 loc) · 2.05 KB
/
InstructionCache.cpp
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
#include "basetypes.h"
#include "InstructionCache.h"
InstructionCache::InstructionCache(const uint32 desiredEntries) : numEntries(!desiredEntries ? DEFAULT_NUM_CACHE_ENTRIES : desiredEntries)
{
validBitmap = new uint32[(numEntries/32) + 1];
// init_array((uint8*)validBitmap, ((numEntries / 32) + 1)*sizeof(uint32)); // not needed as Invalidate is called below
cacheEntries = new InstructionCacheEntry[numEntries];
//!! init_array((uint8*)cacheEntries, numEntries*sizeof(InstructionCacheEntry));
Invalidate();
}
InstructionCache::~InstructionCache()
{
if(cacheEntries)
{
delete [] cacheEntries;
}
if(validBitmap)
{
delete [] validBitmap;
}
}
void InstructionCache::Invalidate()
{
memset(validBitmap, 0, (numEntries/32 + 1)*sizeof(uint32));
}
void InstructionCache::InvalidateRegion(const uint32 start, const uint32 end)
{
uint32 mask = 0x80000000UL;
uint32 validBitmapIndex = 0;
for(uint32 i = 0; i < numEntries; i++)
{
const uint32 tag = cacheEntries[i].pcexec;
if((tag >= start) && (tag <= end))
{
validBitmap[validBitmapIndex] &= ~mask;
}
if(mask == 0x01)
{
validBitmapIndex++;
mask = 0x80000000UL;
}
else
{
mask >>= 1;
}
}
}
void InstructionCacheEntry::CopyInstructionData(const uint32 toSlot, const InstructionCacheEntry &src, const uint32 fromSlot)
{
nuances[FIXED_FIELD(toSlot,0)] = src.nuances[FIXED_FIELD(fromSlot,0)];
nuances[FIXED_FIELD(toSlot,1)] = src.nuances[FIXED_FIELD(fromSlot,1)];
nuances[FIXED_FIELD(toSlot,2)] = src.nuances[FIXED_FIELD(fromSlot,2)];
nuances[FIXED_FIELD(toSlot,3)] = src.nuances[FIXED_FIELD(fromSlot,3)];
nuances[FIXED_FIELD(toSlot,4)] = src.nuances[FIXED_FIELD(fromSlot,4)];
scalarInputDependencies[toSlot] = src.scalarInputDependencies[fromSlot];
miscInputDependencies[toSlot] = src.miscInputDependencies[fromSlot];
scalarOutputDependencies[toSlot] = src.scalarOutputDependencies[fromSlot];
miscOutputDependencies[toSlot] = src.miscOutputDependencies[fromSlot];
}