S3.4.2 Pseudo-LRU for Four Ways

HardImplement45 minIcarus Verilog · serverReview the topic

Keep three bits for each set of a four-way cache, turn them away from every way that is used, and follow them to the way that must go.

Hardware context: Eight cache lines arranged as sets and ways, as a counting model, and the compare-and-select logic of 1, 2, 4 and 8 ways through synthesis. Choosing the number of ways of a cache

A cache has four sets of four ways. When a block must come in and its set is full, one way must give up its block. Write the block that picks that way with a tree of three bits for each set.

The cache around it tells you about every access: which set, whether it was a hit, and in which way. It also shows you the valid bits of the ways of that set. You answer with the victim: the way to replace.

Signals in the Timeline

SignalWidthRole
trial10input of each check
Full specification
The three bits of one set (a choice of this problem: other designs number them differently)
BitAt 0 it points atAt 1 it points at
topthe left pair: ways 0 and 1the right pair: ways 2 and 3
leftway 0way 1
rightway 2way 3

The tree names one way: follow the top bit to a pair, and then the bit of that pair to a way.

When a way is used, the bits on its path are turned to point away from it. The top bit points at the other pair. The bit of its own pair points at the other way of that pair. The bit of the other pair does not change.

How to read a result: the bench notes the victim in some cycles. The field "victims" starts with the digit f. After it comes one hexadecimal digit for each victim that was noted, in order. The field "looks" counts them.

Examples

Example 1

Five Misses in a Full Set
Input
Every way of every set is valid. a miss in set 0, then a miss in set 0, then a miss in set 0, then a miss in set 0, then a miss in set 0
Output
looks = 5, victims = 0xf02130, signature = 0x9ffffe

With all bits at 0 the tree points at way 0. Each miss uses the victim and turns the bits away from it: the victims are 0, 2, 1, 3, and then 0 again.

Example 2

Empty Ways First
Input
The cache is empty. a miss in set 1, then a miss in set 1, then a miss in set 1, then a miss in set 1, then a miss in set 1
Output
looks = 5, victims = 0xf01230, signature = 0x300000

An empty way comes first, the lowest one: 0, 1, 2, 3. Those four uses also move the tree. The fifth miss finds the set full and follows the tree to way 0.

Example 3

Hits Turn the Tree
Input
Every way of every set is valid. a hit in way 0 of set 2, then no access, with set 2 on the input, then a hit in way 2 of set 2, then no access, with set 2 on the input, then a hit in way 1 of set 2, then no access, with set 2 on the input, then no access, with set 3 on the input
Output
looks = 4, victims = 0xf2130, signature = 0xd40000

A hit in way 0 turns the tree to way 2. A hit in way 2 turns it to way 1. A hit in way 1 turns the top bit to the right pair, where the right bit still points at way 3. Set 3 was never used and still points at way 0.

Constraints and Contract

  • victim follows set, valid_ways and the stored bits with no clock edge in between. It must be right in every cycle, with or without an access.
  • If any way of the set is not valid, victim is the lowest way that is not valid. Otherwise victim is the way that the tree names.
  • At a rising edge with access at 1, one way of the set counts as used. On a hit it is hit_way. On a miss it is the victim of that cycle, because the new block goes there.
  • With access at 0, nothing changes, and hit and hit_way hold junk. The bits of the other sets never change.
  • At a rising edge with rst_n at 0, every bit of every set becomes 0. The bench also does this in the middle of a run.

Hints

Hint 1

Write the path of each way first: which value of the top bit, and which value of its pair bit, lead to it?

Hint 2

A use writes two of the three bits. Work out both from the number of the way.

Hint 3

A miss is a use too. Ask which way it uses, with a full set and with an empty way.

What the grader checks: Each way used alone, every pair of uses and six orders of four; misses in a row; sets that must not disturb each other; empty ways in every position, with the tree pointing elsewhere; cycles with no access and junk on the inputs; a reset in the middle; random sequences of up to 24 cycles. Each check compares the victims that were noted and a signature over the victim of every cycle.

100 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

Five Misses in a Full Set

Input
Every way of every set is valid. a miss in set 0, then a miss in set 0, then a miss in set 0, then a miss in set 0, then a miss in set 0
Expected output
looks = 5, victims = 0xf02130, signature = 0x9ffffe

With all bits at 0 the tree points at way 0. Each miss uses the victim and turns the bits away from it: the victims are 0, 2, 1, 3, and then 0 again.

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

Icarus Verilog · server