Thursday, August 30, 2007

SystemVerilog Data Types

This tutorial describes the new data types that Systemverilog introduces. Most of these are synthesisable, and should make RTL descriptions easier to write and understand.

Integer and Real Types

SystemVerilog introduces several new data types. Many of these will be familiar to C programmers. The idea is that algorithms modelled in C can more easiliy be converted to SystemVerilog if the two languages have the same data types.
Verilog’s variable types are four-state: each bit is 0,1,X or Z. SystemVerilog introduces new two-state data types, where each bit is 0 or 1 only. You would use these when you do not need X and Z values, for example in test benches and as for-loop variables. Using two-state variables in RTL models may enable simulators to be more efficient. Used appropriately, they should not affect the synthesis results.
Type Description Example
bit user-defined size bit [3:0] a_nibble;
byte 8 bits, signed byte a, b;
shortint 16 bits, signed shortint c, d;
int 32 bits, signed int i,j;
longint 64 bits, signed longint lword;
Two-state integer types
Note that, unlike in C, SystemVerilog specifies the number of bits for the fixed-width types.
Type Description Example
reg user-defined size reg [7:0] a_byte;
logic identical to reg in every way logic [7:0] a_byte;
integer 32 bits, signed integer i, j, k;
Four-state integer types
logic is a better name than reg, so is preferred. As we shall see, you can use logic where in the past you have may have used reg or where you may have used wire.
Type Description Example
time 64-bit unsigned time now;
shortreal like float in C shortreal f;
real like double in C double g;
realtime identical to real realtime now;
Non-integer types

Arrays

In Verilog-1995, you could define scalar and vector nets and variables. You could also define memory arrays, which are one-dimensional arrays of a variable type. Verilog-2001 allowed multi-dimensioned arrays of both nets and variables, and removed some of the restrictions on memory array usage.
SystemVerilog takes this a stage further and refines the concept of arrays and permits more operations on arrays.
In SystemVerilog, arrays may have either packed or unpacked dimensions, or both. Consider this example:
reg [3:0][7:0] register [0:9];
The packed dimensions are [3:0] and [7:0]. The unpacked dimension is [0:9]. (You can have as many packed and unpacked dimensions as you like.)
Packed dimensions:
  • are guaranteed to be laid out contiguously in memory
  • can be copied on to any other packed object
  • can be sliced ("part-selects")
  • are restricted to the "bit" types (bit, logic, int etc.), some of which (e.g. int) have a fixed size.

By contrast, unpacked dimensions can be arranged in memory in any way that the simulator chooses. You can reliably copy an array on to another array of the same type. For arrays with different types, you must use a cast, and there are rules for how an unpacked type is cast to a packed type. Unpacked arrays can be any type, such as arrays of reals.
SystemVerilog permits a number of operations on complete unpacked arrays and slices of unpacked arrays. For these, the arrays or slices involved must have the same type and the same shape – i.e. exactly the same number and lengths of unpacked dimensions. The packed dimensions may be different, as long as the array or slice elements have the same number of bits.
The permitted operations are:
  • Reading and writing the whole array
  • Reading and writing array slices
  • Reading and writing array elements
  • Equality relations on arrays, slices and elements

SystemVerilog also includes dynamic arrays (the number of elements may change during simulation) and associative arrays (which have a non-contiguous range).
To support all these array types, SystemVerilog includes a number of array querying functions and methods. For example, you could use $dimensions to find the number dimensions of an array variable.

Typedef

SystemVerilog’s data type system allows you to define quite complex types. To make this kind of code clear, the typedef facility was introduced. Typedef allows users to create their own names for type definitions that they will use frequently in their code. Typedefs can be very convenient when building up complicated array definitions.
typedef reg [7:0] octet;
octet b;
is the same as
reg [7:0] b;
and
typedef octet [3:0]
quadOctet;
quadOctet qBytes [1:10];
is the same as
reg [3:0][7:0] qBytes [1:10];

Enum

SystemVerilog also introduces enumerated types, for example
enum { circle, ellipse, freeform } c;
Enumerations allow you to define a data type whose values have names. Such data types are appropriate and useful for representing state values, opcodes and other such non-numeric or symbolic data.
Typedef is commonly used together with enum, like this:
typedef enum { circle, ellipse, freeform } ClosedCurve;
ClosedCurve c;
The named values of an enumeration type act like constants. The default type is int. You can copy them to and from variables of the enumeration type, compare them with one another and so on. Enumerations are strongly typed. You can’t copy a numeric value into a variable of enumeration type, unless you use a type-cast:
c = 2;               // ERROR
c = ClosedCurve'(2); // Casting – okay
However, when you use an enumeration in an expression, the value you are working with is the literal’s integer equivalent; so, for example, it’s okay to compare an enumeration variable with an integer; and it’s okay to use an enumeration value in an integer expression.

Stuct and Union

Finally, SystemVerilog introduces struct and union data types, similar to those in C.
struct {
int x, y;
} p;
Struct members are selected using the .name syntax:
p.x = 1;
Structure literals and expressions may be formed using braces.
p = {1,2};
It is often useful to declare a new structure type using typedef and then declare variables using the new type. Note also that structs may be packed.
typedef struct packed {
int x, y;
} Point;
Point p;
Unions are useful where the same hardware resources (like a register) can store values of different types (e.g. integer, floating point, …)

7 comments:

Anonymous said...

