Skip to content

feat(sv): support inout ports with a single tristate driver - #1951

Merged
mergify[bot] merged 1 commit into
masterfrom
feature/feat/1948-sv-inout-tristate
Oct 25, 2026
Merged

mergify[bot] merged 1 commit into
masterfrom
feature/feat/1948-sv-inout-tristate

Conversation

@tignear

@tignear tignear commented Oct 25, 2026

Copy link
Copy Markdown
Contributor

What

SV inout ports below the top module are accepted when their net has exactly one continuous driver anywhere in the hierarchy. A conditional driver like oe ? dr : 'z counts as one, including the per-bit form that drives rtlmeter C906's GPIO pad b_pad_gpio_porta. Closes #1948.

Why / semantics

  • IEEE 1800-2023 23.3.3: an inout port connection is a non-strength-reducing transistor connection, so both sides form one net.
  • 6.6: a net's value comes from its drivers; with no active driver it is z.
  • 23.3.3.2: only nets may be on either side of an inout port.

How

  • resolve_inout_drivers runs over the specialized module graph before the driver checks. It records, per specialization, the inout ports whose net is driven in that module or below it, through a local driver, a child output, or a child inout that is itself driven inside. The fixpoint terminates because recursive instantiation is already rejected.
  • Each inout connection is then lowered as a one-way port connection. It carries the value out of the child when the child side drives the net (the output glue) and into the child otherwise (the input glue; an unconnected inout reads z). Reads on both sides see the driven value or z, and 0 in two-state mode.
  • child_output_driver_ranges counts an inout connection as a driver only when its child side drives the net. As a result, a net driven on both sides of an inout connection, by two children, or by a child output plus a child inout is rejected with multiple net drivers for .... Resolving several drivers (6.6.1, wand/wor, strengths) is the follow-up in feat(sv): support inout ports with a single tristate driver #1948.
  • A variable or an expression connected to an inout port is now an illegal-context error (23.3.3.2). Implicit nets are allowed.
  • Still unsupported: inout ports of the top module, and inout ports of foreign (Veryl) children (Support inout ports on external SystemVerilog modules instantiated from Veryl #1021).

The handling is per port connection. Designs without inout ports go through unchanged paths: child_port_direction returns the port's own kind, and the resolver finds no inout ports.

Validation

  • cargo nextest run -p celox -p celox-frontend-sv -p celox-test-suite --features celox/systemverilog -E 'binary(systemverilog) | package(celox-frontend-sv) | binary(retained_reports)': 4739 passed, 0 failed.
  • New shared cases in hierarchy.vtest, run on all backends (native, cranelift, wasm, plus the parallel variants):
    • inout_tristate_driver_in_child_reaches_parent: a per-bit tristate in a grandchild, read back inside the driving block and through the port on the parent side. Covers all bits driven, half driven (upper nibble z), and oe=0 (all z, === 1'bz).
    • inout_tristate_driver_in_parent_reaches_child: the driver is in the parent; direct, pass-through and unconnected readers; a z read while en=0.
    • inout_tristate_nets_read_zero_in_two_state: both directions in two-state mode, with z reading as 0.
    • inout_tristate_drivers_reach_implicit_nets: inout connections through implicit nets.
  • External simulators (verify-sv-icarus, verify-sv-verilator, --filter hierarchy::inout):
    • Icarus: 4/4 passed.
    • Verilator: the two-state case passed; the three four-state cases are skipped because Verilator is 2-state.
  • review_regressions::rejects_inout_nets_with_several_drivers covers two children, a parent plus a child through a pass-through, a child output plus a child inout, and a local driver plus a child inside the inout's own module. rejects_variables_and_expressions_on_inout_ports covers the 23.3.3.2 check.
  • cargo clippy -p celox-frontend-sv -p celox --features celox/systemverilog --tests -D warnings and cargo fmt --check are clean.
  • sv-tests: no case in the pinned revision contains inout, so its verdicts and expected.tsv are unaffected.

Performance (designs without inout)

callgrind on the xezim synthetic b2_vm_dispatch_bit.sv (--two-state --unlimited, --toggle-collect='*SimulationState*step_until*', heliodor-dev, taskset -c 8-11), origin/master vs. this PR:

total Ir JIT code Ir (4 functions)
base (de79c93) 4,385,804,548 2,761,200,000 / 12,400,027 / 3,600,000 / 70
this PR 4,385,804,548 2,761,200,000 / 12,400,027 / 3,600,000 / 70

Both runs produce checksum 136.

C906

End to end, C906 still stops before this code path. It needs non-ANSI port declarations (#426) and a hierarchical struct-member reference from tb. The new cases reproduce the GPIO structure: a per-bit oe ? dr : 1'bz with a read-back, passed through intermediate inout ports to a parent that only connects and reads the net.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-10-25T01:05:07.825462Z
We couldn’t complete this review. Comment @codex review to try again.
f8728d0 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@mergify

mergify Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Queued — the merge queue status continues in this comment ↓.

@tignear
tignear force-pushed the feature/feat/1948-sv-inout-tristate branch from f8728d0 to 6353879 Compare October 25, 2026 08:50
@tignear tignear added the merge-ready Request merging through Mergify after required checks label Oct 25, 2026
@mergify mergify Bot added the queued Mergify queue entry label Oct 25, 2026
@mergify

mergify Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-10-25 09:43 UTC · Rule: changes · triggered by rule Queue explicitly requested merges
  • 🚫 Left the queue — 2026-10-25 11:24 UTC · at 6353879106606f4ecfc028b4d11728cc997cba68

This pull request spent 1 hour 41 minutes 10 seconds in the queue, with no time running CI.

Reason

The pull request conflicts with the base branch

The pull request was held in the queue, conflicting with at least one of 3 pull requests ahead of it. The conflict became a base branch one after #1954 merged.

Hint

You should update or rebase your pull request.

If you want to requeue this pull request, you can post a @mergifyio queue comment.

Requeued — the merge queue status continues in this comment ↓.

@mergify mergify Bot added dequeued Mergify stopped this queue entry; investigate before retrying and removed queued Mergify queue entry labels Oct 25, 2026
Both sides of an inout port connection form one net (IEEE 1800-2023
23.3.3), whose value its drivers determine and which is z without one
(6.6). An inout port below the top module whose net has one continuous
driver, such as `assign io = oe ? d : 'z;`, now lowers to a one-way
connection carrying the value away from the side that drives it, so
reads on either side see the driven value or z (0 in two-state mode).

The ports whose net is driven in their module or below it are resolved
over the specialized hierarchy before the driver checks. A net driven on
both sides of an inout connection, or by several children, is still
rejected as having multiple net drivers, and a variable or expression
connected to an inout port is rejected (23.3.3.2). Inout ports of the
top module and of foreign modules remain unsupported.

Closes #1948

Change-Id: I76a456ac73b4a8d6e314baf63d75a9cc35a790dc
@tignear
tignear force-pushed the feature/feat/1948-sv-inout-tristate branch from 6353879 to 5efe018 Compare October 25, 2026 11:51
@tignear tignear removed the dequeued Mergify stopped this queue entry; investigate before retrying label Oct 25, 2026
@mergify mergify Bot added the queued Mergify queue entry label Oct 25, 2026
@mergify

mergify Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

This pull request spent 40 minutes 32 seconds in the queue, including 39 minutes 9 seconds running CI.

Required conditions to merge
  • check-success = Conventional Commit title
  • check-success = Queue validation
  • any of [🛡 GitHub repository ruleset rule master]:
    • check-success = @github-actions/Lint & Format
    • check-neutral = @github-actions/Lint & Format
    • check-skipped = @github-actions/Lint & Format
  • any of [🛡 GitHub repository ruleset rule master]:
    • check-success = @github-actions/NAPI Build (Linux ARM64 GNU)
    • check-neutral = @github-actions/NAPI Build (Linux ARM64 GNU)
    • check-skipped = @github-actions/NAPI Build (Linux ARM64 GNU)
  • any of [🛡 GitHub repository ruleset rule master]:
    • check-success = @github-actions/NAPI Build (Windows)
    • check-neutral = @github-actions/NAPI Build (Windows)
    • check-skipped = @github-actions/NAPI Build (Windows)
  • any of [🛡 GitHub repository ruleset rule master]:
    • check-success = @github-actions/Rust Test & NAPI Build
    • check-neutral = @github-actions/Rust Test & NAPI Build
    • check-skipped = @github-actions/Rust Test & NAPI Build
  • any of [🛡 GitHub repository ruleset rule master]:
    • check-success = @github-actions/JS Test (Ubuntu)
    • check-neutral = @github-actions/JS Test (Ubuntu)
    • check-skipped = @github-actions/JS Test (Ubuntu)
  • any of [🛡 GitHub repository ruleset rule master]:
    • check-success = @github-actions/JS Test (Windows)
    • check-neutral = @github-actions/JS Test (Windows)
    • check-skipped = @github-actions/JS Test (Windows)
  • any of [🛡 GitHub repository ruleset rule master]:
    • check-success = @github-actions/Conventional Commit title
    • check-neutral = @github-actions/Conventional Commit title
    • check-skipped = @github-actions/Conventional Commit title

@mergify
mergify Bot merged commit 25b0177 into master Oct 25, 2026
23 checks passed
@mergify
mergify Bot deleted the feature/feat/1948-sv-inout-tristate branch October 25, 2026 12:57
@mergify mergify Bot removed the queued Mergify queue entry label Oct 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-ready Request merging through Mergify after required checks

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(sv): support inout ports with a single tristate driver

1 participant