Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Doubt in system verilog

Status
Not open for further replies.

deepu_s_s

Full Member level 5
Joined
Mar 24, 2007
Messages
305
Helped
15
Reputation
30
Reaction score
5
Trophy points
1,298
Activity points
3,021
Hi friends,

I didnt understand the concept of Unions in SV. Pls tell me any1 how unions are useful in system verilog. what are the difference between unions and structures? what are tagged unions.

and also what is the difference between packed structures and unpacked structures.


Thanks and regards
Deepak
 

i CAN HELP U WITH DIFFERENCE OF UNION AND STRUCTURE:




wHEN U DECLARE VARIABLES IN A UNION ,THE MEMORY ALLOCATED TO A UNION IS OF THE SIZE OF MAXIMUM SIZE OF THE VARIABLE IN THE UNION AND NOT THE SUM OF THE SIZES OF VARIABLES....

Wheras in structure,the total memory allocated is the sum of the sizes of the variables....

Suppose u declare three variables of 2byte, 4byte ,and 8byte in union the memory allocated to union is of 8byte


u declare three variables of 2byte, 4byte ,and 8byte in Structure the memory allocated to structure is of 14byte.....
 

hi nan,
suppose i declared 3 variables of different sizes..
var1 or 2 bytes
var2 of 4 bytes
var3 of 8 bytes.
According to above answer, are values of var1 and var2 are lost ?
 

Hi,
1st about unions.....

suppose

a. Unpacked Union --->

module top();
typedef union {int a; bit b;} union1;
union1 a;

initial
begin
a.x = 1; // at time=0 x=1 and b=1
#2 a.x = 2; // at time=2 x=2 and b=0 because b points at x[0]
end

b. Packed Union --->
all the elements have to be of the same width or you will get an error :
#Packed union fields must all be the same width
 

1.Unions when declared as packed are synthesizable and unpacked are not
synthesizble.

2. Packed Unions memory allocation is contiguous bits where as unpacked does
not have any order of memory allocation of there variables
3. Packed Unions allows part select and bit select where as unpacked doesn't
 

union share the memory space while the struct has independant memory!
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top