VLSI DV Interview Puzzles · All levels

constraint_mode Changes Pass/Fail

Call #1 disables c_secure. Call #2 enables it back. Which call passes?

Puzzle

Difficulty: Hard · Puzzle 4 of 6 · Topic: randomize() with Puzzles

Call #1 disables c_secure. Call #2 enables it back. Which call passes?

Code

systemverilog
class sec_req;
  rand bit secure;
  rand bit [3:0] addr;
  constraint c_addr   { addr inside {[0:15]}; }
  constraint c_secure { secure -> addr[3] == 1'b1; }
endclass

sec_req s = new();
s.c_secure.constraint_mode(0);
assert(s.randomize() with { secure == 1; addr inside {[0:3]}; }); // Call #1

s.c_secure.constraint_mode(1);
assert(s.randomize() with { secure == 1; addr inside {[0:3]}; }); // Call #2

Hint

With secure==1 and c_secure enabled, addr[3] must be 1.

Step-by-step solution

diagram
1) Call #1: c_secure disabled, so secure==1 with addr 0..3 is legal -> pass.
2) Call #2: c_secure enabled, secure==1 implies addr[3]==1 -> addr must be 8..15.
3) Inline addr 0..3 conflicts with required 8..15, so intersection is empty -> fail.

Answer

Answer: Call #1 passes and Call #2 fails; enabling c_secure makes the inline addr range illegal for secure==1.

Why candidates get it wrong

Candidates forget disabled constraints are completely removed from the solve set.

Interviewer follow-up

What inline change makes Call #2 pass while keeping secure==1?

Related topics