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 ?
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
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
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.