Subject: [sv-bc] Proposal to add unchecked next() and prev() methods to enum types
From: Evan Rosser (Evan.Rosser@synopsys.com)
Date: Sun Mar 16 2003 - 17:07:15 PST
Hello SV-BC memebers,
Sorry for the previous empty email.
Here is the second proposal I mentioned, to add some new functionality
to enum types. This would introduce unchecked next() and prev()
methods, which would allow more-efficient implementations that would
not require a return to the initial element if an out of range value
is seen. By using these methods, the user would take responsibility
for ensuring that the given enum variable has a value in the valid set.
Comments and suggestions are welcome.
Evan Rosser
Staff R&D Engineer, HDL Compiler
Synopsys, Inc.
Proposal to add unchecked versions of next() and prev() methods on enum
varibles, and add a method valid()
The implicit check for validity in the current definition of next()
and prev() can be expensive both in simulation or synthesis. This
change proposes adding unchecked versions of these functions, and
supplying the user with the ability to check the validity.
Note: The valid() method is not my own idea; I saw a mention of it on
the email list, but couldn't any other references to it. Since it's
useful to have it for the unchecked versions of next and prev(), I
included a version of it here, in case it's not otherwise on a path to
be part of the standard.
1. ADD a section between 3.11.5.2 and 3.11.5.3:
3.11.5.3 valid()
The syntax for the valid() method is:
function bit valid();
The valid() method returns 1'b1 if the given enum variable
contains a value in the set of enumeration values of the type,
and 1'b0 otherwise.
2. ADD two sections after the current 3.11.5.4 "prev()":
3.11.5.5 next_unchecked()
The syntax for the next_unchecked() method is:
function enum next_unchecked( unsigned int N = 1 );
If the given enum variable contains a value in the set of
enumeration values of the type, the next_unchecked() method
returns the Nth next enumeration value starting from the
current value. A wrap around to the start of the enumeration
occurs when the end of the enumeration is reached. If the given
value is not a member of the enumeration, the result of
next_unchecked() is undefined.
3.11.5.6 prev_unchecked()
The syntax for the prev_unchecked() method is:
function enum prev_unchecked( unsigned int N = 1 );
If the given enum variable contains a value in the set of
enumeration values of the type, the prev_unchecked() method
returns the Nth previous enumeration value starting from the
current value. A wrap around to the end of the enumeration
occurs when the start of the enumeration is reached.
If the given value is not a member of the enumeration,
the result of prev_unchecked() is undefined.
Alternate proposal
Another alternative would be to add an additional parameter to next()
and prev() to request or decline checking. I saw a discussion of
cast_assign that included an optional CHECK parameter, but didn't find
the formal definition. This would be analogous.
Another alternative would be to remove the implicit checking from the
next() and prev() methods and define them as next_unchecked() and
prev_unchecked() are defined above. While that would make the
functions more efficient, it would place a burden on the user to check
validity.
Comments and suggestions are welcome.
Evan Rosser
This archive was generated by hypermail 2b28 : Sun Mar 16 2003 - 17:08:21 PST