In reply to Tapas:
I rewrote your function, but I still got the same results of No solutions exist
Like you, I fail to understand why.
I tried other approaches, but my algorithms are wrong.
Perhaps this will help you into a different solution.
Also, perhaps someone else can explain why the failure.
class A;
rand bit [7:0]mask;
rand bit [7:0]b;
function void display();
$display("Mask is %8b::b=%8b",mask,b);
endfunction
//mask_validation function is to be used in the constraint block.
//This fucntion returns "1" if input mask value is having continuous 1s.
//Otherwise returns zero.
//example: 1111,1110,1100,1000,0111,0110,0100,0011,0010,0001,0000 should return "1".
//Other values will return "0".
//Explanation: Here it will keep on checking the each bit, If "1" is appeared,
//then it will set the a_one_occurred = 1. After a one if zero will be hit,
//then it sets zero_after_one = 1. If after this again a one come then it will return "0".
//As mask value is non continuous. (e.g. 1010.1001,1101 etc)
function bit mask_validation(bit [7:0]mask);
bit a_one_occurred = 0;
bit zero_after_one = 0;
bit fail=0;
foreach(mask[i]) begin // Mask is 01110010::b=00011010
case({a_one_occurred, zero_after_one})
2'b00: if(mask[i]) a_one_occurred=1'b1;
//2'b01: if(mask[i]) a_one_occurred=1'b1;
2'b10: if(mask[i]==1'b0) zero_after_one=1'b1;
2'b11: if(mask[i]) fail=1'b1; // mask[i]==1'b0; // must be 0
endcase
end
return fail;
endfunction
constraint nonzero_b{b != 8'b00000000;}
constraint nonzero_mask{mask!=8'b00000000;}
constraint valid_maskF{mask_validation(mask) == 0;}
/* constraint valid_mask{{mask[7:4]!=4'b1001}; //2 zeros and 1
{mask[6:3]!=4'b1001};
{mask[5:2]!=4'b1001};
{mask[4:1]!=4'b1001};
{mask[3:0]!=4'b1001};
{mask[7:3]!=5'b10001}; //3 zeros and 1
{mask[6:2]!=5'b10001};
{mask[5:1]!=5'b10001};
{mask[4:0]!=5'b10001};
{mask[7:1]!=6'b100001}; //4 zeros and 1
{mask[6:0]!=6'b100001}; } */
/*constraint new_mask{ {mask[7]==1 -> mask[6:4]!= 3'b001 &&
mask[5:3]!= 3'b001 &&
mask[4:2]!= 3'b001 &&
mask[3:1]!= 3'b001 &&
mask[2:0]!= 3'b001};
{mask[6]==1 -> mask[5:3]!= 3'b001 &&
mask[4:2]!= 3'b001 &&
mask[3:1]!= 3'b001 &&
mask[2:0]!= 3'b001};
{mask[5]==1 -> mask[4:2]!= 3'b001 &&
mask[3:1]!= 3'b001 &&
mask[2:0]!= 3'b001};
{mask[4]==1 -> mask[3:1]!= 3'b001 &&
mask[2:0]!= 3'b001}; }*/
endclass
module test;
A a;
initial begin
a=new();
repeat (10) begin
void'(a.randomize());
a.display();
end
end
endmodule