R9.4.2 A Descriptor Table

MediumImplementVerilator + Yosys · serverReview the topic

Keep four records in an array of packed structs. Build a write that updates only the fields its mask names, a valid bit, and a total length.

Hardware context: An RV32I immediate decoder that reads one word through a packed union of B, U and J views; and a table of four descriptor records. Design the descriptor table with a masked write, a valid bit and a total length.

A DMA block keeps a table of four buffer descriptors. Each one has a permission field, a length and a valid bit. Software updates one field at a time, so a write carries a mask. The old table was four separate vectors, and a masked write once cleared the wrong field.

This is an Implement problem: write desc_tab around an array of desc_t records. The package and the ports are given. The tests first fill the table, then reset it, then apply five steps and read rdata and total_len after every edge.

Brief: rising-edge clk; rst_n asynchronous and active-low, after which every entry is invalid and all fields are 0. At an edge, inv = 1 marks entry waddr invalid and leaves its fields. Otherwise we = 1 marks entry waddr valid and copies the fields that wmask names from wdata. The valid bit of wdata is not used. Reads are combinational. Synthesis check: the design must build on the site's synthesis flow with no latch. The cell and level counts come from an open-source flow and are a proxy for area and depth, not a foundry result.

Signals in the Timeline

SignalWidthRole
script80input of each check
Full specification
The package and the ports (keep them)
// desc_pkg: one descriptor. Keep the type and member names.
package desc_pkg;
  typedef struct packed {
    logic       valid;
    logic [1:0] perm;
    logic [4:0] len;
  } desc_t;                        // 8 bits: valid is bit 7
endpackage

module desc_tab
  import desc_pkg::*;
(
  input  logic       clk,
  input  logic       rst_n,        // asynchronous, active-low
  input  logic       we,           // 1: write entry waddr
  input  logic       inv,          // 1: mark entry waddr invalid; wins over we
  input  logic [1:0] waddr,
  input  logic [1:0] wmask,        // bit 1: update perm, bit 0: update len
  input  desc_t      wdata,
  input  logic [1:0] raddr,
  output desc_t      rdata,
  output logic [6:0] total_len
);
  // your design
endmodule
At a rising edge out of resetEntry waddr
inv = 1 (we may be 0 or 1)valid becomes 0; perm and len keep their values
inv = 0, we = 1valid becomes 1. perm is copied if wmask[1] is 1. len is copied if wmask[0] is 1. A field that is not copied keeps its value.
inv = 0, we = 0no change
OutputValue (combinational)
rdataentry raddr if it is valid; all zeros if it is not
total_lenthe sum of len over the valid entries, 0 to 124

Each test runs a previous life (four writes that fill the table), holds rst_n low across one edge, then applies 5 steps. The result holds rdata and total_len after each step's edge. rdata is shown as valid, perm and len.

Examples

Example 1

After Reset Every Entry Is Invalid
Input
idle, read 0; idle, read 1; idle, read 2; idle, read 3; idle, read 0
Output
valid_step0 = no, perm_step0 = 0, len_step0 = 0, total_step0 = 0, valid_step1 = no, perm_step1 = 0, len_step1 = 0, total_step1 = 0, valid_step2 = no, perm_step2 = 0, len_step2 = 0, total_step2 = 0, valid_step3 = no, perm_step3 = 0, len_step3 = 0, total_step3 = 0, valid_step4 = no, perm_step4 = 0, len_step4 = 0, total_step4 = 0

The previous life filled all four entries. The reset must clear them, so every read gives zeros and the total is 0.

Example 2

Write Both Fields, Then One Field
Input
write 1 mask=11 perm=2 len=9, read 1; write 1 mask=01 perm=3 len=20, read 1; write 1 mask=10 perm=1 len=31, read 1; write 2 mask=11 perm=3 len=4, read 1; idle, read 2
Output
valid_step0 = yes, perm_step0 = 2, len_step0 = 9, total_step0 = 9, valid_step1 = yes, perm_step1 = 2, len_step1 = 20, total_step1 = 20, valid_step2 = yes, perm_step2 = 1, len_step2 = 20, total_step2 = 20, valid_step3 = yes, perm_step3 = 1, len_step3 = 20, total_step3 = 24, valid_step4 = yes, perm_step4 = 3, len_step4 = 4, total_step4 = 24

The second write has mask 01: len becomes 20 and perm stays 2. The third has mask 10: perm becomes 1 and len stays 20.

Example 3

Invalidate, Then Write Again
Input
write 0 mask=11 perm=1 len=12, read 0; write 3 mask=11 perm=2 len=7, read 0; inv 0, read 0; write 0 mask=10 perm=3 len=30, read 0; idle, read 3
Output
valid_step0 = yes, perm_step0 = 1, len_step0 = 12, total_step0 = 12, valid_step1 = yes, perm_step1 = 1, len_step1 = 12, total_step1 = 19, valid_step2 = no, perm_step2 = 0, len_step2 = 0, total_step2 = 7, valid_step3 = yes, perm_step3 = 3, len_step3 = 12, total_step3 = 19, valid_step4 = yes, perm_step4 = 2, len_step4 = 7, total_step4 = 19

After inv, entry 0 reads as zeros and leaves the total. The masked write that follows makes it valid again with its old len of 12.

Constraints and Contract

  • Inputs are known 0/1 values and change while clk is low.
  • Keep the package, the type and member names and the module ports.

Hints

Hint 1

An assignment pattern with default resets every member of every entry in one line.

Hint 2

Write to one member of one entry: the array index comes first, then the member name. A member you do not assign keeps its value.

Hint 3

total_len needs a loop over the four entries with a constant bound, and a result wide enough for four lengths of 31.

What the grader checks: Seven directed and thirteen seeded scripts of five steps each run after a previous life and a reset. rdata and total_len after every edge are compared with an independent model. Passing shows the table follows the brief on these scripts; the synthesis check adds the latch count.

The submitted design must synthesize with 0 latches and no combinational loop. Counts come from the pinned open-source synthesis flow. They are proxies for logic size and depth, not physical area or timing.

20 checks on Verilator + Yosys · 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 2 steps and the final capstone

Report a problem with this page

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

After Reset Every Entry Is Invalid

Input
idle, read 0; idle, read 1; idle, read 2; idle, read 3; idle, read 0
Expected output
valid_step0 = no, perm_step0 = 0, len_step0 = 0, total_step0 = 0, valid_step1 = no, perm_step1 = 0, len_step1 = 0, total_step1 = 0, valid_step2 = no, perm_step2 = 0, len_step2 = 0, total_step2 = 0, valid_step3 = no, perm_step3 = 0, len_step3 = 0, total_step3 = 0, valid_step4 = no, perm_step4 = 0, len_step4 = 0, total_step4 = 0

The previous life filled all four entries. The reset must clear them, so every read gives zeros and the total is 0.

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

Verilator + Yosys · server