Skip to content

fix(testbench): keep unknown bits in TB writes and conditions - #2654

Merged
mergify[bot] merged 1 commit into
masterfrom
stack/tignear/perf/tb-statements-generated/keep-unknown-bits-tb-writes-conditions--d06ef4ac
Oct 31, 2026
Merged

mergify[bot] merged 1 commit into
masterfrom
stack/tignear/perf/tb-statements-generated/keep-unknown-bits-tb-writes-conditions--d06ef4ac

Conversation

@tignear

@tignear tignear commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

In a four-state build a Veryl testbench lost every unknown bit it wrote:
r = 'x stored 0 and s = 'z stored 1, in both schedulers. The frontend
dropped the mask of constants, and TB expressions ran in bit registers with
two-state result slots.

TB expressions now keep unknown bits as the HDL does:

  • Constants with x/z digits are emitted with their mask, in Celox's
    encoding. Unsized fill literals ('0, '1, 'x, 'z) fill their
    context (IEEE 1800-2023 5.7.1).
  • In a four-state build, loads of four-state storage, masked constants and
    every result computed from one use logic registers, so the shared SIR
    operators propagate X. Result slots and saved values that hold one keep a
    mask plane.
  • A condition with no known one bit is false: if, and immediate
    assertions (12.4, 16.3).
  • A conditional operator with an unknown condition combines both arms
    bit by bit (11.4.11). Arms that write state, make strings or load an
    unchecked dynamic address still run only as the condition's known bits
    select, so that a known condition never runs the other arm; an unknown
    condition then runs the second one.
  • A selected write at an unknown index writes nothing, and a read there is
    x, or 0 from two-state storage (11.5.1). An unknown index never addresses
    memory.
  • A wildcard pattern's unknown bits match anything (11.4.6).
  • A cast to a two-state type, a two-state destination (a variable or a
    function argument), loop bounds, counts and other numeric uses read
    unknown bits as 0 (6.11.2).
  • Narrow loads and selections drop their other bits by moving bits, so z
    bits stay z.

Message arguments now get their mask from the expression result, which
replaces the plain-load special case that #2625 added.

A two-state build creates no logic registers, so its generated code does
not change. A constant's unknown bits read as 0 there, which turns a 'z
into 0 instead of 1 (6.11.2); a wildcard pattern's unknown bits read as 0
too, as they did before.

four_state_tb_edges now really moves its reset to and from x and z: those
moves take 5 host edge batches instead of 2, and its count differs from the
reference scheduler by the missed negedge of #2650.

Fixes #2645

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 30, 2026 •

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 ✅ Completed 2026-10-30T18:30:09.188195Z b9c2177 New commits
ℹ️ 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 chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7fc4a3d5ef

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread crates/celox-testbench/src/lowering.rs Resolved
Comment thread crates/celox-testbench/src/lowering.rs Resolved
Comment thread crates/celox-testbench/src/lowering.rs Resolved
@mergify

mergify Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

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

@tignear

tignear commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor Author

Revision history

# Type Changes Reason Date
1 initial 7fc4a3d 2026-10-30 15:19 UTC
2 content 7fc4a3d → bc63862 2026-10-30 15:19 UTC
3 content bc63862 → ae870d6 2026-10-30 16:57 UTC
4 content ae870d6 → b9c2177 2026-10-30 18:26 UTC

@tignear
tignear force-pushed the stack/tignear/perf/tb-statements-generated/keep-unknown-bits-tb-writes-conditions--d06ef4ac branch from 7fc4a3d to bc63862 Compare October 30, 2026 15:23

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bc638620d5

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread crates/celox-testbench/src/lowering.rs Resolved
@tignear
tignear force-pushed the stack/tignear/perf/tb-statements-generated/keep-unknown-bits-tb-writes-conditions--d06ef4ac branch from bc63862 to ae870d6 Compare October 30, 2026 17:01

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ae870d6816

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread crates/celox/src/testbench.rs Resolved
In a four-state build a Veryl testbench lost every unknown bit it wrote:
`r = 'x` stored 0 and `s = 'z` stored 1, in both schedulers. The frontend
dropped the mask of constants, and TB expressions ran in bit registers with
two-state result slots.

