Commit Graph

105 Commits

Author SHA1 Message Date
Cary R 5a4cb616d1 Fix and cleanup tgt-vp based on cppcheck results 2025-07-21 23:21:57 -07:00
Lars-Peter Clausen 60b6435653 tgt-vvp: Support nested lvalues for all property types
Currently nested lvalues are only supported for vector typed properties.
Refactor the code to also support other types.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2025-01-05 16:54:18 -08:00
Lars-Peter Clausen 9f8a8959a7 Add regression tests for assignment operators on queue and darray elements
Check that assignment operators work as expected on queue and dynamic array
elements.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2025-01-05 15:55:34 -08:00
Lars-Peter Clausen 43c138fdd3 tgt-vvp: Support assignment operators on queues and dynamic array elements
Currently assignment operators on queues and dynamic elements trigger an
assert.

Add support for handling this properly. Since the operation for loading an
element for an queue or dynamic array is identical most of the code can be
shared, only writing back the value has to be handled separately.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2025-01-05 15:55:01 -08:00
Lars-Peter Clausen 867c7d18b4 tgt-vvp: Support assignment operators on object properties
Currently assignment operators on object properties are silently
ignored. Make sure that they are handled.

To enable this refactor the code a bit so that the assignment
operator handling can be shared between object property assignments
and scalar value assignments.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2025-01-05 15:55:01 -08:00
Lars-Peter Clausen 1e9cfc34c0 tgt-vvp: Remove implicit casts between vector and real
Remove implicit casts between vector and real in tgt-vvp. These are not
required since any implicit cast in the source will be converted to an
explicit cast in the elaboration stage.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2025-01-02 17:40:29 -08:00
Lars-Peter Clausen de9d5e98b1 tgt-vvp: Replace `%pushi ...; %op` with `%opi`
For sequences where the tgt-vvp backend generates `%pushi` followed by one
of the operations that have an immediate version replace it with the
immediate version. This is slightly more efficient.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2024-08-31 13:46:30 +02:00
Lars-Peter Clausen 9549156226 Add initial support for array assignment patterns
SystemVerilog allows to use assignment patterns to assign values to an
array. E.g. `int a[4] = '{1, 2, 3, 4}`.

Each value is evaluated in the context of the element type of the array.

Nested assignment patterns are supported. E.g. `int a[2][2] = '{'{1, 2},
'{1, 2}};`

Add initial support for array assignment patterns for both continuous as
well as procedural assignments.

For continuous assignments the assignment pattern is synthesized into an
array of nets. Each pin is connected to one of the assignment pattern
values and then the whole net array is connected to target array.

For procedural assignments it is unrolled in the vvp backend. E.g
effectively turning `a = '{1, 2};` into `a[0] = 1; a[1] = 2;`.

Not yet supported are indexed initializers or `default`.
E.g. `int a[10] = '{1:10, default: 20};`

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2023-06-17 11:50:23 -07:00
Lars-Peter Clausen 872ccd32c4 tgt-vvp: Add resize for string element assignment where necessary
There are some cases where during an assignment the elaboration step can
generate constructs with the right-hand-side expression being wider than
the left-hand-side expression.

To handle this the tgt-vvp backend inserts a %pad operation when necessary.
One place where this is missing is when writing to an string element. Here
instead an assert is triggered requiring the right-hand-side expression to
be 8 bits wide.

E.g.
```
bit [7:0] x;
bit [8:0] y;
string s;

x = y; // tgt-vvp inserts %pad
s[0] = y; // tgt-vvp triggers assert
```

Long term this should be fixed at the elaboration stage and insert the
proper width cast. But for now solve this the same way as other places in
tgt-vvp and insert the %pad operation for string element assignments if the
width does not match.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2023-06-16 07:29:16 -07:00
Lars-Peter Clausen f831d7d76f Add `ivl_type_packed_width()` API
The C++ API for `ivl_type_t` has a method to query the total width of a
packed type. This is currently not exported to the C API and the tgt-vvp
backend implements similar functionality by querying the individual
dimensions of a type.

