RE: [sv-bc] default initial value issues

From: Mark Hartoog <Mark.Hartoog@synopsys.com>
Date: Wed Nov 03 2004 - 14:28:03 PST

> Issue 286 also interacts with issue 216, on initializing
> 4-state enums to X.

There have been two views of what enums should be in System Verilog.

One view is that enums should be strongly typed and that the language
should guarantee that an enum variable will never have a value that is
not one of the enum labels. This is close the VHDL view of enums.

The other view is that enums are just a way of labeling the
values of some variable and of declaring variables that generally
should hold a value assigned to one of the labels, but no guarantees
and the user can do whatever they want.

Note that even with enums defined to be very strongly typed in the
language, it is possible to achieve the second view also. For example,

typedef enum logic [1:0] {A, B, C, D} ET;

logic [1:0] myvar;

always @(....)
    myvar = A;

Here the variable is not declared of the enum type, and will initialize
to 'x', but the user is still free to assign the enum labels to it.

The second view above was how enums were specified in System Verilog 3.0.
In 3.1 an effort was made to shift the standard to the first view,
but it didn't really make it. Enums became more strongly typed and
the initialization to the first label rule was added, but there were
several ways (casts and unions) left to introduce values that were
not one of the labels.

The advantage of the first view is suppose to be that synthesis can
do some additional optimizations with enums because it knows the enum
can only take on one of the label values, but with the backdoors in
the language this is basically lost.

The only advantage I see for the strongly typed with backdoors approach
we have now is that it provides some checking that you are using the
correct labels with each variable, while providing backdoors to get
around this when you need to.

I don't see where the initialization to the first label is really doing
anything for the language unless we close all the backdoors too.

If we want to change the initialization of 4 state enums, then I would
be strongly opposed to making the initialization of 4 state enums different
then 2 state enums. All enums should initialize in the same way. This means
either first label or the default initial value for the base type ('x' for
4 state and '0' for 2 state).

Mark Hartoog
700 E. Middlefield Road
Mountain View, CA 94043
650 584-5404
markh@synopsys.com

 
Received on Wed Nov 3 14:27:31 2004

This archive was generated by hypermail 2.1.8 : Wed Nov 03 2004 - 14:27:53 PST