Monday, February 27, 2017

What is exact difference between $cast as a task and function?

This terminology originally comes from Verilog where a function call always had a return value and could only be used as part of an expression, and a task call never had a return value and could only be used as a simple statement. Now System Verilog allows functions defined with no return value (a void return type), and allows functions with return values to be called as simple statements, and the return value is just thrown away.

So when we say $cast called as a function, we mean it is called as part of an expression

if ($cast(a_handle, b_handle)) something;

and when $cast is called as a task, it is just a simple statement.

$cast(a_handle, b_handle);

The only difference between the two is when the cast fails. Called as a task, it generates a run-time error, which would be consider a testing error.

When called as a function, it never generates an error, it just returns 1 for success and 0 for unsuccessful. You would use a $cast as a function when you have a class handle and want to know what the type of the class object is. Normally, you have a base class variable and want to try casting it to an extended class variable type.

Wednesday, February 22, 2017

Systemverilog Assertions Overview

Wednesday, February 8, 2017

Why system verilog does not allow always block in program block?

The program block came from the Vera verification language that was donated to SystemVerilog. In Vera, a program was a single procedure that represented the "test". Your test was started at time 0 and when the test terminated, the program terminated the simulation. If you needed multiple test threads, you either had to use the fork statement to start it, or use multiple programs. When the last program terminated, the simulation terminated.

As part of the integration with SystemVerilog, the program was turned into a module-like construct with ports and initial blocks are now used to start the test procedure. Because an always block never terminates, it was kept out of the program block so the concept of test termination would still be there.

Today, most people do not utilize this termination feature because the OVM/UVM have their own test termination mechanisms. The program block is no longer a necessary feature of the language other than to help people converting over from Vera to SystemVerilog.

Monday, January 30, 2017

Why we are using 2 state data type in system verilog?

2-state data types is used to improve simulator performance and reduce memory usage, compared with variables declared as 4-state types.

2-state data type :-
bit (FYI,by default unsigned),

4-state data type :-
time (FYI,by default unsigned),
logic (FYI,by default unsigned),
reg (FYI,by default unsigned).

What is logic and reg in System verilog?

SystemVerilog improves the classic reg data type so that it can be driven by continuous assignments, gates, and modules, in addition to being a variable. It is given the synonym logic so that it does not look like a register declaration. A logic signal can be used anywhere a net is used, except that a logic variable cannot be driven by multiple structural drivers, such as when you are modeling a bidirectional bus.

You can use the logic type to find netlist bugs as this type can only have a single driver. Rather than trying to choose between reg and wire, declare all your signals as logic, and you’ll get a compilation error if it has multiple drivers. Of course, any signal that you do want to have multiple drivers, such as a bidirectional bus, should be declared with a net type such as wire.

Wednesday, January 25, 2017

What is $test$plusargs and $value$plusargs? or Difference between $test$plusargs and $value$plusargs?

$test$plusargs (string)

This system function searches the list of plusargs for the provided string. The plusargs present on the command line are searched in the order provided. If one matches all characters in the provided string, a result of 1'b1 is returned. If no plusarg from the command line matches the string provided, the result of 1'b0 is returned.

Example :
module top;

initial begin
bit error_injection;
error_injection = 0;
if ($test$plusargs ("err"))
error_injection = 1;
$display ("Error Injection =%d", error_injection);


Simulation Command Line : +err

$value$plusargs (user_string, variable)

This system function searches the list of plusargs (like the $test$plusargs system function) for a user specified plusarg string. If the string is found, the remainder of the string is converted to the type specified in the user_string and the resulting value stored in the variable provided. If a string is found the function returns the value 1'b1. If no string is found matching, the function returns the value 1'b0 and the variable provided is not modified.

Example :
module top;

initial begin
if ($value$plusargs ("TESTNAME=%S", testname))
$display ("Running test %0s.", testname);


Simulation Command Line : +TESTNAME=this_test

Monday, January 23, 2017

What is p_sequencer ? OR Difference between m_sequencer and p_sequencer?

m_sequencer is the default handle for uvm_virtual_sequencer and p_sequencer is the hook up for child sequencer.

m_sequencer is the generic uvm_sequencer pointer. It will always exist for the uvm_sequence and is initialized when the sequence is started.

p_sequencer is a typed-specific sequencer pointer, created by registering the sequence to the sequencer using macros (`uvm_declare_p_sequencer) . Being type specific, you will be able to access anything added to the sequencer (i.e. pointers to other sequencers, etc.). p_sequencer will not exist if we have not registered the sequence with the `uvm_declare_p_sequencer macros.

The drawback of p_sequencer is that once the p_sequencer is defined, one cannot run the sequence on any other sequencer type.