Bounded Queue Query

HI all,

I have the following code

 module Pushing_Val_Inside_FUll_Size_Bounded_Q;
int q[$:2];

initial
begin

  q.push_back(10); // Inserts at Index 0

  $display(" Q Contents are %p",q); // OP: Q Contents are '{10}

  q.push_back(100); // Inserts at Index 1

  $display(" Q Contents are %p",q); // OP : Q Contents are '{10,100}

  q.push_back(9);   // Inserts at Index 2

  $display(" Q Contents are %p",q); // OP : Q Contents are '{10,100,9}

  q.push_front(90); // Inserting at Index 0

  $display(" Q Contents are %p",q); // OP : Q Contents are '{10,100,9}  Expecting :  '{90,10,100}

end

endmodule

Since the Invalid Index would be 3 after push_front , Shouldn’t value 9 be Discarded ?

Thanks,

AGIS

Its a bounded queue of size 3, so we can’t push data more than 3
So the last push operation was not performed and showing some warning message

In reply to aashu singh:

Here is what LRM has to say : A bounded queue shall not have an element whose index is higher than the queue’s declared upper bound.
Operations on bounded queues shall behave exactly as if the queue were unbounded except that if, after any operation that writes to a bounded queue variable, that variable has any elements beyond its bound, then all such out-of-bounds elements shall be discarded and a warning shall be issued

According to it out of bound Index would be Discarded and after the pop_front Index 3 should be Discarded since its Higher than Declared Upper Bound.

The pop_front() operation should be similar to that performed on Unbounded Queue and then later on the Out-of_bound Element would be Discarded

In reply to Etrx91:

For your information:

Here is the warning if q[$:2] with Questa Sim.

** Warning: my_file.sv(39): Queue operation would exceed max. right index of 1.

You can also do this check to avoid it !
However you have to drop the last element to add a new element at the front.



        if (q.size() == 2)
          begin
            $display("Queue is FULL");
            lru = lru[0:$-1];  //  Delete last element
          end

        // Update with new value
       q.push_front(x);

In reply to Ep1c F4iL:

Hi,

The Queue Would be full on Inserting 3 Elements into it i.e q.size() == 3

Here is the Warning on Questa Sim Version 10.6b ::

Warning: Pushing_Val_Inside_FUll_Size_Bounded_Q.sv(32): Queue operation would exceed max. right index of 2.

The push_front() operation on Bounded Queue Variable ( q ) would be same as that performed on Unbounded Queue ( i.e '{90,10,100,9} ) . So now q has Index 3 which is out of Bound and Hence I was Expecting Index 3 with Value 9 to get Discarded

Regards,

AGIS

In reply to Etrx91:

The behavior defined in the LRM was a relatively recent clarification. 2 of 4 simulators I tested did not behave correctly for this case. Please contact your vendor.

In reply to dave_59:

Hi Dave ,

So my expected output should be the Actual Output right ?

Regards,

AGIS

In reply to Etrx91:
I think so.