Hardware interview practice
Constrain exactly five changed bit positions
Two randomized bytes must differ in exactly five bit locations. Write the single constraint that expresses that Hamming-distance relation.
Starting point
Question code
class distance_pair;
rand bit [7:0] a;
rand bit [7:0] b;
endclassReviewed example
Work through one case
Input
a=8'h00, b=8'h1FExpected output
legal: $countones(a ^ b) = 5a XOR b equals 8'b0001_1111, which contains exactly five set bits.
What to cover
Requirements
- 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.