TB expressions now keep unknown bits as the HDL does:

- Constants with x/z digits are emitted with their mask, in Celox's
  encoding. Unsized fill literals (`'0`, `'1`, `'x`, `'z`) fill their
  context (IEEE 1800-2023 5.7.1).
- In a four-state build, loads of four-state storage, masked constants and
  every result computed from one use logic registers, so the shared SIR
  operators propagate X. Result slots and saved values that hold one keep a
  mask plane.
- A condition with no known one bit is false: `if`, and immediate
  assertions (12.4, 16.3).
- A conditional operator with an unknown condition combines both arms
  bit by bit (11.4.11). Arms that write state, make strings or load an
  unchecked dynamic address still run only as the condition's known bits
  select, so that a known condition never runs the other arm; an unknown
  condition then runs the second one.
- A selected write at an unknown index writes nothing, and a read there is
  x, or 0 from two-state storage (11.5.1). An unknown index never addresses
  memory.
- A wildcard pattern's unknown bits match anything (11.4.6).
- A cast to a two-state type, a two-state destination (a variable or a
  function argument), loop bounds, counts and other numeric uses read
  unknown bits as 0 (6.11.2).
- Narrow loads and selections drop their other bits by moving bits, so z
  bits stay z.

Message arguments now get their mask from the expression result, which
replaces the plain-load special case that #2625 added.

A two-state build creates no logic registers, so its generated code does
not change. A constant's unknown bits read as 0 there, which turns a `'z`
into 0 instead of 1 (6.11.2); a wildcard pattern's unknown bits read as 0
too, as they did before.

`four_state_tb_edges` now really moves its reset to and from x and z: those
moves take 5 host edge batches instead of 2, and its count differs from the
reference scheduler by the missed negedge of #2650.

Fixes #2645

Change-Id: Id06ef4acf030dff9789a05cb375d1144dc99f280
@tignear
tignear force-pushed the stack/tignear/perf/tb-statements-generated/keep-unknown-bits-tb-writes-conditions--d06ef4ac branch from ae870d6 to b9c2177 Compare October 30, 2026 18:27
@tignear tignear added the merge-ready Request merging through Mergify after required checks label Oct 31, 2026
@mergify mergify Bot added the queued Mergify queue entry label Oct 31, 2026
@mergify

mergify Bot commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

✅ Merged into master as 89e2819 at 05:02 UTC

13 min in the queue, 11 min of it CI.

So far

9 merge conditions met
  • check-success = Conventional Commit title
  • check-success = Queue validation
  • check-success = Verify workflow lockfile
  • any of · required by 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 · required by 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 · required by 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 · required by 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
  • any of · required by GitHub repository ruleset rule master:
    • check-success = @github-actions/Queue validation
    • check-neutral = @github-actions/Queue validation
    • check-skipped = @github-actions/Queue validation
  • any of · required by GitHub repository ruleset rule master:
    • check-success = @github-actions/Verify workflow lockfile
    • check-neutral = @github-actions/Verify workflow lockfile
    • check-skipped = @github-actions/Verify workflow lockfile

Times in UTC · dashboard · how the merge queue works

@mergify
mergify Bot merged commit 89e2819 into master Oct 31, 2026
28 checks passed
@mergify
mergify Bot deleted the stack/tignear/perf/tb-statements-generated/keep-unknown-bits-tb-writes-conditions--d06ef4ac branch October 31, 2026 05:02
@mergify mergify Bot removed the queued Mergify queue entry label Oct 31, 2026
@github-actions github-actions Bot mentioned this pull request Oct 31, 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.

Veryl testbench writes of 'x and 'z store known values in four-state builds

1 participant