Systemverilog Q&A: Normal Inline Assertion Example
Systemverilog Q&A: Normal Inline Assertion Example
If you use static task for multiple places in your testbench, the local variables will
share the common, static storage. In this case, different threads will step on each other's
values.
By using atuotmic storage, it will make a copy of local variables and use them. Not a
common static storage any more.
Packed array is an array without gap. Unpacked array is good for local individual
variable access.
In this case, all 32 bits word are packed with 4 bytes. A packed array is handy if you
need to convert to and from scalars.
Logic and wire are almost the same except wire can be driven by multiple sources.
Logic can only driven by single source.
assertStateStartShortFalse:
assert property (@(posedge clk) disable iff(!reset_n)
(state==`START) |-> (short==FALSE))
else $display("Error state START and short is true ");
property p_check_par;
@(posedge clk) (^(data^parity)) == 1’b0;
endproperty
a_check_par: assert property(p_check_par);
endmodule
ovl_even_parity
Answer: Systemverilog Assertions (SVA) are temporal, Declarative and formal friendly.
Temporal : Design Variables relationship in time
Declarative: Orthogonal to procedural form in design (describe what instead of
how )
Synthesizable: Good for dynamic and formal verification.
SVA provides interoperability with RTL, testbench features and functional
coverage.
2. What are the benefits of using assertions?
Answer: There are 3 ways to connect assertion to RTL: inline, Instantiation and Virtual
Instantiation (bind).
Inline Assertion: Assertion directly put into the RTL by designer. Use compile
option for synthesis.
For example:
// A synchronous D Flip-Flop
moduledff (input logic [7:0] D, input RST_, input CLK, output logic [7:0] Q);
always @(posedge CLK)
if (!RST_) Q<= 8'h0;
else Q <= D;
// assertions
propertyd_q_property_0 (clk, rst_, q);
@(posedge clk) !rst_ |->##1(q == 8'h0);
endproperty
assert_d_q_property_0 : assert property(d_q_property_0(CLK, RST_, Q));
endmodule
Assertion Instantiation: Put assertion into another module and use it again by RTL
designers.
For example:
moduledff (input logic [7:0] D, input RST_, input CLK, output logic [7:0] Q);
always @(posedge CLK)
if (!RST_) Q<= 8'h0;
else Q <= D;
endmodule
moduledffChecker (clk, rst_, d, q);
parameter WIDTH = 8;
input clk, rst_;
input [WIDTH-1:0] d, q;
propertyd_q_property_0;
@(posedge clk) !rst_ |->##1 (q == 8'h0);
endproperty
assert_d_q_property_0 : assert property(d_q_property_0);
endmodule
Virtual Instantiation (bind): Use bind method to connection both modules together. It's a
saftest method for DV because it did not change RTLs. Plus we can use OVL for most of
common checkers.
For examples:
binddff dffChecker #(8) Chk0(CLK, RST_, D, Q);
array[$] queue
e.g. int q[$] = { 2, 4, 8 };
q = {}; // clear the queue (delete all items)
e = q[0]; // read the first (leftmost) item
e = q[$]; // read the last (rightmost) item
class EA extends A ;
task disp ();
$display(" This is Extended class A ");
endtask
endclass
program main ;
EA my_ea;
A my_a;
initial
begin
my_a = new();
my_a.disp();
my_ea = new();
my_a = my_ea;
my_a.disp();
end
endprogram
RESULTS
This is class A
This is Extended class A
Answers:
There are 2 types of copy. Show copy or deep copy
For example:
class B;
int
endclass
program main;
initial
begin
B b1;
B b2;
b1 = new();
b1.i = 123;
b2 = b1; // b1 and b2 point to the same memory. The properties did
not get copied.
$display( b2.i );
end
endprogram
RESULTS:
123
RESULTS:
123
321
If the value of b1 change, it will also change the value of b1. It's because it's pointing to
the same memory.
Deep Copy
A deep copy copies all fields, and makes copies of dynamically allocated memory
pointed to by the fields. To make a deep copy, you must write a copy constructor and
overload the assignment operator, otherwise the copy will point to the original, with
disasterous consequences.
EXAMPLE:
class A;
int i;
endclass
class B;
A a;
endclass
program main;
initial
begin
B b1;
B b2;
b1 = new();
b1.a = new();
b1.a.i = 123;
b2 = new b1;
b2.copy(b1.a);
$display( b1.a.i );
$display( b2.a.i );
b1.a.i = 321;
$display( b1.a.i );
$display( b2.a.i );
end
endprogram
RESULTS:
123
123
321
123
1) There is a waveform
in _____|====|________
out_____|=|___|=|______
Verilog code
Answer:
Answer:
example main.cpp
void main()
{
int a=2, b=3;
swap (a, b);
}