You get 2048 bits of memory and three kinds of branch behaviour. Design a direction predictor that stays under a limit of wrong guesses on all three.
Hardware context: Test code that replays the branches which the real core ap_rv32 executed, with a plain 2-bit table, gshare and a local-history predictor side by side. Choosing the kind and the length of branch history from recorded traces
A plain counter table is good at branches with a steady habit. A predictor with history is good at patterns and at branches that follow other branches. Neither is good at everything.
Build a predictor that is. The bench owns its memory: one register of 2048 bits. Your module is only logic. From the memory and an address it gives a guess. From the memory, the address and the outcome it gives the memory of the next moment.
How you divide the 2048 bits is your design. The starter is a plain table that uses a quarter of them.
Signals in the Timeline
| Signal | Width | Role |
|---|---|---|
trial | 10 | input of each check |
mispredictions | 16 | input of each check |
limit | 16 | input of each check |
Full specification
| Step | What happens |
|---|---|
| 1 | The bench puts the address of the branch on pc, and what the branch does on taken. |
| 2 | It reads predict_taken. A guess that differs from taken counts as one wrong guess. |
| 3 | It stores next_state into the memory. That value is state for the next branch. |
| Kind | What the branches do | Wrong guesses allowed |
|---|---|---|
| Steady branches | 48 branches at different addresses. Each always goes the same way. They come in a scrambled order. Between them comes, now and then, one branch that is a coin flip. | 285 |
| Patterns | A loop with six branches. Each is taken, except once in every few rounds. The six have different periods, from 2 to 6 rounds. | 340 |
| A branch that follows another | Groups of three branches: a coin flip, a branch that is always taken, and a branch that does what the coin flip did. There are four such groups at different addresses. | 385 |
How to read a result: within_limit is 1 when a run stayed at or under its limit. The waveform of a public case shows the count of wrong guesses beside the limit.
Examples
Example 1
Steady Branches- Input
1500 branches: many branches that each always go the same way, met in a scrambled order, with a coin flip now and then. At most 285 wrong guesses are allowed.
- Output
within_limit = 1
The reference design makes 242 wrong guesses here. About one branch in four is the coin flip, and half of those are lost whatever you build. A plain table is good enough for this run. A predictor with history alone is not.
Example 2
Patterns- Input
1500 branches: a loop of six branches, each of which is not taken once in every few rounds. At most 340 wrong guesses are allowed.
- Output
within_limit = 1
The reference design makes 252 wrong guesses here. A plain table makes more than 400: it is wrong whenever a branch leaves its habit, and again right after.
Example 3
A Branch That Follows Another- Input
1500 branches: a coin flip, a branch that is always taken, and then a branch that repeats the coin flip. At most 385 wrong guesses are allowed.
- Output
within_limit = 1
The reference design makes 338 wrong guesses here. A third of the branches are coin flips. The branch that repeats the coin flip is a coin flip too, for any predictor that looks only at its address.
Constraints and Contract
- predict_taken must depend on state and pc only. It is read while taken already holds the outcome, and it must not look at it.
- Your module must have no memory of its own. Clocks, latches and initial blocks are refused. At the end of a run the bench repeats three earlier questions with the memory of that moment. Both outputs must be the same as before.
- Every address is a multiple of 4 and below 1000 in hex.
- The private runs use other seeds, and for the patterns other addresses and periods. A design made to fit only the public runs will fail them.
Hints
Hint 1
Run the starter and read the three counts in the waveform. Which kinds of run does a plain table lose?
Hint 2
Add a second predictor that sees the outcomes of the last branches. Give it its own part of the memory, and its own history bits.
Hint 3
Now you have two guesses. Give each address a small counter that learns which of the two to trust.
Hint 4
If one run is still over its limit, change the sizes: the number of history bits matters more than the number of counters.
What the grader checks: Three public runs and five private runs of 1500 branches each: steady branches with a coin flip between (three seeds), patterns (two sets of addresses and periods), and a branch that follows a coin flip (three seeds). The count of wrong guesses of each run is compared with the limit of its kind. Three earlier questions are repeated at the end of each run, to find a module with memory of its own. The limits were set with the reference and with fourteen weaker designs, each of which is over a limit in at least one run.
8 checks on Icarus Verilog · server. Run the examples first, then check the full regression. Full checks use the server judge. Downloads contain your source only; samples require the simulation service. A passing result establishes the tested cases, not a proof for all possible inputs.
See all 2 problems on this path