
Minimal Branch Predictor
By:
errant on
Apr 17th, 2012 | syntax:
C++ | size: 0.91 KB | hits: 54 | expires: Never
class local_update : public branch_update
{
public:
unsigned int counter;
};
class local_predictor : public branch_predictor
{
public:
local_update u;
branch_info binfo;
local_predictor (void)
{
}
branch_update *predict (branch_info & b)
{
binfo = b;
if (b.br_flags & BR_CONDITIONAL)
{
u.direction_prediction ((u.counter) >> 1);
}
else u.direction_prediction(true);
u.target_prediction (0);
return &u;
}
void update (branch_update *u, bool taken, unsigned int target)
{
unsigned int *c = &((local_update*)u)->counter;
if (binfo.br_flags & BR_CONDITIONAL)
{
if (taken)
{
if (*c < 3)
(*c)++;
}
else
{
if (*c > 0)
(*c)--;
}
}
}
};