I got an project to convert 2-bit branch predictor in ‘SimpleScalar’ to 8-bit branch predictor. Which means I need to change the source code of 2-bit predicor from ‘SimpleScalar’ and make it work like a 8-bit predictor.
I know how predictors work but I do not know how to implement a branch predictor using c language. Recommend me some implementation of 8-bit brach predictor.
This set of slides does a good job of describing 2-bit branch prediction. Extending this to 8-bit (I assume) means that we are allowed a state machine of 256 states rather then 4 in the 2 bit case to decide what is going on. If we extend the 4 state case in the logical way, there will be 128 states where we predict the branch will be taken and 128 where it’s not taken…a kind of hysteresis.
I am supposing you are programming inside a processor emulator or simulator. You didn’t say. The C code only has to keep track of the last 128 decisions made and only switch to the alternate prediction if 128 guesses were wrong:
Without more information, this is the best I can do.