⚫ System Verilogis a hardware description and Verification language (HDVL). ⚫ It was developed by Accellera Systems Initiative and the IEEE Standards Association to address the growing complexity of modern digital systems. ⚫ System Verilog (IEEE Standard 1800-2005) is an extensive set of enhancements to IEEE 1364 Verilog- 2001 standards. ⚫ It inherits features from Verilog, VHDL, C and C++. ⚫ One of the key advantages of using SV is its ability to streamline the design and verification process. ⚫ Another significant advantage of System Verilog is its support for advanced verification techniques, such as the Universal Verification Methodology (UVM). What is SV?
⚫System Verilog offersfollowing Data Types: o 4-State Type o 2-State Type o Real o Arrays o User Define Data Type o Structures o Unions o Strings o Enumerated Type o Class
5.
⚫Allowed values are0, 1, X and Z. ⚫Following 4-State types are included from Verilog: o wire //Size: 1-bit Value: Z o reg //Size: 1-bit Value: X o integer // Size: 32-bit Value: X o time // Size: 64-bit Value: X ⚫User can define size for wire and reg. ⚫integer is signed, all others are unsigned. 4-State Type
6.
⚫Addition to SystemVerilog o logic //Size: 1- bit ⚫User can define size for logic. Value: X ⚫Logic is improved reg data type. ⚫Logic can be driven by continuous as well as procedural assignments. ⚫Logic has a limitation that it cannot be driven by multiple drivers in such case use wire. 4-State Type
Logic driver . Example3: module example3 (input logic a, b, output logic c); assign c= a & b; //driving logic using continuous assignment always @ * c= a | b; assignmen t //driving logic using procedural eTnhdismcoodduelewill give compilation error because of multiple
9.
Logic Compilation error, usewire to achieve this functionality. Example4: module example4 ( input logic a, b, ctrl, output logic c); assign c= ctrl?a:1’bZ; //driving logic using continuous assignment assign c= !ctrl?b:1’bZ; //driving logic using continuous assignmen t endmodul e
10.
⚫Allowed values are0 and 1. ⚫System Verilog offers following 2-State Data Types : ⚫ All are signed except bit which is unsigned. o shortint //Size: 16-bit Value: 0 o int //Size: 32-bit Value: 0 o longint //Size: 64-bit Value: 0 o byte //Size: 8-bit Value: 0 o bit //Size: 1-bit Value: 0 ⚫User can define size for bit. 2-State Type
11.
Example1 c=‘0; end endmodul e // locations withgiven number module example1; int a; int unsigned b; bit signed [7:0] c; initia l begi n a=-32’d127; b=‘1; //unsigned integer //same as byte //SV offers un-sized literal to fill all
12.
Example2 module example2; int a; logic[31:0] b=‘Z; initia l begi n a=b; b=32 ’h12 3x_5 678; //b=32’hzzzz_zzzz // a=32’h0000_0000 if($unknown(b)) $display(“b is unknown”); $display(“b is known”); else end end mo dul
13.
⚫Included from Verilog oreal //Default Value : 0 ⚫real is same as double in C. ⚫Addition to System Verilog o shortreal //Default Value : 0 o realtime //Default Value : 0 ⚫shortreal is same as float in C. ⚫realtime and real can be used interchangeably. Real Type
14.
⚫void data typerepresents non existing data. ⚫It can be used as return type of functions to indicate nothing is returned. Void Usage: display() ; Example : function void display; $display(“Hello”) ; endfunction
15.
⚫Arrays are usedto group elements of same type. ⚫Arrays can be categorized as following: o Fixed Array o Dynamic Array o Packed Array o Unpacked Array o Queues o Associative Array Arrays
16.
⚫Array whose sizeis fixed during compilation time is called as Fixed Array. ⚫Size of fixed array cannot be modified during run time. element Fixed Array Examples int array1 [15]; elements //array of int containing 15 //Equivalent to int array1 [0:14] int array2 [0:14]; logic array3 [7:0]; //array of logic containing 8
17.
⚫Unpacked Arrays canbe declared by adding size after array name. ⚫Unpacked Arrays can be made of any data type. Example: ⚫System Verilog stores each element of an unpacked array in a longword (32-bit). Unpacked Array int array1 [16] [8]; bit array2 [3:0] [7:0]; bit [7:0] array3 [4]; //16 rows , 8 columns //4 rows , 8 columns //4 rows each containing 8 bits
18.
Unpacked Array bit [7:0]array1 [4]; array1 [2] array1 [3] Unus ed 7 6 5 4 3 2 1 0 Unu sed 7 6 5 4 3 2 1 0 array1 [0] Memory array1 [1] Memory Unu sed 7 6 5 4 3 2 1 0 Memory Unu sed 7 6 5 4 3 2 1 0 Memory
Basic Array Operation ⚫Arrayscan be manipulated using for and foreach loop bit [7:0] array1[10], array2[10] ; initia l begi n for ( int i=0; i <$siz e(arr ay1); //$size returns size of //k is defined implicitly
⚫Packed Arrays canbe declared by adding size before array name. ⚫One dimensional packed arrays are also referred as vectors. ⚫Packed array is a mechanism of subdividing a vector into subfields which can be accessed as array elements. ⚫Packed array represents contiguous set of bits. ⚫Packed array can be made of single bit data (logic, bit, reg), enumerated type or other packed arrays. Packed Array
Packed vs. UnpackedArray ⚫ Packed arrays are handy if user wants to access array with different combination. ⚫ If user want to wait for change in array(i.e. @), in that case packed array will be preferred over unpacked array. ⚫ Only fixed size arrays can be packed. Therefore it is not possible to pack following arrays: o Dynamic Arrays o Queues o Associative Arrays
27.
Operation on Arrays intA [0:7] [15:0] , B [0:7] [15:0]; ⚫Following operation are possible for both packed and unpacked arrays. ⚫Both array A and B should be of same type and size. A=B; A[0:3]= B[0:3]; A[1+:4]= B[3+:4]; A[5]=B[5]; A==B A[2:4]! =B[2:4]; //Copy Operation //Slice and Copy //Comparison Operations
28.
Operation on Arrays bit[3:0] [7:0] A; ⚫Following operation are only allowed in packed arrays: A=0; A=A + 3; A=A * 2; A=‘1; A=A & 32’d255; A[3:1]=16’b1101_1110_0000_1010;
29.
⚫Dynamic arrays areunpacked arrays whose size can be set and changed during simulation time. ⚫new constructor is used to set or change size of Dynamic Array. ⚫size() method returns current size of array. ⚫delete() method is used to delete all elements of the array. Dynamic Array
30.
Dynamic Array int dyn1[ ]; int dyn2 [4] [ ]; //Defining Dynamic Array (empty subscript) initial begin dyn1=new[10]; foreach (dyn1[ i ]) dyn1[ i ]=$random; dyn1=new[20] (dyn1); //Allocate 10 elements // Initializing Array // Resizing array and // Copying older values // Resizing to 50 elements Old Values are lost // Delete all elements dyn1=new[50 ]; dyn1.delete; end
31.
Dynamic Array int dyn1[ ]= ‘{5, 6, 7, 8} ; //Alternative way to define size initial begin repeat (2) if (dyn1.size != 0) begin foreach(dyn1 [ i ] ) $display(“dyn1 [%0d]=%0d”, i, dyn[ i ] ); dyn1.delete; en d else
32.
⚫System Verilog allowsuser to define new data types using typedef keyword. User Defined typedef byte unsigned uint8; typedef bit [15:0] word; //Defining uint8 //Defining word uint8 a, b; word c, d; a=8’d10; c=16’d25;
33.
⚫System Verilog stringtype is used to store variable length strings. ⚫Each character of string is of type byte. ⚫There is no null character at the end of string. ⚫String uses dynamic memory allocation, so size of string is no longer a concern. Example : string s=“hello”; String
34.
String Operators ⚫str1 ==str2 checks whether strings are equal or not. ⚫str1 != str2 checks for inequality of strings. ⚫Comparison using lexicographical ordering of strings. o str1 < str2 o str1 <= str2 o str1 > str2 o str1 >= str2 ⚫{str1, str2, str3, .. , strn} concatenation of strings.
35.
String Operators Example : strings1=“hello”, s2=“Hello”, s3=“xyz”; initial begin if(s1 != s2) $display(“strings are different”); if(s1 > s3) $display(“s1 is more than s3”); else $display(“s3 is more than s1”); $display({s1, s2, s3}); end
36.
String Methods ⚫len() methodreturns length of a string. ⚫putc(position, character) method replaces character at given position by character passed as an argument. ⚫getc(position) method returns ASCII value of character at given position. ⚫toupper() method returns a string with all characters in uppercase.
37.
String Methods ⚫tolower() methodreturns a string with all characters in lowercase. ⚫compare(string) compares given string with string passed as an argument. ⚫icompare(string) same as above but comparison is case insensitive. ⚫substr(i, j) returns a string formed between characters at position i and j.
38.
String Methods ⚫atoi() methodreturns integer corresponding to ASCII decimal representation. ⚫The conversion scans all leading digits and underscore characters ( _ ) and stops as soon as it encounters any other character or the end of the string. ⚫itoa(i) stores the ASCII decimal representation of i in sEtrxinagm.ple : string s1=“12_3xyz”, s2; int a, b=127; a=s1.atoi(); //a=123 s2.itoa(b); // s2=“127”
⚫An enumeration createsa strong variable type that is limited to a set of specified names. Example : enum { RED, GREEN, BLUE } color; typedef enum { FETCH, DECODE, EXECUTE } operation_e; ⚫enum are stored as int unless specified. typedef enum bit [2:0] { RED, GREEN, BLUE } color_e; ⚫First member in enum gets value 0, second value 1 and so on. ⚫User can give different values to member if required. Enumerated Type
41.
Enumerated Type Example : enum{ RED, GREEN, BLUE } color; //RED=0, GREEN=1, BLUE=2 enum { GOLD, SILVER=3, BRONZE} medals; //GOLD=0, SILVER=3, BRONZE=4 enum {A=1, B=3, C, D=4} alphabet; //Compilation error C and D have same value enum logic [1:0] {A=0; B=‘Z, C=1, D} exam; //A=00, B=ZZ, C=01, D=10 Default value of exam is X
42.
⚫first() method returnsfirst member of enumeration. ⚫last() method returns last member of enumeration. ⚫next(N) method returns the Nth next member (default is 1) starting from current position. ⚫previous(N) method returns Nth previous member (default is 1) starting from current position. Enumerated Type Methods
43.
⚫Both next() andprev() wraps around to start and end of enumeration respectively. ⚫num() method returns number of elements in given enumeration. ⚫name() method returns the string representation of given enumeration value. Enumerated Type Methods
44.
Enumerated Type Methods Example typedefenum { RED, BLUE, GREEN} color_e; color_e mycolor; mycolor = mycolor.first; do begin $display("Color = %0d %0s", mycolor, mycolor.name); mycolor = mycolor.next; end while (mycolor != mycolor.first); // Done at wrap- around
45.
const ⚫const keyword isused to define constants in System Verilog. ⚫localparam constants are set during elaboration time. ⚫const constants are set during simulation time. Example: const byte colon= “:”; const real pi=3.14;
46.
Events • Events arestatic objects useful for synchronization between the process. • Events operations are of two staged processes in which one process will trigger the event, and the other processes will wait for an event to be triggered. • Events are triggered using -> operator or ->> operator. • wait for an event to be triggered using @ operator or wait() construct • System Verilog events act as handles to synchronization queues. thus, they can be passed as arguments to tasks, and they can be assigned to one another or compared. • Syntax: a) ->event_name; b) @(event_name.triggered);
47.
Casting ⚫Casting is usedconvert data from one type to other. ⚫There are two ways to perform casting : o Static Casting: destination = return_type’ (source). This type of casting always succeeds at run time and does not give any error. o Dynamic Casting: using $cast system task or function. Example : int a; initial a=int’(3.0 * 2.0);
48.
Casting ⚫System Verilog providesthe $cast system task to assign values to variables that might not ordinarily be valid because of differing data type. ⚫ $cast can be called as either a task or a function. $cast used as a function if ($cast(destination, source)) source // should be singular $cast used as a task $cast(destination, source); //destination and
49.
Casting int a; real b=3.0; if($cast(a,b)) //Returns 1 if casting succeeds else 0 $display(“casting success”); $cast(a, b); //If casting fails run time error occurs In both cases if casting fails then destination value remains unchanged.
Casting typedef enum {red, green, blue, yellow, white, black } Colors; Colors col; int a, b; initial begin col=green; //col=3; a= blue * 2; b= col + green; end Runtime error
52.
Casting en d typedef enum {red, green, blue, yellow, white, black } Colors; Colors col; initial begin $cast( col, 2 + 3 ); // col=black if ( ! $cast( col, 2 + 8 ) ) $display( "Error in cast" ); //10: invalid cast col = Colors’(2 + 1); col = Colors’(4 + 3); //col=yellow //value is empty
Loops inital begin int a [8][5]; foreach ( a [i, j] ) a[i] [j]=$rando m; end inital begin int i=10; do begin i -=1; //statements end while (i >5) end Statements executed first an then execution depends upon condition Used to access all elements in an array
55.
Break and Continue inital beginint i; repeat(10) begin if(i==7) break; i+=1; en d en inital begin int i; repeat(10) begin if(i==7) continue; i+=1; en d en
56.
If-else Expression Futurewiz www.futurewiz.co.i ⚫It ispossible to select property expression based on some condition using if-else expression. property test; @(posedge clk) (req1 || req2) -> if(req1) ##1 ack1; else ##1 ack2; endpropert y