Repository navigation
feat(sv): support $random and $urandom_range - #1396
Merged
Merged
Conversation
$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.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
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.
Contributor
|
Queued — the merge queue status continues in this comment ↓. |
Contributor
Merge Queue Status
This pull request spent 56 minutes 32 seconds in the queue, including 54 minutes 44 seconds running CI. Required conditions to merge
|
39 of 70 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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-bitlong. 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 returnsLONG_MINas 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$randomgets the same numbers as simulators that keep one seed for the whole design.$urandom_range(maxval, minval = 0)(18.13.2) draws from the$urandomstream, 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.$urandomalready was.Testing
random_follows_annex_n_and_updates_its_seed,random_without_a_seed_continues_its_stream,urandom_range_stays_within_its_bounds.$randomcases because it doesn't implement Annex N. This is recorded assv_verilator_random_algorithm, with the reproducer inverification/repros/sv_random.json.cargo test -p celox-sv-analyzer -p celox-frontend-sv -p celox-test-suitecargo test -p celox --features systemverilog --test systemverilog(2488 passed)cargo clippy -p celox-sv-analyzer -p celox-frontend-sv --all-targets