S2.11.2 Predict the Loop

EasyImplement12 minIcarus Verilog · serverReview the topic

One loop branch, four ways to guess it. Step the 1-bit entry and the 2-bit counter by hand, and count the right guesses.

Hardware context: Test code that replays the branches which the real core ap_rv32 executed for three programs, and asks four predictors before each one: not taken, backward taken, a 1-bit entry and a 2-bit counter for each branch. Estimating the accuracy of a direction predictor from a branch trace before any hardware is built

A loop has four rounds. The branch at its end, at address 18 in hex, goes back to address 08. So in one run of the loop it is taken three times and then not taken once. The loop runs three times, one run right after the other: twelve outcomes in all.

This worksheet uses named constants. The first three entries show how to record your decisions.

Signals in the Timeline

SignalWidthRole
question8input of each check
Full specification

The 1-bit entry starts at "not taken". The 2-bit counter starts at 1. It guesses taken at 2 and 3, and it stops at 0 and at 3.

Write the twelve outcomes in a row, T for taken and N for not taken. Under each, write the guess of each predictor, and the count after the outcome.

Enter every value in decimal. For a guess, enter 1 for taken and 0 for not taken.

EntryYour decision
NOT_TAKEN_RIGHTHow many of the twelve does "always not taken" guess right?
BACKWARD_TAKEN_RIGHTHow many does "backward taken" guess right?
COUNT_AFTER_1What is the 2-bit count after the first outcome?
COUNT_AFTER_3What is the 2-bit count after the third outcome?
COUNT_AFTER_4What is the 2-bit count after the fourth outcome?
TWO_BIT_GUESS_5What does the 2-bit counter guess for the fifth outcome?
ONE_BIT_GUESS_5What does the 1-bit entry guess for the fifth outcome?
ONE_BIT_RIGHTHow many of the twelve does the 1-bit entry guess right?
TWO_BIT_RIGHTHow many of the twelve does the 2-bit counter guess right?
ONE_BIT_WRONG_FOR_EACH_RUNOnce warmed up, how many wrong guesses does the 1-bit entry make for each run of the loop?
TWO_BIT_WRONG_FOR_EACH_RUNOnce warmed up, how many wrong guesses does the 2-bit counter make for each run of the loop?
TWO_BIT_RIGHT_FOR_KThe loop runs K times in place of three. Give the number of right guesses of the 2-bit counter, as an expression in K.

Examples

Example 1

NOT TAKEN RIGHT
Input
How many of the twelve does "always not taken" guess right?
Output
matches = 1

It is right only at the three exits of the loop.

Example 2

BACKWARD TAKEN RIGHT
Input
How many does "backward taken" guess right?
Output
matches = 1

The branch goes back, so the guess is always taken. It is wrong only at the three exits.

Example 3

COUNT AFTER 1
Input
What is the 2-bit count after the first outcome?
Output
matches = 1

It starts at 1, and the first outcome is taken.

Constraints and Contract

  • Keep the parameter and named constants. Use the numeric codes and units on this page.
  • For TWO_BIT_RIGHT_FOR_K, enter a constant expression using K. Only this entry changes with the parameter. The supported integer range is 3 through 20, inclusive.

Hints

Hint 1

Twelve letters: T T T N, three times.

Hint 2

For each outcome, first write the guess from what the predictor holds. Then update it with the outcome.

Hint 3

A guess is right when it equals the outcome under it.

What the grader checks: Each check compares the full eight-bit answer. Parameter trials change one condition and keep the other decisions fixed.

12 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

Report a problem with this page

Your code SystemVerilogSaved locally
Ln 1, Col 1Tab indents · Ctrl/⌘ + Enter runs samples
Not run yet

NOT TAKEN RIGHT

Input
How many of the twelve does "always not taken" guess right?
Expected output
matches = 1

It is right only at the three exits of the loop.

Run samples executes all 3 public checks. Check all tests runs 12 checks on the server.

Icarus Verilog · server