You are on page 1of 2

always_comb compared to always @*

 always_comb automatically  always @* waits until a

executes once at time zero, change occurs on a signal in the
 always_comb is sensitive to inferred sensitivity list
changes within the contents of a  always @* is only sensitive
function, to changes to the arguments of a
 always_comb is sensitive to function.
expressions in immediate  always @* is sensitive to
assertions within the procedure expressions in immediate
and within the contents of a assertions within the procedure
function called in the procedure only.
 Variables on the left-hand side of  always @* permits multiple
assignments within an processes to write to the same
always_comb procedure, variable.
including variables from the  always @* is sensitive to
contents of a called function, shall expressions in immediate
not be written to by any other assertions within the procedure
processes only.
 always_comb is sensitive to
expressions in immediate
assertions within the procedure Example 1:
and within the contents of a always @(*) // equivalent
function called in the procedure, to @(a or b or c or d or
Eg. f)
always_comb y = (a & b) | (c & d) |
a = b & c; myfunction(f);
always_comb Example 2:
d <= #1ns b & c; always @* begin //
equivalent to @(a or b or
c or d or tmp1 or tmp2)
tmp1 = a & b;
tmp2 = c & d;
y = tmp1 | tmp2;
Example 3:
always @* begin //
equivalent to @(b)
@(i) kid = b; // i is not
added to @*

 A structure represents a collection of data types that can be referenced as a whole, or
the individual data types that make up the structure can be referenced by name.
 By default, structures are unpacked. Unpacked structures can contain any data type.
Structure declarations follow the C syntax, but without the optional structure tags before the “{”. The syntax
for structure declarations is

struct { bit [7:0] opcode; bit [23:0] addr; }IR; // anonymous structure
// defines variable IR
IR.opcode = 1; // set field in IR.

typedef struct {
bit [7:0] opcode;
bit [23:0] addr;
} instruction; // named structure type
instruction IR; // define variable

 A union is a data type that represents a single piece of storage that can be accessed using one of the
named member data types. Only one of the data types in the union can be used at a time.
 By default, a union is unpacked, meaning there is no required representation for how members of the
union are stored.
 Dynamic types and chandle types can only be used in tagged unions

typedef union { int i; shortreal f; } num; // named union type
num n;
n.f = 0.0; // set n in floating point format
typedef struct {
bit isfloat;
union { int i; shortreal f; } n; // anonymous union type
} tagged_st; // named structure

Packed and unpacked arrays

 The term packed array is used to refer to the dimensions declared before the data identifier name.
 The term unpacked array is used to refer to the dimensions declared after the data identifier name.

bit [7:0] c1; // packed array of scalar bit types

real u [7:0]; // unpacked array of real types

Packed arrays

 A packed array is a mechanism for subdividing a vector into subfields, which can be conveniently
accessed as array elements.
 packed array is guaranteed to be represented as a contiguous set of bits. An unpacked array may or may
not be so represented

byte c2; // same as bit signed [7:0] c2;

integer i1; // same as logic signed [31:0] i1;

Unpacked arrays
 Unpacked arrays can be made of any data type.
 Arrays whose elements are themselves arrays are declared as multidimensional arrays

int Array[0:7][0:31]; // array declaration using ranges

int Array[8][32]; // array declaration using sizes