Skip to the selected question
ASIC.FYI

ASIC Question Bank

1,000+ hardware interview questions
DescriptionQ406
Page ↗
Q406DVIntelASIC interview problem

Constrain a bounded packet split

TechniquesDVSystemVerilogUVMConstrainsplit
DifficultyMedium
TopicSystemVerilog & UVM
LanguageSystemVerilog
Requirements4 checkpoints
01

Problem

A transfer is divided into a fixed number of random packet lengths while leaving enough bytes for every remaining packet. Write a SystemVerilog constraint class for the packet lengths.

Class declarationSystemVerilog
class packet_split;
rand int unsigned len[8];
int unsigned total, count, min_len, max_len;
constraint legal_c;
endclass

Example input and output

Use this case to check your interpretation
Input
total=12, count=3, min_len=4, and max_len=4.
Output
The only legal randomized array is {4,4,4,0,0,0,0,0}.
Explanation

Three active entries must each equal four and sum to twelve, while every inactive entry is constrained to zero.

02

Requirements (4)

  • randomize() is legal only when 1<=count<=8, max_len<=65535, min_len<=max_len, total<=65535, and count*min_len<=total<=count*max_len.
  • For every active i<count, require min_len<=len[i]<=max_len and the sum of active lengths to equal total.
  • Set every inactive len[i] for i>=count to zero.
  • Add ordering or solve-before constraints only if needed for solver clarity; do not use post_randomize to repair an illegal result.