Skip to content

feat(sv): support $random and $urandom_range - #1396

Merged
mergify[bot] merged 2 commits into
masterfrom
feature/sv-random
Oct 17, 2026
Merged

mergify[bot] merged 2 commits into
masterfrom
feature/sv-random

Conversation

@tignear

@tignear tignear commented Oct 17, 2026

Copy link
Copy Markdown
Contributor

Stacked on #1392; GitHub retargets this PR to master when that branch is deleted.

Summary

  • $random (IEEE 1800-2023 20.14.1) follows the algorithm of Annex N, rtl_dist_uniform(seed, LONG_MIN, LONG_MAX) with a 32-bit long. Annex N computes it in floating point; Celox has no floating-point IR, so the frontend uses an integer formula on bits 31:9 of the next seed. I checked the formula exhaustively against the C reference (all 2^23 values), including the integral negative results Annex N decrements and the overflowing conversion, which returns LONG_MIN as the reference does on x86 and Icarus does.
  • $random(seed) updates its seed variable. The driver scans now count that write (SystemFunction::writes_argument). Without an argument, each process keeps its own seed starting at 0, so a design where only one process calls $random gets the same numbers as simulators that keep one seed for the whole design.
  • $urandom_range(maxval, minval = 0) (18.13.2) draws from the $urandom stream, swaps reversed bounds, and scales the number into the range. Scaling takes the offset from the high bits, because the low bits of the LCG have short periods.
  • All three random functions are rejected in constant-value contexts, as $urandom already was.

Testing

  • New shared cases: random_follows_annex_n_and_updates_its_seed, random_without_a_seed_continues_its_stream, urandom_range_stays_within_its_bounds.
    • Celox: pass on all backends.
    • Icarus 13.0: passes all three.
    • Verilator 5.052: fails the two $random cases because it doesn't implement Annex N. This is recorded as sv_verilator_random_algorithm, with the reproducer in verification/repros/sv_random.json.
  • cargo test -p celox-sv-analyzer -p celox-frontend-sv -p celox-test-suite
  • cargo test -p celox --features systemverilog --test systemverilog (2488 passed)
  • cargo clippy -p celox-sv-analyzer -p celox-frontend-sv --all-targets

$random follows the algorithm of IEEE 1800-2023 Annex N, computed with
integer operations that are exact for every seed, and updates its seed
variable; without an argument, each process continues its own seed from
0. $urandom_range draws from the $urandom stream and scales the number
into its inclusive bounds, swapping reversed bounds.

Add shared cases that Icarus Verilog passes, and record Verilator's
different $random algorithm as a reviewed limitation.
@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-17T01:00:27.699812Z 7df0ef7 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.

Record the reviewed Verilator exclusion of the two $random cases in its
retained report, restore "$random" in the exclusion reason, and accept
chapter-20/20.15--random.sv, which now passes.
Base automatically changed from feature/sv-systf-catalog to master October 17, 2026 02:04
@mergify

mergify Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

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

@tignear tignear added the merge-ready Request merging through Mergify after required checks label Oct 17, 2026
@mergify mergify Bot added the queued Mergify queue entry label Oct 17, 2026
@mergify

mergify Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-10-17 06:44 UTC · Rule: changes · triggered by rule Queue explicitly requested merges
  • ✅ Checks passed · on draft merge queue: checking #1396 on master (ab46a2f) #1413
  • ✅ Merged — 2026-10-17 07:40 UTC · at 4f309563e8e56e1c5360dbfc8bc4876c026f849c · merge

This pull request spent 56 minutes 32 seconds in the queue, including 54 minutes 44 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 mentioned this pull request Oct 17, 2026
39 of 70 tasks
@mergify
mergify Bot merged commit 4f30956 into master Oct 17, 2026
25 of 29 checks passed
@mergify
mergify Bot deleted the feature/sv-random branch October 17, 2026 07:40
@mergify mergify Bot removed the queued Mergify queue entry label Oct 17, 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.

1 participant