DescriptionQ648
Q648DVASIC interview problem
Constrain a nonzero 32-bit power of two
TechniquesDVSystemVerilogConstraintsPower of twoBit manipulation
DifficultyEasy
TopicConstrained Random
LanguageSystemVerilog
Requirements4 checkpoints
01
Problem
Write a solver-friendly SystemVerilog constraint for a 32-bit randomized field that contains exactly one set bit and therefore represents a nonzero power of two.
Class declarationSystemVerilog
class one_hot_value;
rand bit [31:0] value;
endclassExample input and output
Use this case to check your interpretationInput
value=32'h0001_0000Output
legal: $countones(value) = 1Explanation
Exactly bit 16 is set, so $countones(value) equals one.
02
Requirements (4)
- Allow every value from 32'h0000_0001 through 32'h8000_0000 that has one set bit.
- Reject zero.
- Reject values with two or more set bits.
- Express the condition as an integral constraint without post_randomize repair.
