Skip to question and answer

Hardware interview practice

SystemVerilog solve before Constraint Semantics

HardConstraintsMultiple choice

How does solve a before b change this randomization?

Question code
rand bit a;
rand bit [1:0] b;
constraint c {
  (a == 0) -> (b == 0);
  solve a before b;
}

Answer choices

  1. A. It changes the legal solutions and forces a to 0
  2. B. It leaves the legal solutions unchanged but makes P(a=0) one half rather than one fifth
  3. C. It makes P(a=0) one fifth rather than one half
  4. D. It is illegal because implication and solve before cannot appear together

Concise answer

The answer and the key reason

The ordering leaves the five legal `(a,b)` pairs unchanged, but it raises `P(a=0)` from `1/5` to `1/2`. `solve a before b` chooses between the two legal values of `a` first, then selects a compatible value for `b`.

Deeper explanation

Work through the implementation and tradeoffs

The implication permits only `b=0` when `a=0`; when `a=1`, all four two-bit values of `b` are allowed. That creates one tuple whose first field is zero and four whose first field is one. Under the prompt’s equal-tuple model and without ordering, the lone zero tuple receives one fifth of the probability.

With `a` solved first, its legal values zero and one are selected at that stage with equal probability. The later conditional choice for `b` has one option after zero and four options after one, but it does not retroactively bias `a`. The directive changes sampling distribution, not satisfiability or the set of permitted tuples.

What to remember

  • Five legal tuples remain
  • Ordering changes marginal probability
  • `solve before` is not a filter

Practice the complete prompt

Explain it first, then compare the reviewed solution.

Open this exact question in the practice bank to attempt it, check your reasoning, and access the full member solution.Practice this question

Keep practicing

ConstraintsSystemVerilog Basic Constraint Interview QuestionConstraintsSystemVerilog Soft Constraints ExplainedConstraintsSystemVerilog dist Constraints Explained