Google

Lubee's Blog--Digtial IC Fan's Home

WELCOME IC FANS' HOME! --ASIC/IC Design,Logical Design,STA,Digital IC Design,Synthesis, and so on.

2008-01-06

systemverilog tutorial(Ch3 Data Types 1)



Introduction



SystemVerilog added lot of new data types and improved the existing data types to improve run time memory utilization of simulators. Highlights of the SystemVerilog datatypes are below


space.gif




  • shortint and longint data types.
  • shortreal (real was already defined in Verilog) data type.
  • string, chandle and class data types.
  • logic, bit and byte data type.
  • User defined types typedef.
  • struct, union, and class data types.
  • void data type.
  • null data type.
  • arrays, queue, associative array, dynamic array

space.gif




Next few pages we shall see the basics of this new data types, and then in later chapers we shall see the details of each of this data types.


space.gif


../images/main/bulllet_4dots_orange.gif Integer data types



Integer data types can be classified into 2-state types and 4-state types. 2-state types can take only 0, 1, where as 4-state types can take 0,1,X,Z. 2-state types consume less (50%) memory and simulate faster when compared to 4-state types.


space.gif




2 state value integer data types are




  • shortint : 16-bit signed integer.
  • int : 32-bit signed integer.
  • longint : 64-bit signed integer.
  • byte : 8-bit signed integer, can be used for storing ASCII charater.
  • bit : User defined vector types.



4-state value integers data types are




  • logic : User defined vector types.
  • reg : User defined vector types.
  • wire : User defined vector types.
  • integer : 32-bit signed integer.
  • time : 64-bit unsigned integer.

space.gif




Integer types can be signed or unsigned, thus can change the result of a arthimetic operation. So care should be taken when declaring the data types that may be have to do arthimetic operation on it. By default byte, shortint, int, integer and longint default to signed and bit, reg, logic, and wire defaults to unsigned.


space.gif




NoteData type reg and logic are one and same. logic data type was introduced to avoid confusion with reg data type.


space.gif


../images/main/bullet_star_pink.gif Example - Integer Types

space.gif





