Hi Forun,
Requesting help to fix below constraint:
Constraint: if any bit of byte_enable(be) is set correspondingly a byte of data should be a non zero value.
Issue: why be is all ones ? I tried fixing with $countones but unsuccessful.
For ex:
Your problem is the distribution of solutions. Each enable bit has a 1-in-256 chance of being set to 0 because data has a 1-in-256 chance of being set to 8’b0.
If you add the constraint
solve byte_enable before data;
Then each bit of byte_enable has a 1-2 chance of being 0.
class prac;
rand bit [31:0] be;
randc bit [3:0] x;
int low, high;
constraint c1 {foreach(x[i])
{ if(x[i] == 1)
{
be[i*8 +:7] inside {[16:255]} ;}
else
be[i*8 +:7] == 0;
}}
endclass
module tb;
prac pr;
initial begin
pr = new();
repeat(5)
begin
pr.randomize();
$display("Value of x is %04b",pr.x);
$display("Value of be is %8h",pr.be);
end
end
endmodule
Only issue is when I am running the test sometimes I am getting 80 (when byte enable is 0). Like this
Value of x is 0101
Value of be is 00a700f4
Value of x is 0110
Value of be is 805a2b00
Value of x is 1011
Value of be is c8805bd4
Value of x is 1100
Value of be is f7658000
Value of x is 1111
Value of be is c1e3d2a8