Hi ,
I want to find indexes which are 1’b1 .
bit [3:0] b = 4'b1010 ;
// I want Output as 3 , 1
LRM 7.12.1 has Array Locator methods .
Here is my sample code using find_index ::
bit [3:0] b [1] = '{ 4'b1010 } ;
int ind[$] ;
initial begin
foreach(b[,j]
ind = b.find_index with ( b[item.index][j] == 1'b1 ? j : 0 ) ;
$display("High Indexes are %0p",ind);
end
The Queue is empty ( Since No index has a value of ‘j’ ) and No Indexes are Printed .
Needed assistance with the same
**Is it possible to skip the foreach and have some logic for the packed dimension ( j ) ??
**
In reply to Have_A_Doubt:
Hi,
It is always recommended to use the queue push_back() or push_front() method instead of assigning value directly to the queue.
In reply to srishis:
Actually , Array reduction methods return a queue .
Hence its necessary to use a Queue
In reply to Have_A_Doubt:
Please read the comments carefully. I have suggested you to use queue methods to assign a value.
// sample code
``` verilog
ind.push_back(value); // get value based on the requirements.
In reply to srishis:
Well the Original Question does say using Array Locator methods
( which returns a Queue by default )
Also your original comment ::
“It is always recommended to use the queue push_back() or push_front() method instead of assigning value directly to the queue”
Is Incorrect in my case . The LRM clearly states these methods return a Queue .
It even has examples with the same
In reply to Have_A_Doubt:
You are right. Apology for my comment. Let me run this and debug the issue.
In reply to Have_A_Doubt:
Array locator methods operate only on unpacked arrays. Hence, I am assuming any operation on packed dimensions will not work.
In reply to Have_A_Doubt:
module top;
bit qbit[$];
int found[$];
bit [3:0] b = 4'b1010;
initial begin
qbit = {<<{b}}; // convert packed bits to unpacked, reversing index order
found = qbit.find_index() with (item == '1);
$display("%p",found);
end
endmodule