In reply to prashant.kaushik:
Hi,
Thanks for your help, but it still doesn’t work for me.
The total_size function always returns 0 and the solver fails.
The “solve sgl before payload_desc;” doesn’t appear to have any effect.
If I hack the total_size function to return, say 3. Then the solver passes as expected.
module top;
typedef byte sgl_t[][][16];
// Class
class myclass;
rand byte sgl[][][16];
rand byte unsigned payload[];
rand int unsigned payload_desc[];
// Array creation
constraint c_sgl_size { sgl.size == 5;
payload.size == 15;
foreach(sgl[i,,]) {
sgl[i].size == 2;
}
}
function int total_size(sgl_t x);
foreach (x[i,]) begin
total_size += x[i].size();
end
return total_size;
//return 3;
endfunction
constraint C_PAYLOAD_DISTRIBUTION {
solve sgl before payload_desc;
payload_desc.size == total_size(sgl);
payload_desc.sum with (longint'(item)) == payload.size;
}
function void post_randomize();
$display("payload_desc size = %d ", payload_desc.size());
$display("sgl size = %d ", sgl.size());
foreach(sgl[i,]) begin
$display("sgl[%1d].size= %d ", i, sgl[i].size);
end
foreach(payload_desc[i]) begin
$display("payload_desc[%1d]= %d ", i, payload_desc[i]);
end
endfunction: post_randomize
endclass // myclass
initial
begin
myclass c;
c= new();
if(!c.randomize()) begin
$display("Randomize fail ");
end
else begin
$display("Randomize Pass");
end
end
endmodule // top;