Hi, everyone!
i cannot randomize my object, if i use function in constrainsts:
class A;
rand int a;
rand int b;
function static int foo(int i);
$display("call foo() with a: %0d, b: %0d", a, b);
return i == 0;
endfunction
constraint b_c {
b inside {[0:5]};
};
constraint a_c {
a == foo(b);
a inside {[1:5]};
};
endclass
A a = new();
module tb;
initial begin
void'(a.randomize());
$display("Result: %p", a);
$finish();
end
endmodule
i receive following message:
call foo() with a: 0, b: 3
testbench.sv(25): randomize() failed due to conflicts between the following constraints:
testbench.sv(15): a_c { (a == this.foo(b)); }
testbench.sv(16): a_c { (a inside { [1:5] }); }
Where:
a = 0 /* random */
this.foo(b) = 0
looks like solver has made one run with a = 0, b=3 and then stopped
if i do not use function, like this
class A;
rand int a;
rand int b;
function static int foo(int i);
$display("call foo() with a: %0d, b: %0d", a, b);
return (i == 0);
endfunction
constraint b_c {
b inside {[0:5]};
};
constraint a_c {
if (b==0) a == 1;
else a == 0;
a inside {[1:5]};
};
endclass
A a = new();
module tb;
initial begin
void'(a.randomize());
$display("Result: %p", a);
$finish();
end
endmodule
solver works correctly:
Result: '{a:1, b:0}
** Note: $finish : testbench.sv(30)
can anyone explain, why function are not working with randomization?
I use Questa 2020.1