DescriptionQ255
Q255DVASIC interview problem
Constrain exactly five changed bit positions
TechniquesDVSystemVerilogConstraintsHamming distanceXOR
DifficultyEasy
TopicConstrained Random
LanguageSystemVerilog
Requirements4 checkpoints
01
Problem
Two randomized bytes must differ in exactly five bit locations. Write the single constraint that expresses that Hamming-distance relation.
Class declarationSystemVerilog
class distance_pair;
rand bit [7:0] a;
rand bit [7:0] b;
endclassExample input and output
Use this case to check your interpretationInput
a=8'h00, b=8'h1FOutput
legal: $countones(a ^ b) = 5Explanation
a XOR b equals 8'b0001_1111, which contains exactly five set bits.
02
Requirements (4)
- Count differing positions rather than counting ones in each operand independently.
- Require exactly five differing bits.
- Allow every pair that satisfies the relation.
- Check whether randomize() succeeds.
