Fix a dual-port RAM scoreboard so that each read is checked on its own due edge, whatever the port does then.
Hardware context: Single-clock dual-port byte-enabled RAM. Match delayed read data for both ports without using DUT storage internals.
A RAM scoreboard reported extra responses from a correct RAM. Each one came on an edge where that port was idle. The scoreboard looked for due reads only when the port had a new request.
The class ram_scoreboard checks a dual-port RAM from outside. It sees only the requests of each edge and the responses after it. It keeps its own copy of memory and a queue of expected reads. Each entry holds a due edge, a port and the captured value.
The tests call sample() once per edge for 16 edges and record report() after each one. They use latencies from 1 to 3, set per port. They run the scoreboard on a correct RAM and on RAMs with planted faults.
Find the bug and fix it. The order of work inside sample() is in the specification.
Signals in the Timeline
| Signal | Width | Role |
|---|---|---|
active_lanes | 3 | input of each check |
memory_depth | 3 | input of each check |
latency_a | 2 | input of each check |
latency_b | 2 | input of each check |
fault_mode | 4 | input of each check |
image_seed | 32 | input of each check |
Full specification
class ram_scoreboard;
function new(input int depth, lanes, lat_a, lat_b, policy, priority_mode, input bit [31:0] seed);
function void sample(input int cycle, input ram_op item,
input bit av, input bit [31:0] ad, input bit bv, input bit [31:0] bd);
function string report();
endclass
| Step in sample() | What it does |
|---|---|
| Reset edge | Cancel every read in flight, even one due on this edge. A valid response on either port is a RESET error. Accept no request, and stop. |
| 1. Retire | Take every queued read whose due edge is this edge, for both ports. |
| 2. Compare | Check A, then B. Expected but no response is MISSING. A response with nothing expected is EXTRA. Both present with different data is DATA. |
| 3. Write | Apply the accepted writes of this edge to your own memory model, with the lane and priority rules. |
| 4. Queue | Queue each accepted read with due = cycle + its port latency and a value captured now: the OLD or NEW word. |
| Error kind | Value |
|---|---|
| MISSING | 1 |
| EXTRA | 2 |
| DATA | 4 |
| RESET | 8 |
K=<bad>:<first_cycle>:<first_port>:<first_kind>|E=<errors>|N=<accepted>,<retired>,<matched>,<canceled>,<pending>
| Report field | Meaning |
|---|---|
| bad | The OR of every error kind seen so far. |
| first_cycle, first_port, first_kind | The first error. On one edge, A comes before B. Before any error they are ff, ff and 00. |
| errors | The number of errors. Each port has at most one error per edge. |
| accepted | Reads queued so far. |
| retired | Reads that reached their due edge, right or wrong. |
| matched | Retired reads whose response came on time with equal data. |
| canceled | Reads removed by a reset. |
| pending | Reads still queued. accepted = retired + canceled + pending after every edge. |
Reset keeps memory and the error history. Only the reads in flight are cancelled.
| Faulty RAM | What is wrong |
|---|---|
| Swapped bytes | Write bytes 0 and 1 trade places, when both exist. |
| Wrong priority | B wins shared lanes in mode 0, and A in mode 1. |
| Wrong policy | OLD and NEW are swapped. |
| Stale data | The response data register never updates. |
| Late | Every response comes one edge late. |
| Dropped B | Reads on port B never respond. |
| Reset leak | Reset does not cancel the reads in flight. |
| Alias | Out-of-range addresses wrap into memory. |
Report only what you see. A fault that a trace cannot show must give a clean report.
| RAM rule | Meaning |
|---|---|
| Ports | Ports A and B each have en, wr, address, data and a 4-bit strobe. One rising edge samples both ports. |
| Requests | en = 0 is idle, and the other fields are ignored. en = 1 with wr = 0 is a read. en = 1 with wr = 1 is a write. |
| Strobes | Strobe bit k enables byte lane k. Lane 0 is bits 7:0. A write with no active strobe bit is legal and changes nothing. |
| Width | A word has 1, 2 or 4 active byte lanes: 8, 16 or 32 bits. Strobe bits and data bytes above the width are ignored. Read bits above the width are 0. |
| Addresses | Word addresses 0 to depth - 1 are valid; depth is 1, 3 or 5. An enabled request with a larger address is refused. The other port is not affected. |
| Latency | A read accepted on edge c shows valid = 1 and its data right after edge c + L, never sooner. Time counts on every edge, idle or not. |
| Read value | The value is captured on the accepting edge. OLD policy: the word before the edge. NEW policy: the word after both writes of that edge. |
| Two writes, one word | A lane written by one port takes its byte. A lane written by both takes A in mode 0 and B in mode 1. In mode 2, two writes that share an active lane are both refused. |
| Reset | A reset edge refuses both requests and cancels every read in flight. Stored data is kept. |
| Start | Word a starts as seed XOR (a × 0x01020408), cut to the width. A trusted pulse loads this before each test. |
The tests run 16 edges. After each edge they record the RAM trace row, as in the basic RAM problems. Your report() and a semicolon follow it. The result gives both trace lengths and whether the traces match exactly.
Examples
Example 1
Each Port Has Its Own Deadline- Input
32-bit RAM, depth 3, seed 0x11223344, latencies A = 1 and B = 3, OLD policy. Edge 0: A reads 0 and B reads 1. Edge 1: A writes 0xaabbccdd to 0. Edge 2: A reads 0. Edge 3: B reads 0.
- Output
trace_length = 1030, expected_length = 1030, trace_matches = yes
A gets 0x11223344 after edge 1. After edge 3, A gets 0xaabbccdd and B gets 0x1020374c. B's last read is due on edge 6, while B is idle. All four reads match, so the final report ends N=4,4,4,0,0.
Example 2
Reset Cancels Reads but Keeps Memory- Input
The same RAM, latencies A = 3 and B = 2. Edge 0: A writes 0xdeadbeef to 0. Edge 1: both read 0. Edge 2: reset. Edge 3: both read 0.
- Output
trace_length = 1030, expected_length = 1030, trace_matches = yes
Reset cancels both reads from edge 1, and the write stays. The later reads return 0xdeadbeef after edges 5 and 6. The final report is N=4,2,2,2,0 with no error.
Example 3
A Late RAM Is a Timing Error- Input
A RAM whose responses come one edge late; latencies A = 2 and B = 1. Edge 0: A reads 0 and B reads 1. Edge 2: A reads 2.
- Output
trace_length = 1030, expected_length = 1030, trace_matches = yes
B's response is due after edge 1, so edge 1 has a MISSING error on B: K=01:01:01:01. Each late response then counts as EXTRA, and each read due later is MISSING. The run ends with 6 errors.
Constraints and Contract
- Never read the memory or the pipeline of the RAM. Use only the arguments of sample().
- A late response is an error. Do not match it to a later deadline.
- Keep the class name, the method names and the argument types.
Hints
Hint 1
A deadline belongs to the read, not to the port's current request. Time moves on every edge.
Hint 2
Look at the first example. B's read from edge 3 is due on edge 6, when B is idle. Does the code retire it?
Hint 3
Look at the retire loop at the top of sample(). It also checks the port's enable. That check must go.
What the grader checks: Real clocked RAMs, correct and with planted faults, feed the scoreboard. An independent model checks every response and every report. The tests cover latencies 1 to 3 per port with resets that keep data. They do not cover x or z values or RAMs on two clocks.
122 checks on Verilator · server. Run the examples first, then check the full regression. Full checks use the server judge. Downloads contain public samples only. A passing result establishes the tested cases, not a proof for all possible inputs.
See all 7 steps and the final capstone