Académique Documents
Professionnel Documents
Culture Documents
1 of 59
Clifford E. Cummings
Sunburst Design, Inc.
cliffc@sunburst-design.com www.sunburst-design.com
Stuart Sutherland
Sutherland HDL, Inc.
stuart@sutherland-hdl.com www.sutherland-hdl.com
sponsored by
2 of 59
Cliff Cummings of Sunburst Design presents the details on the major new features in SystemVerilog-2009 that involve hardware models and testbench models
www.sunburst-design.com/papers/ DAC2009_SystemVerilog_Update_Part1_SunburstDesign.pdf
Part 2:
Stu Sutherland of Sutherland HDL presents the details on the major new features in SystemVerilog-2009 that involve SystemVerilog Assertions
www.sutherland-hdl.com/papers/ DAC2009_SystemVerilog_Update_Part2_SutherlandHDL.pdf
1 of 30
Rev 1.1
3 of 59
IEEE 1364.1 Verilog Synthesis Interoperability Group Authored more than 40 technical papers
includes 17 "Best Paper" awards
www.sunburst-design.com/papers www.sunburst-design.com/papers
for 6 years for 6 years Synthesis instructor for 15 years Provides the absolute best Verilog and SystemVerilog training!
Tektronix, FPS, IBM - board, FPGA & ASIC design & Test Lab MSEE-Oregon State Univ. / BSEE-BYU
2009, Sunburst Design, Inc.
4 of 59
www.eda.org/sv-bc/hm/8983.html www.eda.org/sv-bc/hm/8983.html
Disclaimer
Cliff & Stu have made every attempt to show legal SystemVerilog-2009 examples
Not all enhanced features Not all enhanced features can be tested at this time can be tested at this time No guarantees !! No guarantees !!
2 of 30
Rev 1.1
5 of 59
Mantis Item numbers are noted on appropriate slides Mantis items details can be viewed in the Mantis database
After logging in ... After logging in ... Enter Issue # ... Enter Issue # ... ... then select the ... then select the Jump button Jump button
890
2009, Sunburst Design, Inc.
6 of 59
Active Active Inactive Inactive Active region Active region set set Evaluate concurrent Evaluate concurrent assertions assertions Trigger clocking blocks Trigger clocking blocks Reactive region Reactive region set set Execute Execute pass/fail assertion code pass/fail assertion code program block code program block code
Used for sampling & Used for sampling & verifying DUT outputs verifying DUT outputs
(testbench inputs) (testbench inputs)
Re-NBA Re-NBA
Postponed Postponed
3 of 30
Rev 1.1
7 of 59
8 of 59
$display("a=%h
end endprogram
$display
b=%h", a, b);
("a=%h
b=%h" , a, b);
b=000000fb b=00000048 b=000000f4 b=00000860 b=0000003a b=00004895 b=0000007c b=000000da
("a=%0h
b=%0h" , a, b);
("a=%4h
b=%4h" , a, b);
a=71ec a=0003 a=0ed4 a=8fbb a=0003 a=00b1 a=0010 a=097a b=00fb b=0048 b=00f4 b=0860 b=003a b=4895 b=007c b=00da
a=71ec b=fb a=3 b=48 a=ed4 b=f4 a=8fbb b=860 a=3 b=3a a=b1 b=4895 a=10 b=7c a=97a b=da
Remove leading Remove leading 0's (ragged display) 0's (ragged display)
4-character field 4-character field with leading 0's with leading 0's
(orderly display) (orderly display)
4 of 30
Rev 1.1
9 of 59
$display("a=%4x
end endprogram
b=%4x", a, b);
10 of 59
module cplx_adder ( output complex_s sum, input complex_s a, b); assign sum = add(a, b); endmodule
Sized format Sized format specifier %4p for specifier %4p for orderly printing orderly printing
initial $monitor(...);
... endmodule
$monitor("sum=%4p a=%4p b=%4p ", sum, a, b); $monitor("sum=%4p a=%4p b=%4p ", sum, a, b); sum='{re: sum='{re: sum='{re: sum='{re: sum='{re: x, 216, 158, 218, 180, im: x} im: 240} im: 85} im: 240} im: 4} a='{re: x, im: x} a='{re: 193, im: 148} a='{re: 138, im: 154} a='{re: 36, im: 160} a='{re: 108, im: 41} b='{re: x, im: x} b='{re: 23, im: 92} b='{re: 20, im: 187} b='{re: 182, im: 80} b='{re: 72, im: 219}
5 of 30
Rev 1.1
11 of 59
$sformat task assigns $sformat task assigns string to output argument (s) ) string to output argument (s
initial begin $sformat(s, "\nThe value of b = %0d'h%h\n", a, b); $display("%s", s); Output display Output display end endmodule The value of b = 32'haabbccdd module test2;
int a = 32; logic [31:0] b = 32'haabbccdd; string s; SystemVerilog2009 adds SystemVerilog2009 adds $sformatf function $sformatf function that returns aastring that returns string
initial begin s = $sformatf("\nThe value of b = %0d'h%h\n", a, b); $display("%s", s); Mantis 1651: Mantis 1651: end $psprintf was rejected $psprintf was rejected endmodule (Proposed synonym for $sformatf )
2009, Sunburst Design, Inc.
12 of 59
function void check_output; if (cb1.y===exp) $display("PASS: y=%h else $display("FAIL: y=%h endfunction ... endmodule module tb; ...
$fatal / /$error / /$warning / /$info $fatal $error $warning $info can be used anywhere $display can be used can be used anywhere $display can be used exp=%h", y, exp); exp=%h", y, exp);
In SystemVerilog2009 In SystemVerilog2009
function void check_output; if (cb1.y===exp) $info ("PASS: y=%h else $fatal("FAIL: y=%h endfunction ... endmodule
2009, Sunburst Design, Inc.
6 of 30
Rev 1.1
13 of 59
14 of 59
always_ff
Logic-Specific Process
always_ff
Conveys designer's intent to infer clocked logic
module dff1 ( output bit_t q, input bit_t d, clk, rst_n); always_ff @(posedge clk, negedge rst_n) if (!rst_n) q <= 0; else q <= d; endmodule
7 of 30
Rev 1.1
15 of 59
always_ff @(edge clk, negedge rst_n) Could this synthesize to aaDDR flip-flop Could this synthesize to DDR flip-flop in an ASIC vendor library ?? in an ASIC vendor library ??
Sunburst
16 of 59
bin
8
opcode[2:0]
3
alu (8-bit)
alu_out[7]
alu_out
1
zero ones
8
xtend
accum
8
Dangling zero Dangling zero & ones outputs & ones outputs .name allows unconnected .name allows unconnected ports to be omitted ports to be omitted
dataout[7:0]
16
dataout
2009, Sunburst Design, Inc.
Not the original Not the original intent for .name intent for .name
8 of 30
Rev 1.1
17 of 59
Legal (but not required): Legal (but not required): list unconnected ports list unconnected ports
alu alu (.alu_out, .zero(), .one(), .ain, .bin, .opcode); accum accum (.dataout(dataout[7:0]), .datain(alu_out), .clk, .rst_n); xtend xtend (.dout(dataout[15:8]), .din(alu_out[7]), .clk, .rst_n); endmodule ... omit unconnected ports omit unconnected ports alu alu (.alu_out, .ain, .bin, .opcode); accum accum (.dataout(dataout[7:0]), .datain(alu_out), .clk, .rst_n); ...
Legal: Legal:
... omit design port (alu_out) ) omit design port (alu_out alu alu (.ain, .bin, .opcode); accum accum (.dataout(dataout[7:0]), .datain(alu_out), .clk, .rst_n); ...
2009, Sunburst Design, Inc.
Another good reason to avoid using .name Another good reason to avoid using .name
18 of 59
always_comb begin y = 0; unique case ({en,a}) 3'b100: y[a]=1; 3'b101: y[a]=1; 3'b110: y[a]=1; 3'b111: y[a]=1;
endcase end endmodule
unique case unique case with initial default with initial default assignment assignment
SystemVerilog simulators are required SystemVerilog simulators are required to give a run-time warning when en=0 to give a run-time warning when en=0
parallel_case parallel_case (uniqueness) (uniqueness) full_case full_case all possible cases are defined all possible cases are defined (others are "don't cares") (others are "don't cares")
unique means: unique means: (1) case expression can only match 11case item (1) case expression can only match case item (2) case expression MUST match 11case item (2) case expression MUST match case item
2009, Sunburst Design, Inc.
9 of 30
Rev 1.1
19 of 59
y[2]
y[1]
a[1] a[0]
y[0]
20 of 59
always_comb begin y = 0; unique case ({en,a}) 3'b100: y[a]=1; 3'b101: y[a]=1; 3'b110: y[a]=1; 3'b111: y[a]=1; default: ;
endcase end endmodule
unique case unique case with initial default with initial default assignment assignment
unique with empty default unique with empty default same as parallel_case same as parallel_case Empty default Empty default kills full_case kills full_case Ugly, but fixes the Ugly, but fixes the synthesis results synthesis results
10 of 30
Rev 1.1
21 of 59
always_comb begin y = 0; unique0 case ({en,a}) 3'b100: y[a]=1; 3'b101: y[a]=1; 3'b110: y[a]=1; 3'b111: y[a]=1;
endcase end endmodule
unique0 case unique0 case with initial default with initial default assignment assignment
parallel_case parallel_case (uniqueness) (uniqueness) unique0 means: unique0 means: (1) case expression can only match 11case item (1) case expression can only match case item (2) case expression can match 11or 00case items (2) case expression can match or case items
2009, Sunburst Design, Inc.
NOT full_case NOT full_case (others covered by initial (others covered by initial default assignment) default assignment)
22 of 59
y[2]
y[1]
y[0]
11 of 30
Rev 1.1
23 of 59
priority/unique/unique0 Violations
Mantis 2008
Reported as warnings Reported as warnings
(vendors did not want (vendors did not want to report false-errors) to report false-errors)
Reported as violations Reported as violations Ask vendors to provide Ask vendors to provide fatal-on-violation option fatal-on-violation option
Simulation scenario: Simulation scenario: (1) a goes to 1 (1) a goes to 1 (2) always_comb (a1) triggers (2) always_comb (a1) triggers (3) unique case detects violation (3) unique case detects violation (a & not_a both match 1'b1) (a & not_a both match 1'b1) (4) violation report generated (4) violation report generated (scheduled into Observed Region) (scheduled into Observed Region) (5) always_comb (a2) triggers (5) always_comb (a2) triggers (6) not_a goes to 0 (6) not_a goes to 0 (7) always_comb (a1) re-triggers (7) always_comb (a1) re-triggers (8) unique case detects NO violation (8) unique case detects NO violation (9) violation report cleared (9) violation report cleared (before entering Observed Region) (before entering Observed Region)
24 of 59
Default values might be useful Default values might be useful for infrequently used inputs for infrequently used inputs Default values only legal Default values only legal with ANSI-style port list with ANSI-style port list
register module register module with set_n input with set_n input
New input has New input has aadefault value default value
always_ff @(posedge clk, negedge rst_n, negedge set_n) if (!rst_n) q <= '0; else if (!set_n) q <= '1; CAUTION: instantiation rules else q <= d; CAUTION: instantiation rules can be confusing endmodule can be confusing
12 of 30
Rev 1.1
25 of 59
register r1 (.q(q), .d(d), .clk(clk), .rst_n(rst_n), .set_n(set_n)); register r1 (.q, .d, .clk, .rst_n, .set_n); tb overrides default tb overrides default set_n // rst_n values set_n rst_n values
register r1 (.q(q), .d(d), .clk(clk), .rst_n(rst_n)); register r1 (.q, .d, .clk, .rst_n); register keeps default register keeps default set_n // rst_n values set_n rst_n values tb only overrides tb only overrides default rst_n value default rst_n value
CAUTION: this can be confusing CAUTION: this can be confusing
register r1 (.*);
2009, Sunburst Design, Inc.
26 of 59
module tb; logic [7:0] logic [7:0] set_n logic set_n assigned logic assigned
declared declared
q; d; clk; rst_n;
assign set_n = d[7]; // register ... register instantiation register instantiation endmodule
register r1 (.q(q), .d(d), .clk(clk), .rst_n(rst_n), .set_n(.set_n)); tb overrides default set_n // rst_n values tb overrides default set_n rst_n values register r1 (.q(q), .d(d), .clk(clk), .rst_n(rst_n)); tb only overrides tb only overrides default rst_n value default rst_n value
register r1 (.q, .d, .clk, .rst_n, .set_n); register r1 (.q, .d, .clk, .rst_n);
2009, Sunburst Design, Inc.
13 of 30
Rev 1.1
27 of 59
Verilog only allows bit Verilog only allows bit and part selects of and part selects of nets and variables nets and variables ILLEGAL - -to reference aapart ILLEGAL to reference part select on the LHS expression select on the LHS expression
28 of 59
14 of 30
Rev 1.1
29 of 59
q, d, clk, rst_n);
Use the data_t and clk_t Use the data_t and clk_t from the data_pkg from the data_pkg Use the rst_t from Use the rst_t from the bit_pkg the bit_pkg
30 of 59
... packages have been imported ... packages have been imported into the $unit/$root space into the $unit/$root space
(depending upon the simulator) (depending upon the simulator)
15 of 30
Rev 1.1
31 of 59
module register import bit_pkg::rst_t, data_pkg::*; (output data_t q, input data_t d, input clk_t clk, input rst_t rst_n); ... endmodule
2009, Sunburst Design, Inc.
... packages have been imported ... packages have been imported locally into the register module locally into the register module
32 of 59
If used, re-declaration of src1_t If used, re-declaration of src1_t and dst1_t was required and dst1_t was required
import and use the import and use the expanded pkg2a package expanded pkg2a package
2009, Sunburst Design, Inc.
16 of 30
Rev 1.1
33 of 59
Mantis 1323
module register ( output pkt_t q, input pkt_t d, input logic clk, input logic rst_n); ... endmodule
34 of 59
package pkg4; import pkg3a::byte_t; import pkg3b::*; import pkg3c::*; import pkg3d::*; export *::*; endpackage export all packages export all packages
(using wildcards) (using wildcards)
Like doing package Like doing package extension ... extension ...
2009, Sunburst Design, Inc.
17 of 30
Rev 1.1
35 of 59
package complex; typedef struct { logic [7:0] re; logic [7:0] im; } complex_s;
package automatic complex; typedef struct { logic [7:0] re; logic [7:0] im; ... automatic ... automatic function } complex_s; function function complex_s add; input complex_s a, b; complex_s sum; sum.re = a.re + b.re; sum.im = a.im + b.im; return(sum); endfunction endpackage
function complex_s add; input complex_s a, b; complex_s sum; sum.re = a.re + b.re; sum.im = a.im + b.im; return(sum); endfunction endpackage
2009, Sunburst Design, Inc.
36 of 59
Cannot override localparam Cannot override localparam Ordered parameter replacement Ordered parameter replacement omits the localparam value omits the localparam value
ram instantiation: ram instantiation: AWIDTH=20 (1MB) AWIDTH=20 (1MB) DWIDTH=16 DWIDTH=16
2009, Sunburst Design, Inc.
18 of 30
Rev 1.1
37 of 59
38 of 59
File: rtl.cfg File: rtl.cfg config rtl; design tbLib.tb; default liblist rtlLib; instance tb use (.SZ(16)); endconfig Parameter values Parameter values before config before config SZ SZ =12 =12 WIDTH=12 (default 4) WIDTH=12 (default 4) SIZE =12 (default 8) SIZE =12 (default 8) Parameter values Parameter values after rtl config after rtl config SZ SZ =16 =16 WIDTH=16 WIDTH=16 SIZE =16 SIZE =16
More config parameter More config parameter capabilities have been added capabilities have been added (not shown) (not shown)
File: lib.map File: lib.map library tbLib tb/*.sv; library rtlLib rtl/*.sv;
19 of 30
Rev 1.1
39 of 59
Pass an argument to Pass an argument to the macro arg the macro arg
Define aamulti-line macro Define multi-line macro with input arguments with input arguments
(not all Verilog coders know this)
(not all Verilog coders know this) `define assert_clk( arg ) \ assert property (@(posedge clk) disable iff (!rst_n) arg )
2009, Sunburst Design, Inc.
40 of 59
20 of 30
Rev 1.1
41 of 59
`define data size, `define data size, `define address size `define address size `define memory depth `define memory depth
`undef data size, `undef data size, `undef address size `undef address size `undef memory depth `undef memory depth
42 of 59
`undefineall
Mantis 1090
`define DSIZE 8 `define ASIZE 10 `define MDEPTH 1024 module ram1 ( inout [`DSIZE-1:0] data, input [`ASIZE-1:0] addr, input en, rw_n); logic [`DSIZE-1:0] mem [0:`MEM_DEPTH-1]; assign data = (rw_n && en) ? mem[addr] : {`DSIZE{1'bz}}; always_latch begin if (!rw_n && en) mem[addr] <= data; end endmodule `undefineall `define data size, `define data size, `define address size `define address size `define memory depth `define memory depth
`undefineall un-defines `undefineall un-defines all `define macros all `define macros
21 of 30
Rev 1.1
43 of 59
module ram1 #(parameter ASIZE=10, DSIZE=8) (inout [DSIZE-1:0] data, input [ASIZE-1:0] addr, input en, rw_n); localparam MEM_DEPTH = 1<<ASIZE; logic [DSIZE-1:0] mem [0:MEM_DEPTH-1]; assign data = (rw_n && en) ? mem[addr] : {DSIZE{1'bz}}; always_latch begin if (!rw_n && en) mem[addr] <= data; end endmodule
Make the memory depth Make the memory depth aalocalparam localparam Calculate the memory depth Calculate the memory depth from the address size from the address size
Guideline: choose parameter first Guideline: choose parameter first Guideline: choose `define only if needed Guideline: choose `define only if needed
44 of 59
22 of 30
Rev 1.1
45 of 59
function void aa_display; $display("%0d ARRAY ELEMENTS %0d", aa.num()); foreach (aa[i]) $display("aa[%4d]=%2", i, aa[i]); endfunction foreach stores each aa[] index in the i variable foreach stores each aa[] index in the i variable
46 of 59
SV2009 defines SV2009 defines .size() method - .size() method synonym for synonym for .num() method .num() method
23 of 30
Rev 1.1
47 of 59
Queue Delete
Mantis 1560
SV2009 adds aabuilt-in method SV2009 adds built-in method to delete an entire queue to delete an entire queue
program q_methods; bit [7:0] q[$] = '{8'hA0, 8'hA1, 8'hA2}; bit [7:0] data; int q_size;
$display $display
data=8'h00
8'hA0 8'hA1 8'hA2 8'hA0 8'hA1 8'hFF 8'hA2 8'hA0 8'hFF 8'hA2 8'hFF 8'hA2 8'hFF 8'hBB 8'hFF 8'hBB 8'hFF 8'hCC <empty>
q.size=3
initial begin $display("q.size=%0d", q.size()); q.insert(2,8'hff); q.delete(1); data=q.pop_front(); pop_front pop_front data=q.pop_back(); q.push_front(8'hbb); pop_back pop_back q.push_back(8'hcc); q.delete() end endprogram
No argument No argument means to delete means to delete entire queue entire queue
2009, Sunburst Design, Inc.
New to SV2009 New to SV2009 delete entire queue delete entire queue
48 of 59
24 of 30
Rev 1.1
49 of 59
static keyword is optional - static keyword is optional initialization happens before time 00 initialization happens before time automatic variable automatic variable assignment executes each assignment executes each time the outer loop is called time the outer loop is called
Display values Display values
The static variable The static variable assignment executes assignment executes once before time 00 once before time
Display values Display values
50 of 59
argument types must match argument directions must match number of arguments must match return types must match
pure creates aaplace-holder pure creates place-holder pure requires that aa pure requires that method be overridden with method be overridden with an actual implementation an actual implementation
pure requires:
method shall only be a prototype no code can be included for the prototype not even allowed to have endfunction/endtask keywords pure virtual methods MUST be overridden in non-abstract classes
25 of 30
Rev 1.1
51 of 59
Pure Constraint
Mantis 2514 pure constraint is an constraint prototype defined in an abstract class (virtual class) pure requires:
constraint shall only be a prototype
pure constraint constraint-name;
pure requires that aa pure requires that constraint be overridden constraint be overridden with an actual constraint with an actual constraint
52 of 59
function void startup; fork b <= 8'hcc; #1 $display("%t: 2nd Sequence started - b=%2h", $time, b); #3 run; task call that consumes task call that consumes #2 $display("%t: 3rd Sequence started", $time); time (3+3+4=10ns) time (3+3+4=10ns) join_none $display("%t: Initial Sequence started", $time); endfunction
Nonblocking assignment legal Nonblocking assignment legal in function when surrounded in function when surrounded by fork / /join_none by fork join_none
0ns: Initial Sequence started 1ns: 2nd Sequence started - b=cc 2ns: 3rd Sequence started RUN( 10ns): a=88
26 of 30
Rev 1.1
53 of 59
10
class C #(int p = 1, type T = int); extern static function T f(); endclass function C::T C::f(); return p + C::p; endfunction
SystemVerilog-2009 adds the SystemVerilog-2009 adds the ability to have parameterized ability to have parameterized classes with external methods classes with external methods Declaration of Declaration of
extern static function (method) extern static function (method) with return type T (parameterized type) with return type T (parameterized type)
54 of 59
27 of 30
Rev 1.1
55 of 59
56 of 59
SystemVerilog-2009 SystemVerilog-2009 1ns/1ns 1ns/1ns timescale timescale active active `timescale 1ns/1ns module tb; ... endmodule module register ( output logic [7:0] q, input logic [7:0] d, input logic clk); timeunit 100ps/100ps;
Combined 1-line syntax Combined 1-line syntax Must be placed Must be placed immediately after immediately after module header module header
always_ff @(posedge clk) q <= #1 d; endmodule module blka (...); ... endmodule
2009, Sunburst Design, Inc.
always_ff @(posedge clk) q <= #1 d; endmodule module blka (...); ... endmodule
28 of 30
Rev 1.1
57 of 59
58 of 59
These macros allow access to the current file and line number from within SystemVerilog code
29 of 30
Rev 1.1
59 of 59
SystemVerilog-2009 defines how these checks are annotated from SDF files
60 of 59
Clifford E. Cummings
Sunburst Design, Inc.
cliffc@sunburst-design.com www.sunburst-design.com
Stuart Sutherland
Sutherland HDL, Inc.
stuart@sutherland-hdl.com www.sutherland-hdl.com
sponsored by
30 of 30
Rev 1.1