- Debug Daily
- Posts
- (Solution) Another Constraint Challenge
(Solution) Another Constraint Challenge
Good day, dedicated engineers & debuggers!
Yesterday, we shared our second Question of the Day with you. Similar to our first Question of the Day, it was based on constraints.
And just like that first question, the best answer we found was written by dave_59 on verification academy! (you might recognize by now that dave_59 is a great resource to learn from on Verification Academy).
See if you can figure out how the below clever code works. The use of the pattern variable and rotate logic are particularly ingenious. All credits to dave_59.
P.S. be on the lookout for our next question! We will switch gears away from constraints completely (for a bit) and touch on another important aspect of verification!
module test;
class gen;
bit [31:0] pattern = 32'hFFFF_FC00;
rand bit [31:0] value;
rand bit [4:0] rotate;
constraint c { value == (pattern << rotate | pattern >> 32-rotate); } // circular rotate
endclass
gen h =new;
initial repeat (10) begin
assert(h.randomize());
$display("%2d %b", h.rotate, h.value);
end
endmodule
Reply