I’m doing something like this in SV but it gives me error.
`define s 8
int array[31:0];
int size =`s;
int queue[$];
task t();
for(int i=31;i>=0;i-=size )
queue.push_back(array[i-:size]); //This doesn't works
/* queue.push_back(array[i-:`s]); //This works // */
endtask
If the range of slicing MAX-MIN is fixed than i can do it but how to do if MAX-MIN is not fixed ?
How to implement above code without using defines because i want a variable size whose value is random (simulation time) but array is expecting compile time constant?
You are trying to push [i-:size] (or specifically [i-:`s]) ints into a queue of int. This might give incompatible assignment type.
Moreover, the slicing operator (+: or -:) expects the right-hand value (the one after ‘:’) to be constant. Since macros are compile time constants (text substitutes), the macro might work. Sitll the incompatible type assignment shall be showcased by simulator.
In reply to aditgupta100:
The with clause of the streaming operator can help here.
typedef int intQ_t[$];
for(int i=31;i>=size;i-=size )
queue = {queue, intQ_t'({>>{array with [i-:size]}})};
Note that the push_back() method can only push one element on the the queue at a time.
A bit-stream cast could do the assignment in one statement without a for loop
queue = intQ_t'(array);
Hi Dave thanks for replying.
Can you please elaborate a more , i’m not able to understand how this works ?
I want to push slices of array to the queue such that the size of queue is (32/size) ie queue.size() = 4 in my case.
You have to take up unsupported features with your vendor. This works fine in Questa.
It would help if you showed an example with the data you expect array and queue. Your latest description does not match what your original code was trying to do. Each push_back() was trying to push 8 elements onto the queue, and the for-loop iterated 4 times.