I'm working on a 1-bit bimodal branch prediction simulator for a class project. I was thinking of using an unordered_map for the table but I need to be able to set the size, so I was thinking using a vector of pairs and table.reserve(tableSize) may be a good way to do this.
However, this leaves me with only linear search of the vector to find table entries which is horribly slow. Does anyone know a way that I can implement a hash function for this application?
For those of you that do not know how a branch predictor table works, the key is the PC address 0x12345678 and the value is T or NT (branch taken or non-taken). I also need a method of collision resolution. If a branch is taken, the bit (bool) is set to true, which will be the prediction for the next branch. If the next branch is NOT taken, the bit is set to false or 0. The purpose of the simulator is to measure correct predictions vs total branches to get the accuracy and compare it to other methods' accuracies. So, the ultimate goal is to use the 2 least significant bytes of the PC (by masking them out) to define the position in the hash table to store the prediction value 0 or 1.
Any help would be greatly appreciated.
On a side note: The maximum table size will be 1024 entries so the time complexity won't have a chance to really scale that high, but any optimization is worth it since I'll be entering this into a competition.
EDIT:
Decided to go with an unordered_map.
This is the solution I've got so far:
Header File
// bimodal 1-bit
class BM1Pred{
private:
std::ofstream &outputFile;
//hash table with bool value mapped to addresses
// 0 - NOT TAKEN, 1- TAKEN
unordered_map<long long, bool> table;
int tableSize;
public:
// constructor
BM1Pred(std::ofstream& file, int size)
: outputFile(file), tableSize(size) {}
// deconstructor
~BM1Pred()
{}
// member functions
void parseResults(std::string filename);
};