Export the `packed_width()` method to the C API. This allows to remove the
custom implementation from the tgt-vvp backend.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-10-08 13:42:40 +02:00
Lars-Peter Clausen a4eeea75ce tgt-vvp: Handle assignment operator on real array entries
The basic structure for supporting assignment operators on real arrays
exists in the tgt-vvp backend. But there are a few problems, most
importantly it generates the wrong instruction for loading data from the
real array.

The instruction it uses is `%load/reala`, but that instruction does not
exist, the correct name is `%load/ar`.

In addition to this there are a few minor problems.
  * Out-of-bounds access on the array triggers an assert
  * Missing `%pop/real` instruction when skipping a write due to
    out-of-bounds access

Address these so assignment operators are supported on real array entries.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-05-26 21:30:04 +02:00
Lars-Peter Clausen d651aefd92 tgt-vvp: Allow out-of-bounds assignment operator on arrays wider than 32 bits
For an out-of-bounds assignment operator on an array element an assert is
hit if the element width is great than 32.

Remove the assert and make sure that this case is handled correctly by
using the `%pad/s` instruction to extended the X value to the correct
width.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-05-21 21:30:33 +02:00
Lars-Peter Clausen d746c592b2 tgt-vvp: Fix out-of-bounds compressed assignment to arrays
If the index of an array access is known to be out-of-bounds during
elaboration it is replaced with 'x. In the tgt-vvp backend that is handling
compressed array assignments there is an assert() that triggers if the
index is an undefined immediate.

There is already an existing code path that is capable of handling
out-of-bounds access. Remove the assert and set the index to ULONG_MAX to
trigger taking the out-of-bound access path.

On this out-of-bounds path the write to the array is skipped. But this
leaves the result on the vector stack. Insert the `%pop/vec4` instruction
to make sure it is removed.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-05-21 21:15:20 +02:00
Lars-Peter Clausen e263d5b268 tgt-vvp: Fix store skip for assignment operator on dynamic part select
The operator assignment on dynamic part selects uses the `%store/vec4`
instruction to store the value. This instruction will skip the assignment
if flag 4 is set. This is for handling the case where the index is
undefined.

Since the left hand side of the assignment is an arbitrary expression it
can change the flag. The implementation handles this by making a copy of
the flag and restoring it before executing the `%store/vec4` instruction.

The flag is set by the `%ix/vec4` instruction when loading the index
register. But the copy of the flag is made before that and just picks
up the flag that was stored by previous expressions. This can cause
the store to be skipped when it shouldn't.

E.g. in the following code the increment will be skipped. Flag 4 is used
from the `a == 0` comparison, rather than from computing the part select
index.

```
int a = 0;
if (a == 0) begin
  a[a+:2] += 1;
end
$display(a); // Will print 0, should print 1
```

Fix this by moving the copy of the flag after the `%ix/vec4` instruction.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-05-16 10:18:27 +02:00
Lars-Peter Clausen 2abfef68ff tgt-vvp: Fix load skip for assignment operator to array entry
The vvp `%load/vec4a` instruction will skip the load if vvp flag 4 is set
and return 'x. This is meant for handling the case where the index is
undefined.

For assignment operators on array entries, when the index is an immediate
value, vvp flag 4 is not cleared before the load instruction. If a previous
instruction set flag 4 it load yield 'x.

E.g. for the following sequence `x[0]` should be `11`, but will be `'x`.

```
integer x[10];
logic a = 1'b0;
x[0] = 10;
if (a == 0) begin
  x[0] += 1;
end
```