1 module data_types();
2
3 bit data_1bit;
4 byte data_8bit;
5 shortint data_16bit;
6 int data_32bit;
7 longint data_64bit;
8 integer data_integer;
9
10 bit unsigned data_1bit_unsigned;
11 byte unsigned data_8bit_unsigned;
12 shortint unsigned data_16bit_unsigned;
13 int unsigned data_32bit_unsigned;
14 longint unsigned data_64bit_unsigned;
15 integer unsigned data_integer_unsigned;
16
17 initial begin
18 data_1bit = {32{4'b1111}};
19 data_8bit = {32{4'b1111}};
20 data_16bit = {32{4'b1111}};
21 data_32bit = {32{4'b1111}};
22 data_64bit = {32{4'b1111}};
23 data_integer= {32{4'b1111}};
24 $display("data_1bit = ‰0d",data_1bit);
25 $display("data_8bit = ‰0d",data_8bit);
26 $display("data_16bit = ‰0d",data_16bit);
27 $display("data_32bit = ‰0d",data_32bit);
28 $display("data_64bit = ‰0d",data_64bit);
29 $display("data_integer = ‰0d",data_integer);
30 data_1bit = {32{4'bzx01}};
31 data_8bit = {32{4'bzx01}};
32 data_16bit = {32{4'bzx01}};
33 data_32bit = {32{4'bzx01}};
34 data_64bit = {32{4'bzx01}};
35 data_integer= {32{4'bzx01}};
36 $display("data_1bit = ‰b",data_1bit);
37 $display("data_8bit = ‰b",data_8bit);
38 $display("data_16bit = ‰b",data_16bit);
39 $display("data_32bit = ‰b",data_32bit);
40 $display("data_64bit = ‰b",data_64bit);
41 $display("data_integer = ‰b",data_integer);
42 data_1bit_unsigned = {32{4'b1111}};
43 data_8bit_unsigned = {32{4'b1111}};
44 data_16bit_unsigned = {32{4'b1111}};
45 data_32bit_unsigned = {32{4'b1111}};
46 data_64bit_unsigned = {32{4'b1111}};
47 data_integer_unsigned = {32{4'b1111}};
48 $display("data_1bit_unsigned = ‰d",data_1bit_unsigned);
49 $display("data_8bit_unsigned = ‰d",data_8bit_unsigned);
50 $display("data_16bit_unsigned = ‰d",data_16bit_unsigned);
51 $display("data_32bit_unsigned = ‰d",data_32bit_unsigned);
52 $display("data_64bit_unsigned = ‰d",data_64bit_unsigned);
53 $display("data_integer_unsigned = ‰d",data_integer_unsigned);
54 data_1bit_unsigned = {32{4'bzx01}};
55 data_8bit_unsigned = {32{4'bzx01}};
56 data_16bit_unsigned = {32{4'bzx01}};
57 data_32bit_unsigned = {32{4'bzx01}};
58 data_64bit_unsigned = {32{4'bzx01}};
59 data_integer_unsigned = {32{4'bzx01}};
60 $display("data_1bit_unsigned = ‰b",data_1bit_unsigned);
61 $display("data_8bit_unsigned = ‰b",data_8bit_unsigned);
62 $display("data_16bit_unsigned = ‰b",data_16bit_unsigned);
63 $display("data_32bit_unsigned = ‰b",data_32bit_unsigned);
64 $display("data_64bit_unsigned = ‰b",data_64bit_unsigned);
65 $display("data_integer_unsigned = ‰b",data_integer_unsigned);
66 #1 $finish;
67 end
68
69 endmodule
You could download file data_types.sv here

space.gif


../images/main/bullet_star_pink.gif Simulation Output - Integer Types

space.gif




 data_1bit    = 1
data_8bit = -1
data_16bit = -1
data_32bit = -1
data_64bit = -1
data_integer = -1
data_1bit = 1
data_8bit = 00010001
data_16bit = 0001000100010001
data_32bit = 00010001000100010001000100010001
data_64bit = 0001000100010001000100010001000100010001000100010001000100010001
data_integer = zx01zx01zx01zx01zx01zx01zx01zx01
data_1bit_unsigned = 1
data_8bit_unsigned = 255
data_16bit_unsigned = 65535
data_32bit_unsigned = 4294967295
data_64bit_unsigned = 18446744073709551615
data_integer_unsigned = 4294967295
data_1bit_unsigned = 1
data_8bit_unsigned = 00010001
data_16bit_unsigned = 0001000100010001
data_32bit_unsigned = 00010001000100010001000100010001
data_64bit_unsigned = 0001000100010001000100010001000100010001000100010001000100010001
data_integer_unsigned = zx01zx01zx01zx01zx01zx01zx01zx01

Labels:

2008-01-02

systemverilog tutorial(Ch2-new literal values)

New Literal Values

Introductions


SystemVerilog addes following new literal values to existing Verilog literals and improves some of the literals.

  • time values
  • array values
  • structure values
  • Improvements to string literals.

1.1 Integer and Logic Literals

Literals integer and logic values can be sized and unsized, and follow the same rules as of Verilog 2001. Assignment of constant values to any variable can be single literal as shown below.

  • '0 : Set all bits to 0
  • '1: Set all bits to 1
  • 'X or `x : Set all bits to x
  • `Z or `z : Set all bits to z

1.2 Example - Integer Literals

space.gif

1 `timescale 1ns/100ps

2 module int_literals ();

3

4 integer a;

5

6 initial begin

7 $monitor ("@ ‰gns a = ‰h", $time, a);

8 a = '0;

9 #1 a = 'x;

10 #1 a = '1;

11 #1 a = 'z;

12 #1 a = 'b0;

13 #1 a = 'bx;

14 #1 a = 'b1;

15 #1 a = 'bz;

16 #1 $finish;

17 end

18

19 endmodule

Simulator Output

space.gif

@ 0ns a = 00000000

@ 1ns a = xxxxxxxx

@ 2ns a = ffffffff

@ 3ns a = zzzzzzzz

@ 4ns a = 00000000

@ 5ns a = xxxxxxxx

@ 6ns a = 00000001

@ 7ns a = zzzzzzzz

2 Real Literals

The default type is real for fixed point format and exponent format. We can do type casting to covert from real values to shortreal type. Following are real literals examples.

  • 3.14
  • 2.0e16

Example - Real Literals

//------------------------------- Codes Start-------------------------------

1 `timescale 1ns/100ps

2 module real_literals ();

3

4 real a;

5 shortreal b;

6

7 initial begin

8 $monitor ("@ ‰gns a = ‰e b = ‰e ", $time, a, b);

9 a = '0;

10 b = 1.0e2;

11 #1 a = 2e5;

12 // Type casting

13 #1 b = shortreal'(a);

14 #1 a = 2.1E-2;

15 // Type casting

16 #1 b = shortreal'(a);

17 #1 $finish;

18 end

19

20 endmodule

//------------------------------- Codes END-------------------------------

Simulator Output

@ 0ns a = 0.000000e+00 b = 1.000000e+02

@ 1ns a = 2.000000e+05 b = 1.000000e+02

@ 2ns a = 2.000000e+05 b = 2.000000e+05

@ 3ns a = 2.100000e-02 b = 2.000000e+05

@ 4ns a = 2.100000e-02 b = 2.100000e-02

3 Time Literals

Time is written in integer or fixed point format, followed without a space by a time unit. The time literal is interpreted as a real time value scaled to the current time unit and rounded to the current time precision. Following are time literals examples.

  • 1ns
  • 1.4ps
  • 0.01ns

Example - Time Literals

 
  1 `timescale 100ps/10ps
  2 module time_literals ();
  3 
  4 time a;
  5 initial begin
  6   $monitor ("@ ‰g a = ‰t", $time, a);
  7    #1  a =  1ns;
  8    #1  a =  0.2ns;
  9    #1  a =  300ps;
 10    #1  $finish;
 11 end
 12 
 13 endmodule

Simulator Output

 @ 0 a =                    0
 @ 1 a =                  100
 @ 2 a =                   20
 @ 3 a =                   30
//where, the time unit is 10ps

4 String Literals

A string literal is enclosed in quotes and has its own data type. A string literal must be contained in a single line unless the new line is immediately preceded by a \. Non-printing and other special characters are preceded with a backslash. String literals can also be cast to a packed or unpacked array. SystemVerilog added following special string characters.

  • \v vertical tab
  • \f form feed
  • \a bell
  • \x02 hex number

Example - String Literals

  1 `timescale 1ns/100ps
  2 module string_literals ();
  3 
  4 string  a;
  5 
  6 initial begin
  7   $display ("@ ‰gns a = ‰s", $time, a);
  8   a = "Hello Deepak";
  9   $display ("@ ‰gns a = ‰s", $time, a);
 10    #1  a = "Over writing old string";
 11   $display ("@ ‰gns a = ‰s", $time, a);
 12    #1  a = "This is multi line comment \
" 13           and this is second line";
" 14   $display ("@ ‰gns a = ‰s", $time, a);
 15    #1  $finish;
 16 end
 17 
 18 endmodule

Simulator Output

space.gif

  @ 0ns a =
  @ 0ns a = Hello Deepak
  @ 1ns a = Over writing old string
  @ 2ns a = This is multi line comment
            and this is second line

5 Array literals

Array literals are syntactically similar to C initializers, but with the replicate operator ( {{}} ) allowed. The nesting of braces must follow the number of dimensions, unlike in C.

Example - Array Literals

space.gif

1 `timescale 1ns/100ps

2 module real_literals ();

3

4 byte a [0:1][0:2] = {{0,1,2},{3{9}}};

5

6 initial begin

7 $display ("a [0][0] = ‰d", a[0][0]);

8 $display ("a [0][1] = ‰d", a[0][1]);

9 $display ("a [0][2] = ‰d", a[0][2]);

10 $display ("a [1][0] = ‰d", a[1][0]);

11 $display ("a [1][1] = ‰d", a[1][1]);

12 $display ("a [1][2] = ‰d", a[1][2]);

13 #1 $finish;

14 end

15

16 endmodule

Simulator Output

a [0][0] = 0

a [0][1] = 1

a [0][2] = 2

a [1][0] = 9

a [1][1] = 9

a [1][2] = 9

6 Structure Literals

Structure literals are syntactically similar to C initializers. Structure literals must have a type, either from context or a cast. When an array of structures is initialized, the nested braces should reflect the array and the structure.

Example - Struct Literals

1 `timescale 1ns/100ps

2 // Type define a struct

3 typedef struct {

4 byte a;

5 reg b;

6 shortint unsigned c;

7 } myStruct;

8

9 module struct_literals ();

10

11 myStruct object = {10,0,100};

12

13 myStruct objectArray [0:1] = {{10,0,100},{11,1,101}};

14

15 initial begin

16 $display ("a = ‰b b = ‰b c = ‰h", object.a, object.b, object.c);

17 object.a = 15;

18 $display ("a = ‰b b = ‰b c = ‰h", object.a, object.b, object.c);

19 object.c = 16'hDEAD;

20 $display ("a = ‰b b = ‰b c = ‰h", object.a, object.b, object.c);

21 $display ("Printing array of objects");

22 $display ("a = ‰b b = ‰b c = ‰h",

23 objectArray[0].a, objectArray[0].b, objectArray[0].c);

24 $display ("a = ‰b b = ‰b c = ‰h",

25 objectArray[1].a, objectArray[1].b, objectArray[1].c);

26 #1 $finish;

27 end

28

29 endmodule

Simulator Output

a = 00001010 b = 0 c = 0064

a = 00001111 b = 0 c = 0064

a = 00001111 b = 0 c = dead

Printing array of objects

a = 00001010 b = 0 c = 0064

a = 00001011 b = 1 c = 0065

Labels:

2007-12-31

Systemverilog Tutorial(Ch1-intorduction)

Today is the first day of 2008!

Happy New Year For Everyone!

Now Let us make a closed study on the systemverilog.

Several days ago, I came acrossed a book called "Systemverilog Assertion". The preface of the book intrigues my interest on Systemverilog that may be the next generation hardware description language. It is reported that the systemverilog has fixed its roots steadily in EDA field such as system design and verifications of ASIC/IC design.

So it is necessary for us to make a acquaintance with it. Now I have googled many resources about it and sort them as follows step by step! Just follow me! Be patient and systemverilog world is coming.

The following chapter is about the introductions of systemverilog.


../images/main/bullet_green_ball.gif Introduction


Verilog 1995 version has been in market for a very long time. IEEE extended the features of Verilog 1995 and released it as Verilog 2001. But this was no good for verification engineers, so verifcation engineers had to use languages like "e", VERA, Testbuider. It was rather painfull to have two language, one for design and other for verification. SystemVerilog combines the Verification capabilties of HVL (Hardware Verification Language) with ease of Verilog to provide a single platform for both design and verification.

space.gif



Some of the new features in SystemVerilog are as listed below.

space.gif



  • C type data types like int, typedef, struct, union, enum.
  • Dynamic data types : struct, classes, dynamic queues, dynamic arrays.
  • New operators and built in methods.
  • Enhanced flow control like, foreach, return, break, continue.
  • Semaphores, mailboxes, event extensions.
  • classes for object oriented programming.
  • Assertions.
  • Coverage.
  • VPI extensions.

space.gif



Now IEEE has accepted the SystemVerilog, and it is called 1800-2005 standard.

space.gif



Anyone with background of C++, or OO programming language will feel at home with SystemVerilog. But on other hand if you have been thinking C or C++ is not required, then you may be shocked to know that SystemVerilog is very much like C++.

Labels: