HDL Lecture2
HDL Lecture2
Languages
System Verilog
Definition of System Verilog
Main features of System Verilog
System Verilog differences from other languages
System Verilog
Constrained Randomization
OOP support
Assertions
Narrow gap b/w design & verification engineer
Coverage support
New data types like logic
Easy C model integration
Bit data
String
Arrays
Dynamic arrays
Queue
Associative Arrays
New types
Struct
Union
Enumerated
Synopsys University Courseware
Copyright © 2014 Synopsys, Inc. All rights reserved.
Hardware Description Languages
Lecture - 2
Developed By: Vazgen Melikyan
8
Data Types: Bit Data
Operations
Contains a variable
standard Verilog operators
length array of ASCII
len()
characters. Each time substr()
a value is assigned to putc(), getc()
the string, the length toupper(), tolower()
of the array is compare(), icompare()
automatically atoi(), atohex(), atooct(), atobin(),
atoreal()
adjusted. itoa(), hextoa(), octtoa(), bintoa(),
realtoa()
int j = 1,
b[$] = {3,4},
q[$] = {0,2,5};
initial begin
q.insert(1, j);
q.insert(3, b);
q.delete(1);
q.push_front(6);
j = q.pop_back;
q.push_back(8);
j = q.pop_front;
foreach (q[i])
$display(q[i]);
end
Syntax Example
typedef struct typedef struct
{data_type var1,var2,var3;} {bit [7:0] r, g, b;}
struct_name; pixel_s;
Syntax Example
typedef union
typedef union
{data_type var1;} un_name; {int i; real f;} num_u;
Syntax Example
typedef enum
typedef
{name1, name2, …} enum _name; enum {RED, BLUE, GREEN} color;
Statements
Procedural statements
Continue and break statement
Example
Procedural
Initial
statements begin: example
The increment ++ and integer array[10], sum, j;
for (int i = 0; i<10; i++)
decrement – operators
array[i] = I;
are available in both sum = array[9];
pre and post form j = 8;
do
Label on a begin or
sum+= array[j];
fork statement can be while (j--);
put on thematching $display (“Sum=%4d”,sum);
end or join statement end:example
Example
Improvement
Begin..end are task mult_line;
optional, task/endtask, $display(“First line”);
function/endfunction $display(Second line”);
are enough to define endtask: mult_line
the routine boundaries
Routine arguments
Verilog
Declare arguments twice, once for direction and once for type
System Verilog
Declare arguments once
ref Example
Example
Routines storage
program automatic test;
Default task wait_f( input [31:0]
Static for module and addr, expext_data, output
program success );
while (bus.addr !== addr)
User defined
@(bus.addr);
Automatic for program,
success = (bus.data ==
with keyword automatic expect_data);
endtask
…..
endprogram
Class
Basic building block containing routines and variables. The analogue in Verilog is
a module.
Prototype
The header of the routine that shows the name, type, and argument list.
Method
The procedural code that manipulates variables, contained in tasks and functions.
Handle
A pointer to an object.
Object
An instance of a class. In Verilog a module must be instantiated to use it.
Property
A variable that holds data.
Synopsys University Courseware
Copyright © 2014 Synopsys, Inc. All rights reserved.
Hardware Description Languages
Lecture - 2
Developed By: Vazgen Melikyan
29
Classes
Data declarations
Tasks and functions for operating on the data
Verification routines and highly abstract system-level modeling.
Dynamic nature: ideal for testbench modeling. Not Synthesizable
Memory allocation, de-allocation and garbage collection are
automatically handled.
Dynamically created, deleted and assigned values. Objects can be
accessed via handles, which provide a safe form of pointers.
Classes can have inheritance and public or private protection, as in
C++.
function new();
command = 4’hA;
address = 40’hFE;
master_id = 5’b0;
endfunction
task clean () ;
command = 4’h0; address =
40’h0;
master_id = 5’b0;
endtask
endclass
class Bustran;
bit [31:0] addr, crc, data[8];
Statistics stats;
endclass
class Statistics;
time startT, stopT;
static int ntrans = 0;
static time total_elapsed_time;
endclass
Transactor Checker
Observes
Supplies data data
to the DUT from DUT
Driver Assertions Monitor
DUT
Example
Arbiter model using module arb_port (output logic [1:0]
ports grant,
input logic [1:0] request,
input logic reset,
input logic clk);
......
always @(posedge clk or posedge
reset) begin
if (reset)
grant <= 2'b00;
else
…
end
endmodule
Example
Top-level netlist Module top;
without an interface Logic [1:0] grant, request;
Logic clk =0,reset;
Always #5 clk=~clk;
arb_port a1
(grant,request,reset,clk);
Test t1(grant, request, reset, clk);
endmodule
Concurrent
The property must be true throughout a simulation
Procedural
Incorporated in procedural code
Apply only for a limited time
Immediate
At the time of statement execution
Strobed
Schedule the evaluation of the expression for the end
of current timescale to let the glitches settle down
Clocked
Triggered by an event or sampling clock
Severity level
$info
$warning
$fatal : terminates the simulation with an error code. The first
argument shall be consistent with the argument to $finish
$error
assert (myfunc(a,b)) count1 = count + 1; else -
>event1;
[ identifier : ] assert ( expression )
[ pass_statement ] [ else fail_statement ]
Synopsys University Courseware
Copyright © 2014 Synopsys, Inc. All rights reserved.
Hardware Description Languages
Lecture - 2
Developed By: Vazgen Melikyan
49
Strobed Assertions
Example
If immediate assertion is
triggered by a timing control always @(posedge clock)
that happens at the same time a = a + 1; // blocking
as a blocking assignment to assignment
the data being tested, there is always @(posedge clock)
a risk of the wrong value being begin
sampled. ...
Pass and Fail statements in assert (a < b);
strobed assertions must not cas:assert_strobe (a <
create more events at that time b);
slot or change values. end
$onehot
(<expression>) returns true if only one and only one bit of expression is high
$onehot0
(<expression>) returns true if at most one bit of expression is low
$inset
(<expression>, <expression> {, <expression> } ) returns true if the first expression
is equal to at least one of the subsequent expression arguments
$insetz
(<expression>,<expression> {, <expression> } ) returns true if the first expression
is equal to at least other expression argument
$isunknown
(<expression>) returns true if any bit of the expression is ‘x’
Example
A sequence of
sequence request_check;
conditions that spans
request ##[1:3]
multiple clock cycles grant ##1 !request
##1 !grant;
endsequense
Benefits of randomization
Random generation of stimulus
Random setting of parameters
Hard-to-reach corner cases can be reached
Constrained randomization
Improves the result
Speeds-up the bug finding process
More interesting cases can be achieved within the
constrained boundary