Re: Packed struct/union amendments proposal


Subject: Re: Packed struct/union amendments proposal
From: Peter Flake (flake@co-design.com)
Date: Mon Aug 05 2002 - 06:10:20 PDT


Hi Kevin,

I have tested your example.

Peter.

At 07:08 PM 7/22/02 -0700, Kevin Cameron x3251 wrote:
> > If I define
> >
> > typedef struct packed {
> > byte byte1;
> > byte byte2;
> > byte byte3;
> > byte byte4;
> > } bytes;
> >
> > typedef union packed {
> > bit [31:0] word;
> > byte [3:0] byte_slice;
> > bytes slice;
> > } mem_word;
> >
> > then byte[3] and slice.byte1 correspond to word[31:24], because those are
> > all the most significant in each member. And byte[0] and slice.byte4
> > correspond to word[7:0], because those are all the least significant in
> > each member. So it is well defined how they overlay and how access to the
> > different fields will work within SystemVerilog. This may be sufficient
> > for what you want, and is the point I was trying to stress during the
> > meeting.
> >
> > The only thing that is not defined is exactly how this is stored in memory.
> > That is only visible if you have another way of accessing the storage aside
> > from HDL constructs. For example, if you can access the data structure
> > directly from C code.
>
>If we modify the union:
>
> typedef union packed {
> bit [31:0] word;
> byte [3:0] byte_slice;
> bytes slice;
> int b32;
> } mem_word;
>
>and then do:
>
> mem_word.b32 = 32h'12345678;
>
>what's the value of slice.byte1?

typedef struct packed {
   byte byte1, byte2, byte3, byte4;
   } bytes;

typedef byte byt; // cannot have a packed array of integer etc. - backwards
compatibility

typedef union packed {
   bit [31:0] word;
   byt [3:0] byte_slice;
   bytes slice;
   int b32;
   } mem_word;

mem_word a = 32'h12345678;
$displayh(a.slice.byte1); // gives 12



This archive was generated by hypermail 2b28 : Mon Aug 05 2002 - 08:01:37 PDT