Consider an array.
pipe
I am trying to constraint it by using similar to following code.
pipe[i].sum with (item.index < j)
But I keep getting these failures
“This is not a valid built in method name for this object.”
How can I rewrite this. I did not want to do something like below which is hanging my solver. Something inbuilt is helpful
function int sumUntil(row, idx);
for(int i = 0; i < idx; i++) begin
sumUntil += int’(pipe[row][i]);
end
endfunction
You want to sum only some columns of your 2d array? Something like below? It was straight forward using a helper array, but I’d like to know if there is a single array solution.
module tb;
class twod;
rand bit [7:0] cells[5][5];
rand bit [7:0] trunc[5][5]; // helper array
constraint c {
// constrain the first two columns of cells to add up to 30
foreach ( cells[r,c] ) {
cells[r][c] inside { 5,10,15,20 };
if ( c < 2 )
trunc[r][c] == cells[r][c];
else
trunc[r][c] == 0;
}
foreach ( trunc[r,c] ) {
if ( c == 0 ) {
trunc[r].sum() == 30;
}
}
}
function void show();
$write("trunc\n");
foreach ( trunc[r,c] ) begin
$write( "%3d ", trunc[r][c] );
if ( c == 4 )
$write("\n");
end
$write("cells\n");
foreach ( cells[r,c] ) begin
$write( "%3d ", cells[r][c] );
if ( c == 4 )
$write("\n");
end
endfunction
endclass
initial begin
automatic twod td = new;
$display( "randomize == %0b\n", td.randomize() );
td.show();
end
endmodule
It might help to show some examples of array values you’re looking to see and explain in words, nut SystemVerilog syntax the requirements that the arrays need to meet.
Also, pipe[i].sum with (item.index < j) just returns j-1; a count of items whose index is less than j. You are probably looking for pipe[i].sum with ((item.index < j) ? item : 0 )
Sorry for being terse on my example.
Adding more details.
rand oper_e pipe[][]; //oper_e is an enum
Complete constraints that refuses to compile is. I corrected it.
constraint constraint_c3_c {
foreach(pipe[i,j]){
foreach(pipe[k,l]){
if(({i,j} != {k,l}) && (pipe[i][j] == pipe[k][l])) {
if(i+pipe[i].sum with ((item.index < j)*item)>= (k+pipe[k].sum with ((item.index < l)*item))) {
i+pipe[i].sum with ((item.index < j)*item)>= k+pipe[k].sum with ((item.index < l)*item);
}else {
i+pipe[i].sum with ((item.index < j)*item) +int'(pipe[i][j]) <= k+pipe[k].sum with ((item.index < l)*item);
}
}
} }
}
Error:
if(i+pipe[i].sum with ((item.index < j)*item)>= (k+pipe[k].sum with ((item.index < l)*item))) {
|
xmvlog: *E,QAANBI (fbPipe.sv,33|53): This is not a valid built in method name for this object. [SystemVerilog].
So changing my example, is the following supposed to work? I want it to behave the same as my other example above.
module tb;
class twod;
rand bit [7:0] cells[5][5];
constraint c {
// constrain the first two columns of cells to add up to 30
foreach ( cells[r,c] ) {
cells[r][c] inside { 5,10,15,20 };
cells[r].sum() with ( item.index < 2 ? item : 0 ) == 30;
}
}
function void show();
$write("cells\n");
foreach ( cells[r,c] ) begin
$write( "%3d ", cells[r][c] );
if ( c == 4 )
$write("\n");
end
endfunction
endclass
initial begin
automatic twod td = new;
$display( "randomize == %0b\n", td.randomize() );
td.show();
end
endmodule
Do you have a better work around to suggest than my previous example? I don’t like solution space partitioning that the function call approach creates.
I didn’t quite understand the 2nd line of constraint c ::
constraint c {
// constrain the first two columns of cells to add up to 30
foreach ( cells[r,c] ) {
cells[r][c] inside { 5,10,15,20 };
cells[r].sum() with ( item.index < 2 ? item : 0 ) == 30; // How does it work ?
}
}
If ternary condition is false , how is the 0 used ?