Hi,
Whenever I need an “exists()” function for a queue, I use one of the “locator” functions.
I save the return value into a declared queue of the correct type, and then I check if that queue size is larger than 0.
int tmp_q[$];
tmp_q = my_queue.find_first(iterator) with (iterator == 9);
if (tmp_q.size() > 0) begin
...
I’m wondering if there’s a way to shrink the number of lines of code.
I tried stuff like
if ((my_queue.find_first(iterator) with (iterator == 3)).size() > 0) begin
but I don’t think “size” can be tacked on like that.
Is there a way to do this?
Thanks
In reply to nimrodw:
This is a new feature added to 1800-2023. Some tools already handle some basic forms of this, but I haven’t seen the with expression so far.
A couple of ways you could handle this in existing code.
You could wrap your queue in a class and provide the exists() method as a callable function. If you are using the UVM, just extend uvm_queue and add the exists method.
Create a queue size function
function int queue_size(int q[$]);
return q.size;
endfunction
Then you could write
if ( queue_size(my_queue.find_first(iterator) with (iterator == 3)) > 0 ) begin
This is less efficient than the class method if your queue sizes are large.
I have been using things like my_enum.name().tolower() regularly so I knew it existed, but I did not know it wasn’t officially supported.
Will the 2023 SV support method chaining with the “with” expression?
I’m indeed using UVM, and I was not not aware of the existence of uvm_queue. I have never seen it used.
Is it recommended to use it instead of queues like
int q[$];
?
Unfortunately, I can’t control how someone else defines their queue, but it will help me with queues that I define myself.
If using uvm_queues or extending them is recommended, then that’s what I’ll start doing.
Thanks
In reply to nimrodw:
Yes, the enhancement supports method chaining with the “with” expression. It has this example
qi = IA.find(x) with (x > 5).unique; // Call to unique follows with clause