System Verilog Commands

⚡ SystemVerilog Commands – Enhanced Data Types

TopicQuestionAnswer
SVModule declarationmodule name(input logic clk, output logic q);
SVInterface portinterface_name.modport port_name
SVAlways combinationalalways_comb begin ... end
SVAlways sequentialalways_ff @(posedge clk) begin ... end
SVAlways latchalways_latch begin ... end
SVLogic declarationlogic [31:0] value;
SVLogic 2-statebit [3:0] nibble;
SVByte typebyte signed_byte;
SVShortint typeshortint data;
SVInt typeint counter;
SVLongint typelongint big_num;
SVPacked arraylogic [7:0][3:0] packed_array;
SVUnpacked arraylogic [7:0] unpacked [0:15];
SVDynamic array declarelogic [7:0] dyn_array [];
SVDynamic array newdyn_array = new[10];
SVDynamic array resizedyn_array = new[20] (dyn_array);
SVDynamic array deletedyn_array.delete();
SVDynamic array sizesize = dyn_array.size();
SVAssociative arraylogic [7:0] assoc_array [int];
SVAssociative array stringlogic [7:0] assoc [string];
SVAssociative existsif (assoc.exists(key))
SVAssociative deleteassoc.delete(key);
SVAssociative firstassoc.first(key);
SVAssociative nextassoc.next(key);
SVAssociative numsize = assoc.num();
SVQueue declarationlogic [7:0] queue [$];
SVQueue with maxlogic [7:0] queue [$:15];
SVPush backqueue.push_back(data);
SVPush frontqueue.push_front(data);
SVPop backdata = queue.pop_back();
SVPop frontdata = queue.pop_front();
SVQueue insertqueue.insert(index, data);
SVQueue deletequeue.delete(index);
SVQueue sizesize = queue.size();
SVArray defaultint a[10] = '{default:5};
SVArray literalint a[3] = '{1, 2, 3};
SVArray patternint a[4] = '{0:1, 1:2, default:0};
SVAssign all bits 1bit [31:0] data = '1;
SVAssign all bits 0bit [31:0] data = '0;
SVStreaming operator{>>byte_data} = stream;
SVTypedef enumtypedef enum {IDLE, RUN, DONE} state_t;
SVEnum with valuestypedef enum {RED=1, GREEN=2, BLUE=4} color_t;
SVEnum firstcolor_t c = c.first();
SVEnum nextc = c.next();
SVEnum namestring name = c.name();
SVTypedef structtypedef struct {int x; int y;} point_t;
SVPacked structtypedef struct packed {bit[3:0] a; bit[3:0] b;} data_t;
SVUniontypedef union {int i; real r;} union_t;
SVTagged uniontypedef union tagged {int i; real r;} tagged_u;

⚡ SystemVerilog Commands – Interfaces & Modports

TopicQuestionAnswer
SVInterface declarationinterface name; logic [7:0] data; endinterface
SVInterface with parameterinterface name #(parameter WIDTH=8); ...
SVModport mastermodport master (input data_in, output data_out);
SVModport slavemodport slave (output data_in, input data_out);
SVClocking blockclocking cb @(posedge clk); input data; endclocking
SVModport with clockingmodport tb (clocking cb);
SVInterface instantiationinterface_name inst();
SVConnect interfacemodule_name dut(.bus(inst.master));
SVVirtual interfacevirtual interface_name vif;
SVAssign virtual interfacevif = inst;

⚡ SystemVerilog Commands – Classes & OOP

TopicQuestionAnswer
SVClass declarationclass name; int var; function new(); endfunction; endclass
SVClass with parameterclass name #(parameter WIDTH=8); ...
SVClass constructorfunction new(); var = 0; endfunction
SVConstructor with argsfunction new(int init_val); var = init_val; endfunction
SVCreate objectname obj = new();
SVCreate with argsname obj = new(10);
SVClass propertyint data;
SVLocal propertylocal int private_data;
SVProtected propertyprotected int prot_data;
SVStatic propertystatic int shared_count;
SVConst propertyconst int SIZE = 10;
SVClass methodfunction void display(); ... endfunction
SVTask in classtask run(); ... endtask
SVStatic methodstatic function int get_count(); ... endfunction
SVExtern methodextern function void compute();
SVVirtual methodvirtual function void process(); ... endfunction
SVClass inheritanceclass child extends parent; ... endclass
SVSuper callsuper.method();
SVSuper newfunction new(); super.new(); endfunction
SVThis keywordthis.var = value;
SVAbstract classvirtual class name; pure virtual function void f(); endclass
SVPolymorphismparent p = child::new();
SVCopy objectdest = src.copy();
SVClone objectnew_obj = obj.clone();
SVCompare objectsif (obj1.compare(obj2))

⚡ SystemVerilog Commands – Constraints & Randomization

