Re: [sv-ec] rand in struct with union members

From: Steven Sharp <sharp_at_.....>
Date: Fri Sep 04 2009 - 14:20:48 PDT
>From: "Daniel Mlynek" <daniel.mlynek@aldec.com>

>LRM:"Members of unpacked structures containing a union as well as members of
>packed structures shall not be allowed to have a random modifier."
>
>Why does the LRM forbids to have "rand" on  structs  containing an union?
>What was the motivation for this restriction?

I don't remember anything about this restriction, and may not have been
involved.  However, I can make deductions about what was intended.

The wording of this restriction in 8.4 closely matches the restriction in
7.2.2:

"Members of unpacked structures containing a union as well as members of
packed structures shall not be assigned individual default member values."

I assume that the wording in 8.4 was borrowed from 7.2.2.

The issue here is presumably that it is unclear which member of the
union is supposed to be assigned the value.  And for a member of a
packed struct, it may be unclear how to handle the conflict between the
overall initialization of the struct as an integral value, and the
initialization of the member.  A packed struct is effectively a union
between the separate members and the vector value that the entire struct
represents.

The text in 7.2.2 refers to unions that are members of unpacked structs
because it is only members of unpacked structs that can have default
values like this.  So there is no need to say it about unions in general.

Similarly, the text about rand in 18.4 comes immediately after a reference
to rand qualifiers on members of unpacked structs.

Allowing a rand qualifier on a union would be a problem, since it would be
unclear which member of the union should be assigned the random value.  So
why does this only mention unions that are members of unpacked structs?  It
appears that this is because other unions have already been excluded.  8.4
lists everything you can qualify with rand, and it does not list unions.
But when it says it is allowed for a member of an unpacked struct, that seems
to allow a loophole, since that member could be a union.  So this text is
saying that a union still isn't allowed.

It would have been more general if it had said that a struct member could
be made rand, as long as that member was itself of a type that could be made
rand.


>Does above forbids the code:
>
>typedef union packed { reg a; bit b;} TU;
>
>typededef struct {
>
>    rand int a;//illegal as this struct has  union inside

This is fine, as the member does not contain a union.

>    rand TU v; //illegal

This is illegal, as the member contains a union.  It isn't a major issue
in this simple case, but one can imagine cases where it would be.  For
example, what if it were a union between an enum and an int?  Which member
of the union should be randomized?  If it is the enum, then I assume it is
restricted to the defined literals of the enum.  If it is the int, then it
could be any value in its range.  These give different results.  It could
have been defined to randomize the first (or last) member of the union,
but instead it was made illegal.


Steven Sharp
sharp@cadence.com


-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
Received on Fri Sep 4 14:23:25 2009

This archive was generated by hypermail 2.1.8 : Fri Sep 04 2009 - 14:24:22 PDT