Re: Packed struct/union amendments proposal


Subject: Re: Packed struct/union amendments proposal
From: Kevin Cameron x3251 (Kevin.Cameron@nsc.com)
Date: Tue Aug 06 2002 - 13:13:48 PDT


Peter Flake wrote:

> 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;
> byte [3:0] byte_slice;
> bytes slice;
> int b32;
> } mem_word;
>
> mem_word a = 32'h12345678;
> $displayh(a.slice.byte1); // gives 12

Solaris & Linux I presume?

That's fine, but I don't think it spells it out in the LRM.

Kev.

--
National Semiconductor
2900 Semiconductor Drive, Mail Stop A1-520, Santa Clara, CA 95052-8090



This archive was generated by hypermail 2b28 : Tue Aug 06 2002 - 13:15:51 PDT