Skip to content

Three techniques, one class, all of them have to actually work together

tool-limitation / write-from-scratch / requires-patched-verilator / array / multi-constraint / statistical

This one needs a Verilator fix that's still under review upstream (verilator#8100): without it the compiler crashes on unique{} over a row of a 2D array. Run is off until it merges.

REQUIRES A PATCHED VERILATOR: see README.md first. unique{} on a foreach-indexed row of a 2D array crashes the compiler on every released Verilator as of this writing, the same bug thermal_power_fuzzer avoids with pairwise inequality. This exercise uses it at full scale:

make run EX=dma_ring_allocator VERILATOR=/path/to/patched/verilator_bin

A DMA scheduler’s allocation grid: 4 channels of 4 ring-buffer slots, each holding an 8-bit block pointer. Each requirement is ordinary; making them all hold in one randomize() is the hard part.

  • Rows and columns must both be distinct. grid[i] is already an array, so unique {grid[i]} covers a row. There’s no grid[:][j] column slice, so a column’s elements have to be listed explicitly inside something that iterates the column index. IEEE 1800-2023 18.5.4 explains why a whole row and one cell inside a foreach over it differ.
  • Which bound applies depends on qos_mode, so solve ... before has to settle qos_mode ahead of dma_grid.
  • The BURST_MODE sum is over row 1 union column 3. They share dma_grid[1][3]; count it once. Counting it twice makes the >1000 bound easier to meet than intended.

Fix the class below.

RequirementsOn every randomize() call

  1. Every dma_grid[ch][slot] is in [1:255].
  2. Each row’s 4 values are distinct, and each column’s 4 values are distinct, using unique{} for both, not pairwise inequality.
  3. qos_mode is BURST_MODE 70% of the time, SPARSE_MODE 30%.
  4. In SPARSE_MODE, every cell is in [1:20].
  5. In BURST_MODE, the 7 distinct cells of row 1 union column 3 sum to more than 1000.

Source on GitHub

dma_ring_allocator.sv