why i_val and j_val value is not updated after one loop, please help me in this.
`define MAX_ROWS_COLS 5
class data_aray;
rand int arr_d[][];
rand bit[7:0] i_val, j_val,diag_val;
function new();
diag_val=0;
endfunction
constraint md_array {
arr_d.size == `MAX_ROWS_COLS;
diag_val> 10; diag_val<50;
foreach(arr_d[i]) {
arr_d[i].size== `MAX_ROWS_COLS;
}
foreach(arr_d[i,j]) {
if((i==i_val) && (j==j_val)){
arr_d[i][j]==diag_val;
//start_addr_dis(i,j);
i_val == start_addr_i(i_val);//const'(i_val) +1;
j_val == start_addr_j(j_val);//const'(j_val) -1;
//start_addr_dis(i_val,j_val);
}
}
}
function bit[3:0] start_addr_dis (const ref bit[7:0] i_val, j_val);
$display("Hello i=%0d\t j=%0d\n", i_val, j_val);
endfunction
function bit[7:0] start_addr_i(bit[7:0] i_val);
i_val++;
$display("Hello_i_val=%0d",i_val);
return i_val;
endfunction
function bit[7:0] start_addr_j(bit[7:0] j_val);
j_val--;
$display("Hello_j_val=%0d",j_val);
return j_val;
endfunction
endclass
module diagonal_array;
initial
begin
data_aray pkt = new();
pkt.randomize();
$display("\narray : %0p",pkt.arr_d);
end
endmodule
In reply to Subbi Reddy:
Your example has a lot of unused code( macros, variable and functions). Removing that would make it much easier for people to read.
The variables i_val and j_val are not declared rand, so randomize will not change their values. The constraint
i_val == const’(i_val) +1; will always fail.
You call the function
start_addr_dis in a constraint that always returns the value 4’b0. That will always fail.
Your last foreach loop has an implication that is only true for one element: arr_d[0][0].
It would help to show the results you are expecting if you want someone to correct your code.
In reply to dave_59:
In reply to Subbi Reddy:
Your example has a lot of unused code( macros, variable and functions). Removing that would make it much easier for people to read.
Ans: The unwanted code was removed to the best of my ability
The variables i_val and j_val are not declared rand, so randomize will not change their values. The constraint
i_val == const’(i_val) +1; will always fail.
Ans: Even though given rand getting same result and also i tried to increment the _val through const’(val) and function start_addr*() but the result is failed
You call the function
start_addr_dis in a constraint that always returns the value 4’b0. That will always fail.
Ans: start_addr_dis() is used only to find what values present in *_val;
Your last foreach loop has an implication that is only true for one element: arr_d[0][0].
It would help to show the results you are expecting if you want someone to correct your code.
i want to get the matrix like below
Ex: The primary result and above code trying to print diagonal matrix for any square matrix(rows and columns should be equal size).
0 0 0 0 0 6
0 0 0 0 6 0
0 0 0 6 0 0
0 0 6 0 0 0
0 6 0 0 0 0
6 0 0 0 0 0
The whole output expecting is like below (in each row before diagonal value should increment and after diagonal value should decrement), please observe example matrix below for understanding purpose.
Note: diagonal value, remaining values and rows, columns should be dynamic values.
1 2 3 4 5 6
2 3 4 5 6 4
1 3 4 6 3 2
3 5 6 5 3 1
1 6 5 4 3 2
6 5 4 3 2 1
Ex:
3rd row Before 6 value should be increment(1 3 4) and after 6 value should be decrement(3 2)
I answered for your comments, please check it.
please provide good solution for this.
In reply to Subbi Reddy:
Thanks for editing your original example. There still is some confusion as your code seems to try incrementing/decrementing by 1, but you but your expected result is just relatively increasing or decreasing.
You are trying to use i_val and j_val as if the constraint were procedural code, but there can only be one value picked for i_val and j_val in any solution. I think below is what you are looking for
`define MAX_ROWS_COLS 5
class data_aray;
rand int unsigned arr_d[][];
rand bit[7:0] diag_val;
constraint md_array {
arr_d.size == `MAX_ROWS_COLS;
diag_val> 10; diag_val<50;
foreach(arr_d[i]) arr_d[i].size== `MAX_ROWS_COLS;
foreach(arr_d[i,j])
if ( j == `MAX_ROWS_COLS - i - 1)
arr_d[i][j]==diag_val;
else if (j < `MAX_ROWS_COLS - i - 1)
arr_d[i][j] < arr_d[i][j+1]; // if you meant -- arr_d[i][j]-1 == arr_d[i][j+1];
else
arr_d[i][j] < arr_d[i][j-1]; // if you meant ++ arr_d[i][j]+1 == arr_d[i][j+1];
}
endclass
module diagonal_array;
data_aray pkt = new();
initial repeat(5) begin
assert(pkt.randomize());
$display("array:");
foreach (pkt.arr_d[i]) $display("%0p",pkt.arr_d[i]);
end
endmodule