Properly clear the flag before the load instruction to handle this
correctly.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-05-16 10:18:27 +02:00
Lars-Peter Clausen b83ebf3c8e tgt-vvp: Fix store skip on real typed array entries
When assigning a value to a real typed array entry the vvp `%store/reala`
instruction. This instruction will skip the store if the vvp flag 4 is set.
This is to handle the case where the index is undefined.

When the index into the array is an immediate value the flag 4 is not
cleared. If a previous instruction set flag 4 the store will be skipped.

E.g. for the following r[0] will remain 0.0 since the assignment to it is
skipped.

```
integer a = 0;
real r[1:0];
if (a == 0) begin
  r[0] = 1.23;
end
```

Fix this by using the `draw_eval_expr_into_integer()` helper function to
evaluate the index into a word register. The function correctly handles all
the special cases.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-05-16 10:18:27 +02:00
Lars-Peter Clausen 1eb22b7e14 tgt-vvp: Allow multi-dimensional real arrays
There is currently a restriction in the vvp code generator backend that
throws an assertion when generating wire access for a multi-dimensional
real array.

But there is nothing special about multi-dimensional arrays. In vvp arrays
are in canonical form. Meaning they only have a single dimension and the
conversion form multi to single dimension is done in the higher layers.

Remove the assert to allow multi-dimensional real arrays.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-05-02 14:29:15 +02:00
Lars-Peter Clausen b11da7e16f tgt-vvp: Don't accidentally skip assignment pattern initialization
The `%store/dar/...` and `%store/qdar/...` instructions are used to load a
value into an entry in dynamic array or queue. These instructions will skip
the load if VVP flag 4 is 1.

For assignment pattern initialization these instructions are used to load
the value of the individual assignment pattern expressions into the dynamic
array.

For queues flag 4 is never cleared when generating the code for the
assignment pattern. This means the initialization might be skipped
depending on what value the flag had before.

```
int a = 1;
int q[$];
a = a == 1;
q = {1, 2, 3, 4};
```

For dynamic arrays it is cleared once in the beginning. But each item in
the assignment pattern can be an arbitrary expression.  Evaluating the
expression can cause the flag to get overwritten. E.g. the following code
will skip the assignments.

```
int a = 1;
int d[];
d = {a ? 1 : 1, 2, 3, 4};
```

To fix these issues make sure that the flag is cleared after evaluating
each initialization expression and before executing the `%store/...`
instruction.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-04-17 09:09:38 +02:00
Cary R 053777f16d Fix some cppcheck warnings in tgt-vvp 2020-12-31 23:19:34 -08:00
Stephen Williams 3c2fb6a601 Fix dynamic array assignment to make a copy of the rvalue.
IEEE Std 1800-2017 Section 7.6 Array assignments

Assignment of a dynamic array creates a duplicate of the source,
so that assignments to the copy don't impact the original. Handle
all sorts of dynamic array base types.
2020-11-26 12:52:06 -08:00
Cary R 112ebb48d8 Add file/line information to procedural warnings and darray fixes
When -pfileline=1 is used the queue procedural warnings have file
and line information added to the messages. Also switch the trace
debugging to be off by default.

