System Verilog Overview and Features
System Verilog Overview and Features
System Verilog
System Verilog is a language that was based on the description language of
Hardware Verilog 95 and for this reason it encompasses most of the design aspects of
system and the testbench that Verilog offers.
In addition, System Verilog aims to be both a HDL and HVL, that is, suitable for
coding (project) as well as verification.. This requires other functionalities that still
they were not available in Verilog or VHDL, but in E or Open Vera. System Verilog was
very influenced by Open Vera and for this reason resembles this HVL more.
2. Types
Enumeration
2.2. Arrays
System Verilog supports Arrays, as well as the known HDLs. There is the concept of
packed and unpacked array.
Dynamic arrays are also possible in System Verilog, logically for the
verification part.
Example of code:
int memory[];
memory=new[64];
memory = new[128](memory); // preserves the content of the array of 64
int size = size(memory); //returns the current size
[Link]; // deletes the dynamic array
We can index arrays using different types.
int vetor1[0];
int vetor2["hi"];
2.4. Rows
System Verilog also offers queues that increase and decrease in time.
for execution and accept commands to enqueue and dequeue.
You can place elements either at the beginning or at the end, and 0 indicates the first element, 1
the second and so on, while $ represents the last.
An important point is that semantics requires constant access time.
Examples of queues with limited or unlimited size:
int canal[$]; //list of integers
byte data[$] = { 2h'00, 2h'FF}; //byte list with initialization
int restricted_queue[$:16]; //queue with a maximum of 16 elements
Examples of operations that can be performed with queues and are already provided in System
Verilog:
int e, pos;
int canal2[$]; // another queue without limit
e=canal[0]; //gets the first (leftmost) element of the queue
canal2=canal; // copia uma fila completa
canal[0]=e; // writes in the first position of the queue
canal=canal[1:$]; // copies the list to itself without the first element, that is, deletes the first one
canal2={e, canal}; // builds a list with the element e concatenated with the channel list
canal={}; // esvazia a fila
canal = {canal{0:pos},e,canal{pos+1:$}}; // insert the element e at position pos
2.5. Interfaces
An interface groups and encapsulates a set of wires just like a struct does.
with variables. It facilitates access and use.
Interfaces are instantiated and save us from having to define signals that are output in
a module and input in another.
2.6. Structs
2.7. Casting
Similar to C
3. Scope
System Verilog also allows the declaration of global and local signals and variables.
4. Operators
Among the various types, there are operators that can be used:
& e ~& And not-e
| e ~| Either or neither
^ e ~^
== e !== Equality and inequality
e shifts
mixed_structure X,Y,Z;
bind + function mixed_structure fadds(mixed_structure, mixed_structure);
bind + function mixed_structure faddi(mixed_structure, integer);
5. Literals
Literals work similarly to Verilog.
reg [31:0] a, b;
reg [15:0] c,d;
...
a = 32'hf0ab;
c = 16'hFFFF;
a = '0; // fills an array packed with 0s
6. Describe hardware
Naturally, as an HDL, System Verilog must allow for the description of hardware.
This is done by defining hardware modules. Let's see an example:
module topo;
logic clk;
$finish(0);
end
endmodule
7. Describe Verification
In System Verilog, the DUT and the testbench code are separated. This is provided.
through language.
In System Verilog, all the automation that had to be done manually using the
normal verification languages can be automated within the language.
Example:
8. Classes
System Verilog offers classes, as it is an object-oriented language.
therefore it offers encapsulation, inheritance, and polymorphism.
8.1. Constructors
8.2. Scope
Just like Verilog, System Verilog allows observing all signals giving
the complete path within the hierarchy, which is not possible using VHDL.
9. Program Blocks
It is a way to encapsulate what is used in the testbench of your DUT. This
barrier naturally exists if we are using HDL and HVL, but in the case of System
Verilog could mix things up and so there is a need for this separation.
In addition, program blocks help with portability and reuse. It is a way
methodological approach to isolating the transactors.
10. Interfaces
Interfaces represent the ports that communicate the modules. In fact, they serve
as a way to define bundles of types and reuse them. Interfaces do not have direction and
this avoids defining a port on one side as output and on the other as input like
you know in VHDL.
Two empty classes that are there to be rewritten with things that need to be.
done before or after randomization.
Srand(seed) can initialize the seed of the randomization function.
[Link] of randomization
Verilog already contained the random function, which generates a random value within a
interval of values. System Verilog offers, in addition to random, cyclic random, which generates
deterministic data if the same seed is used.
Randcase: One can also randomize which type of function will be called:
Class lala;
task main();
pre_test();
start_test();
random case
5: main_test(); //25%
5: stress_tes(); //25%
1: error_teste(); //5%
9: normal_test(); //45%
end case;
stop_test();
end task;
12.3. Restrictions
Since we want random data, but there is data that does not interest us,
It is possible to restrict the random data that is generated.
class base;
rand int y;
rand int x;
constraint R {y > x;} //boolean expression
End class
One feature that System Verilog also offers is the ability to generate
interactive restrictions.
class C;
rand byte A[];
Inheritance
class BasePacket
int id;
byte Payload[];
task send(bit data[]);
end task
endclass
class ATMPacket extends BasePacket;
byte header[0:4];
function new; // redefine the function
[Link](); // calls the parent constructor
payload = new[48];
.....
end function;
task send(bit data[]); // overrides the parent method
....
endtask
endclass
System Verilog does not support multiple inheritance, but it is not extremely necessary.
for the purposes of verification. Super. is used to redefine the parent method.
It is also possible to completely rewrite a method:
class my_base;
virtual task method_a();
blabla
endtask
endclass
This example is nothing exceptional, just define the writing and reading on
dam. But note that we can now use this superior class to create a class
understood, for example, that writes incorrectly, to see how the system behaves
with errors. In general, the erroneous behavior is quite similar, having only a CRC error.
or a wrong bit or a different byte. So let's take a look at a type of extension that writes
but using the most significant bit corrupted by writing 0 in it.
[Link] Classes
Abstract classes are used as a template for new classes. They serve for reuse.
the idea is to partition the functionality into basic classes and derived classes which helps the
reuse, but note that this must be planned.
[Link]
Two different classes are defined, but they send data packets, each having
your differentiated shipping task.
package ListOfPackages[100]
ATM package pa = new; // creates an ATM package
packageToken pt = new; //creates a Token package
ListadPacotes[0]=pa;
ListadePacotes[1]=pt;
...
ListadePacotes[0].send; // knows that it should use the send from the ATM package
PackageList[1].send; //knows that it should use the send of packets of type Token.
[Link]
System Verilog offers the same type of package as VHDL. The declaration is made in
package file.
package ClassesBasicas;
virtual class Base;
int id;
virtual task status;
end task
end class
…
endpackage
Then it is used in the main program:
program BFM;
import BasicClasses::Base;
The constructions presented here serve for the second case, also called
of functional coverage.
Functional coverage is a metric that indicates how much of the spec has been verified.
used to relate to the verification environment the corner cases, the invariants of
specification and some other conditions.
Since this type of coverage has to be defined by the user, we need to
A way to specify in the language, and SystemVerilog offers this possibility.
Example
How many times has a been equal to 1? Once if we are doing a check
randomly it may happen that the data is not being used once we run it
few times our simulation.
Cross coverage: how many times a was equal to 1 and b was equal to 2.
Thus in System Verilog we can define a covergroup a group that must be
covered and points in this cover points.
[Link]
Bins are containers that can be created for values within a range.
true when we define a data type we know that the range is greater than the
values that will really happen, so I can define 'buckets' to put my values
using for the functional coverage the values that interest me the most
One can use .triggered to indicate the condition of an event being triggered.
[Link] lights
Imagine the situation of a BFM that can only read or write, that is, a
mutual exclusion situation. Thus, one can define the semaphore in_use in such a way that only
one of the processes will be triggered.
[Link]
Assertions
As asserções não serão tratadas aqui, pois farão parte de uma aula exclusiva para elas
together with PSL.
Considerations:
Architecture: The top is System Verilog or VHDL
How we connect the DUT in VHDL in a Testbench in System Verilog
I would have to use a tool that allows you to see (for example, SignalSpy from
mentor).