TopicQuestionAnswer
SVRand variablerand int data;
SVRandc variablerandc bit [3:0] value;
SVConstraint blockconstraint c_name { x > 0; x < 100; }
SVConstraint rangeconstraint c { x inside {[1:10]}; }
SVConstraint distributionconstraint c { x dist {0:=40, [1:3]:=60}; }
SVConstraint implicationconstraint c { if (mode == 0) x < 10; }
SVConstraint foreachconstraint c { foreach (arr[i]) arr[i] < 100; }
SVSoft constraintconstraint c { soft x == 5; }
SVConstraint disableobj.c_name.constraint_mode(0);
SVConstraint enableobj.c_name.constraint_mode(1);
SVRandomizeif (!randomize()) $error("Failed");
SVRandomize variableif (!obj.randomize())
SVRandomize withrandomize(x) with { x > 10; x < 20; };
SVPre-randomizefunction void pre_randomize(); ... endfunction
SVPost-randomizefunction void post_randomize(); ... endfunction
SVDisable randrand_mode(0);
SV$urandomdata = $urandom();
SV$urandom_rangedata = $urandom_range(min, max);

⚡ SystemVerilog Commands – Assertions

TopicQuestionAnswer
SVImmediate assertassert (condition) else $error("Failed");
SVImmediate assert no actionassert (a == b);
SVAssume statementassume (condition);
SVCover statementcover (condition);
SVAssert propertyassert property (@(posedge clk) req |-> ack);
SVAssume propertyassume property (@(posedge clk) req |-> ack);
SVCover propertycover property (@(posedge clk) req ##1 ack);
SVSequence definitionsequence seq; @(posedge clk) a ##1 b; endsequence
SVSequence delaysequence seq; a ##2 b; endsequence
SVSequence range delaysequence seq; a ##[1:3] b; endsequence
SVSequence repetitionsequence seq; a[*3]; endsequence
SVSequence goto repetitionsequence seq; a[->3]; endsequence
SVSequence non-consecutivesequence seq; a[=3]; endsequence
SVSequence throughoutsequence seq; a throughout b[*3]; endsequence
SVProperty definitionproperty prop; @(posedge clk) a |-> ##[1:3] b; endproperty
SVProperty implicationproperty prop; req |-> ack; endproperty
SVProperty if-elseproperty prop; if (mode) (a |-> b) else (c |-> d); endproperty
SVProperty disable iffproperty prop; @(posedge clk) disable iff (rst) req |-> ack; endproperty
SVConcurrent assertassert_name: assert property (prop) else $error("Failed");
SVAssertion with actionassert property (prop) pass_action else fail_action;

⚡ SystemVerilog Commands – Processes & IPC

TopicQuestionAnswer
SVFork-joinfork ... join
SVFork-join_anyfork ... join_any
SVFork-join_nonefork ... join_none
SVWait forkwait fork;
SVDisable forkdisable fork;
SVProcess controlprocess p = process::self();
SVProcess awaitp.await();
SVProcess killp.kill();
SVMailbox declarationmailbox #(int) mbx = new();
SVMailbox boundedmailbox #(int) mbx = new(10);
SVMailbox putmbx.put(data);
SVMailbox getmbx.get(data);
SVMailbox try_putif (mbx.try_put(data))
SVMailbox try_getif (mbx.try_get(data))
SVMailbox peekmbx.peek(data);
SVMailbox numsize = mbx.num();
SVSemaphore declarationsemaphore sem = new(1);
SVSemaphore getsem.get(1);
SVSemaphore putsem.put(1);
SVSemaphore try_getif (sem.try_get(1))
SVEvent declarationevent evt;
SVTrigger event-> evt;
SVWait event@evt;
SVWait event triggeredwait(evt.triggered);

⚡ SystemVerilog Commands – Packages & Program

TopicQuestionAnswer
SVPackage declarationpackage pkg_name; ... endpackage
SVImport packageimport pkg_name::*;
SVImport specificimport pkg_name::item;
SVExport from packageexport pkg_name::item;
SVProgram blockprogram test; ... endprogram
SVInitial in programinitial begin ... end
SVFinal blockfinal begin ... end
SV$unit scopeAccess to compilation-unit scope

⚡ SystemVerilog Commands – Functional Coverage

TopicQuestionAnswer
SVCovergroup definitioncovergroup cg @(posedge clk); ... endgroup
SVCoverpointcoverpoint data;
SVCoverpoint with binscoverpoint data { bins low = {[0:31]}; }
SVAuto binscoverpoint data { bins auto[4] = {[0:255]}; }
SVIllegal binsillegal_bins bad = {127};
SVIgnore binsignore_bins ign = {255};
SVCross coveragecross addr, data;
SVCovergroup optionsoption.per_instance = 1;
SVCovergroup samplecg.sample();
SVGet coveragereal cov = cg.get_coverage();

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top