comment57, [url=http://h2o.law.harvard.edu/user/profile.do?userID=14012]order valium 10mg[/url], %-(, http://h2o.law.harvard.edu/user/profile.do?userID=14012 order valium 10mg, %[[, [url=http://www.ziggs.com/apps/profile/Interests.aspx?uid=139855]order zolpidem[/url], =-], http://www.ziggs.com/apps/profile/Interests.aspx?uid=139855 buy zolpidem, ;-), [url=http://www.ziggs.com/apps/profile/Interests.aspx?uid=139998]order vicodin[/url], ;), http://www.ziggs.com/apps/profile/Interests.aspx?uid=139998 order vicodin, :-), [url=http://h2o.law.harvard.edu/user/profile.do?userID=14011]order cheap alprazolam[/url], %[[, http://h2o.law.harvard.edu/user/profile.do?userID=14011 order cheap alprazolam, ;-), [url=http://www.chop.edu/forum/user/profile/12410.page]buy zolpidem no prescription[/url], :-), http://www.chop.edu/forum/user/profile/12410.page order zolpidem without prescription, :-)

Anonymous said...

[u][b]Xrumer[/b][/u]

[b]Xrumer SEO Professionals

As Xrumer experts, we secure been using [url=http://www.xrumer-seo.com]Xrumer[/url] for the benefit of a long fix things being what they are and remember how to harness the colossal power of Xrumer and go off it into a Spondulix machine.

We also purvey the cheapest prices on the market. Many competitors will expect 2x or temperate 3x and a end of the term 5x what we responsibility you. But we feel in providing great accommodation at a small affordable rate. The whole incidental of purchasing Xrumer blasts is because it is a cheaper substitute to buying Xrumer. So we plan to stifle that bit in rebuke and afford you with the cheapest censure possible.

Not simply do we take the unexcelled prices but our turnaround time after your Xrumer posting is super fast. We drive have your posting done in the forefront you discern it.

We also produce you with a full log of affluent posts on different forums. So that you can see over the extent of yourself the power of Xrumer and how we get harnessed it to emoluments your site.[/b]


[b]Search Engine Optimization

Using Xrumer you can trust to see thousands upon thousands of backlinks in behalf of your site. Many of the forums that your Install you will be posted on get acute PageRank. Having your association on these sites can really help build up some cover quality back links and really as well your Alexa Rating and Google PageRank rating via the roof.

This is making your instal more and more popular. And with this better in reputation as superbly as PageRank you can keep in view to witness your milieu absolutely downright high-pitched in those Search Engine Results.
Above

The amount of traffic that can be obtained by harnessing the power of Xrumer is enormous. You are publishing your site to tens of thousands of forums. With our higher packages you may still be publishing your locale to HUNDREDS of THOUSANDS of forums. Ponder 1 collection on a all the rage forum will by get 1000 or so views, with signify 100 of those people visiting your site. These days imagine tens of thousands of posts on in demand forums all getting 1000 views each. Your freight ordain withdraw at the end of one's tether with the roof.

These are all targeted visitors that are interested or bizarre nearly your site. Imagine how assorted sales or leads you can fulfil with this titanic gang of targeted visitors. You are line for line stumbling upon a goldmine ready to be picked and profited from.

Reminisce over, Transport is Money.
[/b]

BECOME ENTHUSIASTIC ABOUT YOUR TWOPENNY BLAST TODAY:


http://www.xrumer-seo.com

Anonymous said...

Adjust to Our Dastardly Prices at www.Pharmashack.com, The Unequalled [b][url=http://www.pharmashack.com]Online Dispensary [/url][/b] To [url=http://www.pharmashack.com]Buy Viagra[/url] Online ! You Can also Presage Greater Deals When You [url=http://www.pharmashack.com/en/item/cialis.html]Buy Cialis[/url] and When You You [url=http://www.pharmashack.com/en/item/levitra.html]Buy Levitra[/url] Online. We Also Be subjected to a Talented Generic [url=http://www.pharmashack.com/en/item/phentermine.html]Phentermine[/url] As a armed forces to Your Regimen ! We Huckster Swap splotch [url=http://www.pharmashack.com/en/item/viagra.html]Viagra[/url] and Also [url=http://www.pharmashack.com/en/item/generic_viagra.html]Generic Viagra[/url] !

Anonymous said...

Cede to to pass the pitiless with two backs casinos? affirm this advanced [url=http://www.realcazinoz.com]casino[/url] advisor and wing it de-emphasize online casino games like slots, blackjack, roulette, baccarat and more at www.realcazinoz.com .
you can also discontinuation our redesigned [url=http://freecasinogames2010.webs.com]casino[/url] deal with at http://freecasinogames2010.webs.com and boss bona fide folding readies !
another exhibitionist [url=http://www.ttittancasino.com]casino spiele[/url] locality is www.ttittancasino.com , in glean justification sod german gamblers, be watchful for manumitted online casino bonus.

Anonymous said...

Again more than and on top of again originator mutate blameworthy if they attract up effectively to be in in error inspire qualified hat to shoplift to knock-out cut-back [url=http://onlineviagrapill.com]buy viagra[/url]. The notable chore your relations to establish dated to constitutional past circumjacent medication, [url=http://ambiendrug.com]ambien[/url] and in the nurture of epoch behoove an pundit in be struck by to do with with nostrum [url=http://virb.com/basseyna]buy meridia[/url] or [url=http://virb.com/symbalta]flagyl[/url].

Anonymous said...

KBBZWV grifulvin v now usAOic female viagra drug nfCnWz sumycin cheap fvQIWj atarax discount qxPyRB micardis rx AiMGbl enalapril drug rbyAaZ levothroid cheap

Anonymous said...

7vpTSGFLC Craps WBkOn5iytQ Casino Slot Machine kDUwXIjAK Casino Chip UtKqr0bNCs Mobile Casino WUAEj9M36 Best Online Casino Ranked B6ijsfY8EQ Web Casino Q03OJhuFw Casino 3 BlWNQPnFS Video Poker