← ProblemsCS450
Two-bit saturating counter
36%cpu-archcountersBranch predictors commonly track each branch with a two-bit saturating counter, so a single anomalous outcome doesn't immediately flip the prediction. The counter has four states:
state | meaning |
|---|---|
2'b00 | strongly not-taken |
2'b01 | weakly not-taken |
2'b10 | weakly taken |
2'b11 | strongly taken |
Build one such counter. On each rising clock edge, when train_valid = 1 the counter is trained with one branch outcome:
train_taken = 1: increment the counter, saturating at 3 (incrementing2'b11leaves it at2'b11).train_taken = 0: decrement the counter, saturating at 0 (decrementing2'b00leaves it at2'b00).
When train_valid = 0, the counter holds its value.
areset is an asynchronous active-high reset that sets the counter to 2'b01 (weakly not-taken). The output state is the current counter value.