Commit Graph

9662 Commits

Author SHA1 Message Date
Geza Lore 0af3cb9dc0 VlWide4AB prototype for 4-state data
Based on top of #7642. And as discussed in #7193, experiments.

This patch contains 2 parts.

---

The important part:

In the runtime, it introduces `VlWide4AB`, which is is intended to be the
representation of 4-state signals with 32-bit A/B words interleaved
(each 2x32-bit word is an `EData[2] array`, as I'm a bit paranoid about
strict aliasing issues, but could be made a struct with care).
`VlWide4AB` contains `.abits()` and `.bbits()` methods, which yields a
proxy class that through implict constructors can be passed directly to
the existing runtime functions that expect a `WDataInP`/`WDataOutP`.
Whether the `WData*` handle is for a `VlWide` (contiguous), or
`VlWide4AB` is encoded in the spare LSB of the pointer held in the
`WData*` handle. Indexing, arithmetic on the handle considers the
stride, so as long as the runtime only accesses wide state through
`WData*` handles, the routines work for both the 2-state and
4-state-interleaved formats (and the same could be done for
4-state-non-interleaved, or other exotic encodings if necessary.

Example to clarify, though I would recommend a `make test-diff` with
this patch:

```c++
  // This works just like before
  VlWide<10> a2, b2, c2;
  VL_MUL_W(10, a2, b2, c2);

  // This also works
  VlWide4AB<10> a4, b4, c4;
  VL_MUL_W(10, a4.abits(), b4.abits(), c4.abits());

  // But this would also work no problem - note mixed strides/parts:
  VL_MUL_W(10, a2, b4.abits(), c4.bbits());
```

That is, the runtime needs minimal changes. Places where a wide is
accessed without a `WData*` handle or where `WData*::datap()` is called
to get to the raw pointer will need to be fixed. (I will post a separate
patch to add a type-safe template based `scanf` implementation which will
also just work afterwards).

Regarding performance, the encoding is fairly efficient, so impact
should be small, but also most things should be V3Expanded anyway.
If there are performance issues with some, we can always add explicit
variants for those, but I would expect most time to be in the generated
code after V3Expand.

To add runtime functions that take VlWide4AB directly, one would cerate
a `WData4*` handle analogous to `WData`, then can pass the `VlWide4AB`
dierctly without `.abits()`, `.bbits()`. Tracing for example will need
this.

---

The unimportant part:

I hacked up V3Emit and friends to emit `VlWide4AB` for all wide data,
currently always using the `bbits()`, just to test this out. It passes
~94% of the test suite. You can largely ignore this demonstration hack.

---

Continuing the discussion from
https://github.com/verilator/verilator/pull/7193#issuecomment-4444858411
the runtime with the above architecture will work to do 2-state
arithmetic with minimal changes. Verilator internally will do no 4-state
arithmetic after V3Forustate (which needs to run early), which coverts
all 4-state arithmetic into 2-state over abits/bbits like it
currently does.

I came to the conclusion agreeing with Wilson that we will need an
explicit `AstABits`/`AstBBits` LValue type to represent the reference
over aggregate data types (e.g. unpacked arrays of queues of classes
that have associative arrays of 4-state values as members). With the
above runtime, the Emit rule for `AstABits` is simply to print
`.abits()`, and similarly for `AstBBits`, simply print `.bbits()`.

However, we should special case `AstNodeVarRef`, to contain an enum
value, to represent the reference directly when dealing with simple
variable references. (These are the ones that we can optimize
aggressively throughout the compiler). That is, add this to
`AstNodeVarRef`:

```c++
  enum class VarPart : uint8_t {
     WHOLE, // References whole variable, e.g. for `x = y`
     ABITS, // References A bits, e.g `x = p.abits() | q.bbits()`
     BBITS, // References B bits
  };

  class AstNodeVarRef {
        ...
        VarPart m_part
        ...

        VarPart part() const { return m_part; }
        // Encoded reference if needed for map keys - can be other than
        // uintptr_t, but we have a few spare bottom bits in the ptr.
        uintptr_t varpart() const {
          return reinterpret_cast<uintptr_t>(m_varp) | m_part;
        }
  };
```

`AstVarRef(AstVar, VarPart::ABITS)` is then semantically equivalent to
`AstABits(AstVarRef(AstVar, VarPart::WHOLE))`.

(We could special case other LValue nodes if it helps with the
internals, and we will probably want to do e.g. `AstWordSel`, but on the
first try it's probably enoughto have the generic `Ast{A,B}Bits` +
VarRef special.)

Rules to encode in V3Broken:

- After V3FourState, only LValue expressions can have a 4-state type
- `AstABits`/`AstBBits` (and `AstNodeVarRef` with non WHOLE flag) can only
  be applied to a 4-state packed type.
- `AstABits`/`AstBBits (and `AstNodeVarRef` with non WHOLE flag) has a
  2-state type matching it's operand (same width)
2026-05-22 20:07:14 +01:00
Geza Lore c99aa8ede5
Fix erroneous implicit conversions of VlWide (#7642)
Change WDataInP/WDataOutP to be opaque handles types instead of aliases
to raw pointers. This subsequently eliminates needing an implicit cast
operator in VlWide, which is replaced with implicit constructors of
WDataInP/WDataOutP that can create a handle from a VlWide. This
eliminates some unsafe conversions that the previous implicit cast
operator unintentionally enabled (e.g. #7618). It also eliminates
having to insert ".data()" in various places int he generated code, which
simplifies internals (the only place ".data()" should be needed is in
calls to variadic functions where the expected type of the argument is
not WDataInP/WDataOutP).

The handles otherwise behave like pointers, implementing the minimal
amount of operators required to code the runtime. The handle is still
only a single pointer, and will be passed in registers as before, so
this patch should be performance neutral.

As part of this removed WData, which used to be an alias for EData.
All uses are now either EData*, WDataInP, WDataOutP, or VlWide directly.
2026-05-22 20:05:08 +01:00
Geza Lore ef72b2fabb Tests: Disable t_fsm_register_wrapper_noinline --vltmt (#7644) 2026-05-22 14:27:40 +01:00
Lucas Amaral 20f4eca646
Support busses with mix of pullup/pulldown (#7632) 2026-05-21 14:45:40 -04:00
github action a208d17939 Apply 'make format' 2026-05-21 17:51:28 +00:00
Yogish Sekhar f282335600
Support FSM detection in primitive wrappers (#7607) 2026-05-21 13:50:31 -04:00
Artur Bieniek 6a74112f0b
Fix V3Force deterministism (#7620) (#7637)
Fixes #7620.
2026-05-21 11:04:17 -04:00
Benjamin Collier 69b3c5f6d1
Support streaming on queues (#7597) 2026-05-20 19:14:02 -04:00
Nick Brereton c5798f902b
Fix reference counting for modport task references (#7628) 2026-05-20 14:24:56 -04:00
github action d874d2fd06 Apply 'make format' 2026-05-20 11:11:52 +00:00
Yogish Sekhar 9e4863589e
Fix non-determinism in FSM detection (#7619)
Fixes #7619
2026-05-20 12:10:53 +01:00
Wilson Snyder daa4a108de Commentary: Debugging non-determinism 2026-05-19 21:51:12 -04:00
Wilson Snyder f3a86bacdd Commentary: Changes update 2026-05-19 21:40:08 -04:00
Geza Lore afad8db672
Fix VlWide equality comparion in unpacked structs (#7618) 2026-05-20 00:57:33 +01:00
Michael Rogenmoser cb3b9c7c43
Fix nested parameterized class typedef chain (#7538) 2026-05-19 14:12:24 -04:00
Kamil Danecki b06ea01afb
Fix type parameters order (#7615) 2026-05-19 09:52:09 -04:00
Pawel Klopotek efdc8d1cbf
Fix unique_index method on assoc arrays with values differing from the keys (#7616)
Signed-off-by: Pawel Klopotek <pklopotek@internships.antmicro.com>
2026-05-19 09:51:23 -04:00
github action 662cd43348 Apply 'make format' 2026-05-19 01:41:54 +00:00
Nikolai Kumar a67c5f81f3
Fix clocking-block sample of unpacked array (#7612) (#7613)
Fixes #7612.
2026-05-18 21:40:54 -04:00
dependabot[bot] 2ebb99aaa2
CI: Bump actions/create-github-app-token in the everything group (#7611) 2026-05-18 20:48:53 -04:00
Krzysztof Bieganski eb258d7df7
IEEE-compliant, fair `std::semaphore` (#7435) (#7605)
Signed-off-by: Krzysztof Bieganski <kbieganski@antmicro.com>
2026-05-18 11:11:42 +02:00
Yilou Wang 00c9e58006
Fix internal error on consecutive repetition with N > 256 (#7552) (#7603) 2026-05-17 21:54:10 -04:00
Greg Davill 57ce373e99
Fix array pattern concatenation (#7401) (#7402) 2026-05-17 09:49:32 -04:00
github action 7f520ff1a2 Apply 'make format' 2026-05-17 11:35:24 +00:00
Muzaffer Kal 9fe058677b
Support NBAs in initial blocks with delay/event controls (#7566) (#7600)
Fixes #7566.
2026-05-17 07:34:29 -04:00
Wilson Snyder c1ab369da2 Fix process comparison compile error with `--public-flat-rw` (#7592).
Fixes #7592.
2026-05-15 18:22:46 -04:00
Wilson Snyder 349dd546e7 Internals: Rename stdPackageProcessp etc. No functional change. 2026-05-15 17:33:19 -04:00
Geza Lore 4e853d8cb6
Fix cpu pinning when no 'core id' present in /proc/cpuinfo (#7599) 2026-05-15 14:45:39 -04:00
Geza Lore 8c8d9b4f4c Internals: Sign off pylint warnings 2026-05-15 17:39:48 +01:00
Yilou Wang f9427c6d5f
Support property abort operators (accept_on, reject_on) (#7578) 2026-05-15 08:38:38 -04:00
github action 442dd91683 Apply 'make format' 2026-05-15 11:53:21 +00:00
Stuart Morris 67e74c5ce4
Fix interface instance name collision (#7591) (#7593)
Fixes #7591.

Co-authored-by: Leela Pakanati <41307800+cachanova@users.noreply.github.com>
2026-05-15 07:52:26 -04:00
Krzysztof Bieganski a42c8587cb
Optimize force read return values (#7596) 2026-05-14 20:26:02 -04:00
Wilson Snyder d66733aeb8 Fix process comparison compile error with `--public-flat-rw` (#7592).
Fixes #7592.
2026-05-14 17:52:28 -04:00
Wilson Snyder dff2606c0c Commentary: Changes update 2026-05-14 17:38:11 -04:00
Artur Bieniek fb617e49dd
Optimize read selects with no overlapping forces with regular reads (#7594) 2026-05-14 16:46:57 -04:00
Zubin Jain 4a1f17e75f
Fix force of unpacked arrays (#7579) (#7580)
Fixes #7579.
2026-05-14 10:58:16 -04:00
Krzysztof Bieganski c518abd22a
Optimize reading selected words on forced wide (#7391 repair) (#7554 partial) (#7572) 2026-05-14 07:38:42 -04:00
Geza Lore de4f743d0e
Internals: Use /bin/sh to test gdb (#7586) 2026-05-14 04:29:24 -04:00
Wilson Snyder a3da587fc3 Internals: Show operator in assert 2026-05-13 21:02:45 -04:00
Wilson Snyder 83b1dacce1 CI: Use windows-2025-vs2026 2026-05-13 21:02:05 -04:00
Wilson Snyder 1653b982b9 Verilog format 2026-05-13 21:00:34 -04:00
Thomas Brown 1c3ee7ce4c
Support expression coverage on assign statements (#7543) 2026-05-13 13:59:29 -04:00
Geza Lore e485dfe48c
Fix NBA to whole arrays (#7583)
Fixes #7575
2026-05-13 13:20:22 +01:00
Krzysztof Bieganski 3381d656c7
Support calling interface functions without parens (#7584)
Signed-off-by: Krzysztof Bieganski <kbieganski@antmicro.com>
2026-05-13 08:15:32 -04:00
Yilou Wang 05302080a9
Support procedural concurrent assertions with inferred clock (#7581) 2026-05-13 07:42:28 -04:00
Jakub Michalski 1ffa6b277d
Fix property argument retaining type of the previous variable (#7582)
Signed-off-by: Jakub Michalski <jmichalski@antmicro.com>
2026-05-13 07:41:35 -04:00
Yogish Sekhar 8312e9d901
Extend FSM Detect to support 'Wide State Encodings' (#7573) 2026-05-13 06:59:22 -04:00
Nick Brereton 9588e67ca9
V3Timing: pre-clear destructive event state before dynamic waits (#7340)
When lowering dynamic event controls, destructive pre-clear updates were inserted with addHereThisAsNext() on the original node and then that node was replaced. This could leave leaked/orphaned nodes under leak-checking runs.

Build an explicit replacement stmt chain instead:
  [pre-clear stmts] -> trigger loop -> awaitResumption,
and replace the original control with the chain head. Keep the loop-only path unchanged when no destructive pre-clear is needed.
2026-05-12 19:01:37 +01:00
anonkey 67b21e4c62
Fix segmentation fault when using --trace with --lib-create (#7299) (#7518) 2026-05-12 10:16:47 -04:00