Re: [sv-bc] enumeration types

From: Greg Jaxon <Greg.Jaxon@synopsys.com>
Date: Thu Dec 09 2004 - 16:39:18 PST

Our interest in the type safety of reals is different from
that of enums. With reals we are protecting the design from
overt dependence on the real number layout of the simulation
host (or the synthesis engine, if it supports reals). This
is not a feature over which the designer has direct control.

Enums are entirely in the designer's control. They can
serve a design phase where the enum remains abstract -
where it makes sense to warn when the design depends on the
implementation of an abstract type. However, good designs
eventually become concrete. SV needs to serve the needs
of bit twiddlers too.

We know that in integral contexts, an enum reverts to its base
type. So the only semantic question is whether the assignment
back into the enum variable should be legal (the reference is
certainly legal). SV does not (yet) have syntax for a cast
on the lhs of an assignment. Like the cast to the enum
base type, the cast back into the enum type is implicit.
And like implicit truncations, it is unsafe. It merits a
warning in modes where truncation on assignment would issue
a warning, but we can probably leave that up to the tool
vendors.

     There are already loopholes in enum type safety.
If my_enum = 42 is a type error, the designer who wants to
do it anyway is going to write either my_enum = my_enum_t'(42)
or else write my_enum[31:0] = 42. I'd prefer the first,
but it requires the user to have read the manual, so we should
expect to see the second form. And a rational user will be grateful
for the warning message. Rational language designers do not
deliver handicapped semantics.

Greg Jaxon

Brad Pierce wrote:
> According to
>
> http://www.boyd.com/1364_btf/report/full_pr/261.html
>
> "A bit-select or part-select of a scalar, or of a variable
> declared as real or realtime, shall be illegal."
>
> -- Brad
>
> -----Original Message-----
> From: owner-sv-bc@eda.org [mailto:owner-sv-bc@eda.org]On Behalf Of Maidment,
> Matthew R
> Sent: Thursday, December 09, 2004 3:42 PM
> To: Francoise Martinolle; sv-bc@eda.org
> Subject: RE: [sv-bc] enumeration types
>
>
> I agree with your conclusions. It should not be legal to
> index into an enum if the base type is a scalar.
>
> Practically speaking, my experience is that various simulators
> consider it a "feature" to enable reference to a scalar with the index [0].
> Not all tools allow it and it's not in the standard AFAICT.
>
> Matt
>
>
>
>
> From: owner-sv-bc@eda.org [mailto:owner-sv-bc@eda.org] On Behalf Of
> Francoise Martinolle
> Sent: Thursday, December 09, 2004 1:50 PM
> To: sv-bc@eda.org
> Subject: [sv-bc] enumeration types
>
>
> I think that the following is legal:
> typedef enum bit {bit0, bit1} mybit;
>
> But can I use a bit select of a variable of that type when the base type of
> the enum is just bit or logic or alias
> thereof?
>
> mybit v;
>
> initial v[0] = 1'b0;
>
>
> I think that if I define:
> typedef enum bit[0:0] {bit0, bit1} mybitvec;
>
> v[0] is legal.
>
> Francoise
> '
>
>
Received on Thu Dec 9 16:39:23 2004

This archive was generated by hypermail 2.1.8 : Thu Dec 09 2004 - 16:39:27 PST