Also, Add some preliminary missing darray functionality.
2020-08-10 22:01:55 -07:00
Cary R e77d22e135 Add file and line information to warning message 2020-08-07 01:02:00 -07:00
Cary R bff115b9f7 Add initial support for assigning between queues and darrays 2020-08-07 00:23:43 -07:00
Cary R 199ed39abe Report when the array pattern is larger than the maximum queue size 2020-08-02 23:40:35 -07:00
Cary R 2530041a38 Add support for assign array patterns to a queue 2020-07-30 19:52:38 -07:00
Cary R a2ba8a16b1 Add support for inserting into a queue 2020-07-29 23:00:19 -07:00
Cary R 14ade1a9f4 Pass the max size when storing to a queue 2020-07-27 21:24:22 -07:00
Cary R c969c324ed Add initial support for using a queue element as an L-value 2020-07-26 14:02:29 -07:00
Cary R b1699a2781 Fix two compiler warnings 2019-10-05 15:29:08 -07:00
Martin Whitaker 70da8db6b5 Fix assignment to scalar class property in tgt-vvp. 2019-10-05 20:12:52 +01:00
Martin Whitaker d6391490e3 Resize vector before assigning to a dynamic array word.
Failing to do this leads to an assertion failure in vvp.
2019-09-16 20:39:19 +01:00
Martin Whitaker c066e2d15c Properly implement casts from strings and dynamic arrays to vectors.
As discussed on iverilog-devel (2018-03-09), the existing implementation
(using Icarus-specific vpi functions) only worked with assignments to
simple variables, and could not be easily modified to work more generally.
So use the new vvp instructions added in the previous two commits.
2019-09-11 22:08:46 +01:00
Stephen Williams 9a7f31c728 Functions that return strings pass the return value on the stack. 2016-03-01 15:38:28 -08:00
Martin Whitaker a0bee0a76f Add support for real valued compressed assignment statements in tgt-vvp. 2016-02-23 22:02:03 +00:00
Martin Whitaker a85c64d347 Revert "Add support for real valued compressed assignment statements in tgt-vvp."
This reverts commit 3fede95f5e.
2016-02-23 21:49:49 +00:00
Martin Whitaker 3fede95f5e Add support for real valued compressed assignment statements in tgt-vvp. 2016-02-23 20:58:30 +00:00
Martin Whitaker b77d758f19 Fix compressed assignments to concatenations.
When loading a lval concatenation, tgt-vvp was loading the elements
in the wrong order for the %concat instruction.
2016-02-23 16:44:03 +00:00
Stephen Williams 469d4fefa7 Handle compressed assign to function return value. 2016-02-01 12:38:48 -08:00
Stephen Williams c114edfa6c Handle void functions with new .scope format. 2016-02-01 09:29:49 -08:00
Stephen Williams 604a62379c Make .scope aware of return type, and extend %ret/vec4 operands
The .scope needs to be aware of return types so that the %call/vec4
function knows how to intialize the return value. We also need to
extend the %ret/vec4 to support writing parts of the return value.
2016-01-31 15:29:52 -08:00
Stephen Williams e435a879fc Add ability to read back return value / Add vec4 stacked user functions.
Also:
- handle functions as arguments to system tasks.
- Cleanup detect of signal as return value.
2016-01-24 18:36:26 -08:00
Stephen Williams bfc9cd8715 Make real functions in processes use parent stack for return value. 2016-01-10 17:09:33 -08:00
Martin Whitaker cfbc90812b Enable use of MinGW ANSI stdio routines.
Defining __USE_MINGW_ANSI_STDIO=1 provides C99 compatible printf
and scanf routines, which avoids the need for workarounds for the
various failings of the Microsoft C runtime library.
2015-05-10 11:45:42 +01:00
Maciej Suminski 756c9ceccf ivl: Functions returning a dynamic array may be casted to vector. 2015-02-04 16:02:38 +01:00
Maciej Suminski a52242745a ivl: Casting dynamic arrays to vectors. 2015-02-04 16:02:38 +01:00
Cary R b3425d6cf3 Report that 4-state dynamic arrays are not currently supported in vvp
Also fix some error code propagation issues.
2015-01-16 18:22:16 -08:00
Cary R b2d8d41e3f Fix some cppcheck warnings in tgt-vvp 2014-12-10 16:30:55 -08:00
Stephen Williams f287546f49 Fix a %vpi_call call syntax. 2014-12-02 15:28:22 -08:00
Stephen Williams 38f277d81b Merge branch 'master' into vec4-stack
Conflicts:
	vvp/array.cc
	vvp/vthread.cc
2014-12-02 11:21:58 -08:00
Maciej Suminski b12e00d875 ivl: String to vector casting. 2014-11-27 17:36:23 +01:00