System Verilog Questions and Answer part4

Companies Related Questions, System Verilog 0 Comments

What is difference between queue and mailbox?

A mailbox is a built-in class around a queue that uses semaphores to control access to the ends of a queue. A mailbox only has FIFO element ordering whereas you can access the head, tail, or middle elements of a queue. you typically use a mailbox when there are multiple threads reading and writing data and you need the atomic test-and-set operation of semaphore to know when the mailbox is full or empty. In the UVM, we use a TLM FIFO which is another wrapper around a mailbox. A queue is just a data structure, and a mailbox is an higher level concept that is built around a combination of queues and semaphores. If you have only one process reading and writing to the data structure, there is no need to use a mailbox. However if there are more than one thread, a mailbox is a convenient class to use. But if you have multiple threads, and need access to any position in the queue, you will need to write your own class to do that. The mailbox concept is in many other programming languages, so you should be able to search for more information about it

How to check if any bit of the expression is X or Z?

(^bus === 1’bX)

Bit-wise xor the bus then check if the result is X. If any bit is X or Z then the result will be X.

To know which bit in the bus has the error:

always @* begin

for(integer i=0; i<$size(bus); i++) begin

if(bus[i]===1’bX) $display(“bus[%0d] is X”,bus[i]);

if(bus[i]===1’bZ) $display(“bus[%0d] is Z”,bus[i]);

end

end

Leave a Reply