[sv-bc] size of enums

From: Paul Graham <pgraham@cadence.com>
Date: Fri Oct 29 2004 - 11:34:31 PDT

SV defines that an enum's type defaults to int unless an explicit
type declaration is given. So:

    typedef enum {false, true} boolean;

is really a synonym for int. For synthesis this means that each
boolean variable will generate 32 wires. The intent seems to be to
force the user to explicitly size the enum type if he wants it to have
minimal width. But this is troublesome:

    typedef enum logic [3:0] { red, orange, ..., mauve, pink, .... } colors;

Adding new enum values will cause the type to overflow the bounds.
Yet it's easy to set the bounds to be wider than necessary. The user
has to count the enums, or play a game with the tool to find the minimum
width that doesn't trigger an overflow error.

Enums in vhdl are easier to use. If you declare;

    type colors is (red, orange, ...);

then a synthesis tool can compute the minimum bitwidth by itself. This
strikes me as being more maintainable and less error-prone than the SV
approach.

So what is the rationale for defaulting to type int for enums?

Paul
Received on Fri Oct 29 11:34:34 2004

This archive was generated by hypermail 2.1.8 : Fri Oct 29 2004 - 11:34:41 PDT