I am trying following Code ::
int x[] = '{13,41,89,31,2,67,2} ;
int x2[$] = '{13,41,89,31,2,67,2} ;
bit [159:0] pack ;
bit [223:0] pack1 ;
string s = {"A","B","a","b","0","1"} ;
bit [47:0] b ;
int assoc[string] ;
bit [255:0] bassoc ;
// For Application
int min ;
int q[$];
int y[$];
initial begin
min = int'(x.min()) ; // [A] min() returns a Single Element i.e 32-bits . Hence int'() Cast Works !!
$display("%0d",min);
//pack = int'(x) ; // Illegal :: "Fatal: Bit stream casting is only allowed on same size data." i.e we see run-time Error since we have Dynamic Error !!
//pack = 160'(x) ; // Illegal :: "Fatal: Bit stream casting is only allowed on same size data." i.e we see run-time Error since we have Dynamic Error !!
pack1 = 224'(x) ; // [B] Works since Same Size !!
for ( int i = 223 ; i >=0 ; i = i - 32 )
$display("%0d",pack1[i-:32]);
pack1 = 224'(x2); // Works since Same Size !!
for ( int i = 223 ; i >=0 ; i = i - 32 )
$display("%0d",pack1[i-:32]);
$display("===============STRING=================");
b = 48'(s); // Works since Same Size !!
for ( int i = 47 ; i >= 0 ; i -= 8 )
$display("%0s i.e %0d",b[i-:8],b[i-:8]);
$display("===============ASSOC=================");
foreach(s[i]) // Would Iterate 8-times !!
begin
assoc[s[i]] = $urandom ; // [E] :: Throws Compilation error !!
// assoc[$sformatf("%0s",i)] = $urandom ; // [F] :: Can it be a substitute for [A] ??
end
bassoc = 256'(assoc); // [I] Would it work ??
for ( int i = 255 ; i >= 0 ; i -= 32 )
$display("bassoc[%0s] is %0d",bassoc[i-:32],bassoc[i-:32]);
end
LRM 6.24.3 ::
When a dynamic array, queue, or string type is converted to the packed representation, the item at index 0 occupies the MSBs.
When an associative array is converted to the packed representation, items are packed in index-sorted order with the first indexed
element occupying the MSBs
The Code works fine upto String Data types .
[1] Question regarding [E] and [F] ::
For associative array however I see error at [E] , not sure why >
Also I tried using [F] as a substitute for [E] , but even that doesn’t work .
[2] Is the bit-stream cast Statement [I] a correct statement ? Since associative array would have 8-indexes and 32x8 equals 256 , it should work right ?