Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use real_type_t as the data type for real type signals #681

Merged
merged 4 commits into from
Apr 14, 2022

Conversation

larsclausen
Copy link
Collaborator

Currently a vector_type_t with the base type set to IVL_VT_REAL is used as
the data type for real type signals. But there is also the real_type_t data
type, which is used as the data type for function return types and class
properties.

Move signals also over to using real_type_t. This ensures consistent
behavior between all sorts of constructs with a data type, makes sure that
vector_type_t is only used for vector types.

It also allows to eventually differentiate between real and shortreal
at the elaboration stage. Currently this information is discarded by the
parser.

As a side effect this PR also fixes the rather obscure case of passing a call
to a function with a real return type as the argument to the Verilog AMS
abs() function.

Currently only the netvector_t type implements the get_scalar() method. To
check whether a type is scalar it is first cast to netvector_t and then the
method is called.

But there are other types, such as areal that can also be scalar. To
support indicating that a real type is scalar add a virtual get_scalar()
method to ivl_type_s, which is the base class for all types.

Signed-off-by: Lars-Peter Clausen <[email protected]>
reals are both signed and scalar. But the real_type_t currently reports as
neither.

This isn't much of a problem because most real signals are implemented
using netvector_t with the base type set to IVL_VT_REAL, for which the
signedness is correctly reported. Function return values and class
properties use the netreal_t as their data type, but most places that work
with reals check the base type and assume that the value is signed when the
base type is real.

The only place where this really makes a difference at the moment is the
Verilog-AMS function when being passed a function call as its argument. In
that case the `abs()` function will be optimized away and a negative value
will be passed through as negative.

But going forward netreal_t is also going to be used for the data type of
real type signals.

To fix the `abs()` issue and to be ready  to switch real signals over to
using netreal_t as their type implement the appropriate methods on
netreal_t.

Signed-off-by: Lars-Peter Clausen <[email protected]>
Currently a `vector_type_t` with the base type set to `IVL_VT_REAL` is used as
the data type for real type signals. But there is also the `real_type_t` data
type, which is used as the data type for function return types and class
properties.

Move signals also over to using `real_type_t`. This ensures consistent
behavior between all sorts of constructs with a data type, makes sure that
`vector_type_t` is only used for vector types.

It also allows to eventually differentiate between `real` and `shortreal`
at the elaboration stage. Currently this information is discarded by the
parser.

Signed-off-by: Lars-Peter Clausen <[email protected]>
Check that the behavior of the Verilog AMS `abs()` function is correct when
its argument is a function call. Check this for both vector as well as real
types.

This test is largely a copy of the existing vams_abs2 test, just replacing
the identifier argument with a function call argument.

Signed-off-by: Lars-Peter Clausen <[email protected]>
@larsclausen larsclausen changed the title Use real_type_t as the data type for real type signals Use real_type_t as the data type for real type signals Apr 12, 2022
@steveicarus steveicarus merged commit 752a285 into steveicarus:master Apr 14, 2022
@larsclausen larsclausen deleted the signal-real-type branch April 14, 2022 05:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants