From af9e8a11fddf8572073a087f4c4abb344395879a Mon Sep 17 00:00:00 2001 From: tignear Date: Thu, 22 Oct 2026 11:10:30 +0900 Subject: [PATCH 1/2] test(sv): pin the rejections of unimplemented timing features Change-Id: I868d65d3f0f9527010f67146660ec5f9dd7025fb --- .../tests/frontends/systemverilog/timing.rs | 153 ++++++++++++++++++ 1 file changed, 153 insertions(+) diff --git a/crates/celox/tests/frontends/systemverilog/timing.rs b/crates/celox/tests/frontends/systemverilog/timing.rs index 2e76af89cd5..70aabb29492 100644 --- a/crates/celox/tests/frontends/systemverilog/timing.rs +++ b/crates/celox/tests/frontends/systemverilog/timing.rs @@ -330,3 +330,156 @@ fn event_expressions_with_effects_are_rejected() { assert!(error.contains(construct), "{event}: {error}"); } } + +/// Timing features Celox does not implement yet are rejected with a message +/// naming the construct and its tracking issue, instead of being ignored. +/// The comments name the issue that implements a feature when the message +/// still points to the roadmap. +#[test] +fn unimplemented_timing_features_are_rejected() { + for (body, construct, issue) in [ + ("bit a; initial @(a iff a);", "iff-qualified event", 1444), + ("initial fork #1; join", "fork-join block", 88), + ("initial fork #1; join_none", "fork-join block", 88), + // #1711 names the construct. + ( + "event e; initial -> e;", + "unsupported internal data type", + 88, + ), + ( + "bit a, b; initial a = #1 b;", + "intra-assignment timing control", + 88, + ), + ( + "bit a, b; initial a <= #1 b;", + "intra-assignment timing control", + 88, + ), + ( + "bit a, b, c; initial a = @(posedge c) b;", + "intra-assignment timing control", + 88, + ), + ("initial wait fork;", "wait fork statement", 88), + // #1711 names the construct. + ("initial disable fork;", "disable statement", 88), + ( + "bit a; task t(input bit x); wait (a ^ x); endtask initial t(0);", + "wait condition reading a static task argument", + 88, + ), + ( + "bit a; task t(input bit x); @(a ^ x); endtask initial t(0);", + "event expression reading a static task argument", + 88, + ), + ( + "bit a; function automatic bit f(); a = ~a; return a; endfunction initial @(f());", + "impure call `f` in an event expression", + 88, + ), + ( + "bit q; task t(); int s = 1; #1 q = s; endtask initial t();", + "static local in a timed task", + 88, + ), + ( + "bit a, y; assign #1 y = a;", + "delayed continuous assignment", + 444, + ), + // #1708: a plain `always` that is not a flip-flop runs as a process. + ( + "bit [3:0] v; int n; always @(posedge v[0]) n++;", + "always_ff event expression", + 464, + ), + ( + "bit [3:0] v; int n; always @(posedge v) n++;", + "multi-bit always_ff event signal", + 88, + ), + ( + "bit a, b; int n; always @(posedge a or posedge b) n <= n + 1;", + "always_ff event control", + 88, + ), + // #1709 + ( + "bit [7:0] m[4]; initial #1 m[1] <= 5;", + "nonblocking assignment to an unpacked array in a process", + 88, + ), + ( + "bit [3:0] q; int i = 2; initial #1 q[i] <= 1;", + "nonblocking assignment with a run-time position in a process", + 88, + ), + ( + "bit [3:0] q; initial #1 q[5] <= 1;", + "nonblocking assignment outside its target", + 88, + ), + // #1710 + ( + "bit q; task t(); #1 q = 1; endtask always @* t();", + "timed task call in a combinational process", + 88, + ), + ] { + let source = format!("module Top; {body} endmodule"); + let error = celox::Simulation::from_sv_sources( + vec![(source.as_str(), std::path::Path::new("unimplemented.sv"))], + "Top", + ) + .build() + .err() + .unwrap_or_else(|| panic!("`{body}` must be rejected")) + .to_string(); + // The report wraps long lines behind a `│` gutter. + let error = error + .split(|c: char| c.is_whitespace() || c == '│') + .filter(|word| !word.is_empty()) + .collect::>() + .join(" "); + assert!( + error.contains(&format!("[tracking issue #{issue}]")) + && error.contains(&format!("Unsupported SystemVerilog construct: {construct}")), + "{body}: {error}" + ); + } +} + +/// Only `initial` and `always` processes may suspend (IEEE 1800-2023 +/// 9.2.2.2, 9.2.2.4 and 13.4); a timing control elsewhere is an error. +#[test] +fn timing_controls_outside_suspendable_processes_are_rejected() { + for (body, construct) in [ + ( + "bit a, y; always_comb begin #1 y = a; end", + "delay control in an always_comb or always_ff body", + ), + ( + "bit clk, a, q; always_ff @(posedge clk) begin @(a); q <= a; end", + "event control in an always_comb or always_ff body", + ), + // #1711 reports this as illegal rather than unsupported. + ( + "bit a; function automatic bit f(); #1; return a; endfunction", + "delay control in a subroutine", + ), + ] { + let source = format!("module Top; {body} endmodule"); + let error = celox::Simulation::from_sv_sources( + vec![(source.as_str(), std::path::Path::new("outside.sv"))], + "Top", + ) + .build() + .err() + .unwrap_or_else(|| panic!("`{body}` must be rejected")) + .to_string(); + assert!(error.contains(construct), "{body}: {error}"); + } +} From c472fe99db3734dfdd3f8f2b6504ae55022edde0 Mon Sep 17 00:00:00 2001 From: tignear Date: Thu, 22 Oct 2026 11:10:30 +0900 Subject: [PATCH 2/2] docs(sv): document timing controls in processes Change-Id: I356155fb36b2b866435aee3872d4c67dda29963c --- docs/guide/systemverilog-reference.md | 62 +++++++++++++++++++++--- docs/guide/systemverilog.md | 18 ++++--- docs/ja/guide/systemverilog-reference.md | 57 +++++++++++++++++++--- docs/ja/guide/systemverilog.md | 16 +++--- 4 files changed, 126 insertions(+), 27 deletions(-) diff --git a/docs/guide/systemverilog-reference.md b/docs/guide/systemverilog-reference.md index 4f2bcd15a00..cbe8d605be0 100644 --- a/docs/guide/systemverilog-reference.md +++ b/docs/guide/systemverilog-reference.md @@ -42,14 +42,30 @@ synthesis and is tested at the design level. | Statements | `if` / `else`, `case`, `casez`, `casex`, `case ... inside`, `unique` / `priority`, `for`, `while`, `do ... while`, `repeat`, `forever` and `foreach` (unrolled when the trip count is constant, otherwise executed at run time), `break` / `continue` / `return`, immediate assertions | | Functions | `function` and `task` with `input`, `output` and `inout` arguments, `return` or assignment to the function name, local variables and `localparam`s, selected and composite assignments; calls are inlined. Calls with constant arguments in constant expressions (parameters, ranges) are evaluated during elaboration | +### Timing controls {#timing-controls} + +In a timed `Simulation`, `initial` and plain `always` processes can suspend: + +| Control | Supported | +| --- | --- | +| `#delay` | integral delays, `#(min:typ:max)` (the typical value) and [time literals](#time-literal-delays); an X or Z delay counts as zero | +| `@(...)` | variables, `posedge` / `negedge` / `edge`, items joined by `or` or `,`, bit, part and run-time index selects, any expression including calls of pure functions, and `@*` / `@(*)`, which waits on the variables its statement reads | +| `wait (condition)` | any condition; an X or Z condition counts as false | +| Assignments | blocking and nonblocking; nonblocking updates take effect in the NBA region of the time slot | + +An `always` with a sensitivity list other than `@*`, such as +`always @(a or b)`, runs as a process too. A `Simulator` runs no processes, +so such a design simulates without them there; use `Simulation`, or write +`always @*` or `always_comb` ([#1712](https://github.com/celox-sim/celox/issues/1712)). + ### Timed task calls An `initial` or ordinary `always` process can call tasks containing `#delay`, `@(event)` and `wait (condition)`, including through nested tasks. Calls are inlined into the caller's resumable state machine. A normal edge-sensitive `always` that calls a timed task waits for that task to return before rearming -its event control. Functions, `always_comb`, `always @*` and `always_ff` cannot -call a timed task. +its event control. Functions, `always_comb` and `always_ff` cannot call a timed +task, and `always @*` cannot yet ([#1710](https://github.com/celox-sim/celox/issues/1710)). Automatic task arguments and locals have separate storage for each activation and survive suspension. Module-local static task arguments remain shared. Inputs and inouts @@ -74,12 +90,12 @@ stream (IEEE 1800-2023 18.12). Constraints (`with`), class methods, enum variables, unpacked arrays, nets, constants, selects and concatenation arguments are unsupported and rejected. -### Time literal delays +### Time literal delays {#time-literal-delays} Standalone delay controls accept time literals such as `#5ns`, `#(2.75ns)` and `#40ps`, with all six units from `fs` to `s`. Values round at the declaring scope's precision before conversion to scheduler ticks (5.8, 3.14.1). Real-valued -arithmetic expressions remain unsupported. +delays are not supported yet ([#1707](https://github.com/celox-sim/celox/issues/1707)). ### Built-in functions and tasks @@ -103,10 +119,17 @@ it. The error carries the number of the issue that tracks the construct; constructs without a dedicated issue point to the frontend roadmap, [#88](https://github.com/celox-sim/celox/issues/88). - Classes. Timed tasks with static local declarations, recursive calls and `ref` arguments remain unsupported. -- Behavioral and verification constructs: `final`, intra-assignment timing controls, +- Behavioral and verification constructs: `final`, intra-assignment timing controls (`a = #1 b`), delayed continuous assignments ([#444](https://github.com/celox-sim/celox/issues/444)), - named events, `fork` / `join`, concurrent assertions, `force` / `release`. -- Nonblocking assignments inside `always_latch` ([#431](https://github.com/celox-sim/celox/issues/431)); use blocking assignments for the supported latch subset. Level-sensitive sensitivity lists other than `@*` are unsupported. + named events and `->`, `fork` / `join`, `wait fork` / `disable fork`, concurrent assertions, `force` / `release`. +- Timing controls in processes: `iff` qualifiers ([#1444](https://github.com/celox-sim/celox/issues/1444)), + real-valued delays ([#1707](https://github.com/celox-sim/celox/issues/1707)), package-scoped delay values + ([#1710](https://github.com/celox-sim/celox/issues/1710)), impure function calls in event expressions, and + `wait` or event expressions reading a static task argument. Nonblocking + assignments in a process cannot yet target an unpacked array element, a + run-time position or a constant position outside the target + ([#1709](https://github.com/celox-sim/celox/issues/1709)). +- Nonblocking assignments inside `always_latch` ([#431](https://github.com/celox-sim/celox/issues/431)); use blocking assignments for the supported latch subset. - Inferred latches inside `always_comb` are rejected by default. Set `inferred_latch = "warn"` or `"allow"` in `celox.toml` under `[diagnostics]` to permit retained blocking assignments. Ordinary `always @*` and explicit `always_latch` do not require this option. - Ports and instances: non-ANSI port declarations ([#426](https://github.com/celox-sim/celox/issues/426)), `ref` ports ([#427](https://github.com/celox-sim/celox/issues/427)), wildcard `.*` connections ([#442](https://github.com/celox-sim/celox/issues/442)), gate primitives ([#457](https://github.com/celox-sim/celox/issues/457)), @@ -115,7 +138,9 @@ constructs without a dedicated issue point to the frontend roadmap, [#88](https: array, ANSI port default values, tagged unions, soft packed unions, packed union assignment patterns, internal nets without a driver ([#460](https://github.com/celox-sim/celox/issues/460)), unpacked structs, strings and `real`. - Sequential processes: `iff` qualifiers ([#452](https://github.com/celox-sim/celox/issues/452)) and edge operands other than a - plain signal ([#464](https://github.com/celox-sim/celox/issues/464)) in event lists. + plain signal ([#464](https://github.com/celox-sim/celox/issues/464)) in event lists. A plain `always` with + such an edge, a multi-bit edge signal, or several edges without a reset is + rejected too, until it runs as a process ([#1708](https://github.com/celox-sim/celox/issues/1708)). - Combinational processes: nonblocking assignments inside `always_comb` ([#453](https://github.com/celox-sim/celox/issues/453)). - Loops: a procedural loop unrolls at most 10,000 iterations; a combinational @@ -290,6 +315,27 @@ their argument expressions (IEEE 1800-2023 9.4.2.2 and 9.2.2.2.1). Nonblocking latch assignments (`<=`) require NBA scheduling and remain unsupported, including when the inference option is enabled. +### Event and level waits {#timing-semantics} + +- An event control waits for a change that happens after it begins + (IEEE 1800-2023 9.4.2). In `a = 1; @(a ^ b);` the write to `a` is not an + event of the wait; the process resumes when `a` or `b` changes later. + Icarus 13.0 wakes on the earlier write; Verilator 5.052 agrees with Celox. +- `posedge` and `negedge` of a multi-bit expression follow its least + significant bit (Table 9-2): `@(posedge v)` ignores `v[3]`, and + `@(posedge v[3])` follows it. Transitions through X and Z count as in that + table, so `0` to `x` is a `posedge`. +- Continuous assignments, combinational processes and event expressions see + a process's writes when that process reaches a timing control or ends. + After `b = 1; a = 1;`, `a ^ b` has not changed, and a pulse + `a = 1; a = 0;` wakes `@(a)` but not `@(a ^ b)`; write `#0` between the + writes to make the pulse visible. IEEE 1800-2023 4.7 permits this order; + Icarus evaluates the expression at each write. +- A waiter does not yet see a value that one evaluation of `always_comb`, an + edge-triggered `always` or `always_ff` writes and then overwrites, as in + `y = 0; if (a) y = 1;` ([#1706](https://github.com/celox-sim/celox/issues/1706)). `always @*` already + reports that write. + ### Variable lifetimes Variable lifetimes follow IEEE 1800-2023 6.21. A variable declared in a diff --git a/docs/guide/systemverilog.md b/docs/guide/systemverilog.md index dea1c106dc5..7623b7ee719 100644 --- a/docs/guide/systemverilog.md +++ b/docs/guide/systemverilog.md @@ -55,14 +55,15 @@ compilation unit; choose the top by its SystemVerilog module name. | What your test needs | API | | --- | --- | | Set inputs, evaluate logic and advance clock events from Rust | `Simulator::from_sv_sources` | -| Advance simulation time and run supported `initial` processes | `Simulation::from_sv_sources` | +| Advance simulation time and run `initial` and `always` processes with timing controls | `Simulation::from_sv_sources` | | Include both Veryl and SystemVerilog sources | `Simulator::from_mixed_sources` | `Simulator::tick` drives the rising edge of the selected event. `Simulation` -tracks time and runs scheduled edges. Constant initialization applies to both; -`initial` blocks that read design state or call system tasks need `Simulation` -to execute as processes. Timing controls within SV `initial` blocks remain -restricted; see [unsupported constructs](./systemverilog-reference#what-is-not-supported). +tracks time and runs scheduled edges. Constant initialization applies to both. +`initial` blocks that read design state or call system tasks, processes with +timing controls and `always` blocks with a sensitivity list other than `@*` run +as processes and need `Simulation`; a `Simulator` does not run them +([#1712](https://github.com/celox-sim/celox/issues/1712)). Use `.four_state(true)` on the builder when your test needs X/Z values. The [4-state guide](./four-state) explains the state model. For time units, @@ -78,6 +79,7 @@ The main supported areas are: | Design structure | Modules, hierarchy, parameters, generate blocks, packages, interfaces and modports | | Data | Packed vectors, multidimensional packed arrays, structs, enums and unpacked memories | | RTL processes | `assign`, `always_comb`, `always @*`, blocking `always_latch`, edge-triggered `always` and `always_ff` | +| Timed processes | `initial` and `always` with `#delay` (also time literals such as `#5ns`), `@(...)` on variables, edges, selects, expressions and `@*`, `wait (...)`, nonblocking assignments and task calls with timing controls | | Computation | Arithmetic, selects, assignment patterns, branches, loops and functions | | Simulation helpers | Immediate assertions, display tasks, `$readmemh` / `$readmemb`, time queries and random numbers | @@ -89,7 +91,10 @@ ports, types, statements or system functions before porting a design. Common reasons a design needs changes are: -- Class-based verification, concurrent assertions and tasks with timing controls. +- Class-based verification and concurrent assertions. +- `fork` / `join`, named events, intra-assignment timing such as `a = #1 b`, + `iff` in event controls ([#1444](https://github.com/celox-sim/celox/issues/1444)) and real-valued delays + ([#1707](https://github.com/celox-sim/celox/issues/1707)). - Nonblocking latch assignments, multiple drivers and tri-state buses. Inferred latches in `always_comb` require `inferred_latch = "warn"` or `"allow"` in the common `[diagnostics]` configuration. - Non-ANSI module ports, wildcard `.*` connections, gate primitives and `bind`. - Strings, `real`, unpacked structs and several interface features. @@ -120,6 +125,7 @@ and the supported types and call sites. ## Find a specific behavior {#semantics-worth-knowing} - [Initialization, scopes, variable lifetimes and memory files](./systemverilog-reference#semantics-worth-knowing) +- [Event and level waits in processes](./systemverilog-reference#timing-semantics) - [Time units, precision and time queries](./systemverilog-reference#time-and-precision) - [Random seeds and reproducibility](./systemverilog-reference#random-numbers) diff --git a/docs/ja/guide/systemverilog-reference.md b/docs/ja/guide/systemverilog-reference.md index b7e4c3e542e..50ec446cad0 100644 --- a/docs/ja/guide/systemverilog-reference.md +++ b/docs/ja/guide/systemverilog-reference.md @@ -41,12 +41,29 @@ outline: [2, 3] | 文 | `if` / `else`、`case`、`casez`、`casex`、`case ... inside`、`unique` / `priority`、`for`、`while`、`do ... while`、`repeat`、`forever`、`foreach`(反復回数が定数なら展開し、そうでなければ実行時に実行)、`break` / `continue` / `return`、即時アサーション | | 関数 | `input` / `output` / `inout` 引数を持てる `function` と、`task`。`return`、または関数名への代入で値を返す。ローカル変数と `localparam`、部分選択や複合的な代入先への代入。呼び出しはインライン展開。定数式(パラメータ、範囲)の中の定数引数による呼び出しはエラボレーション時に評価 | +### タイミング制御 {#timing-controls} + +時間を持つ `Simulation` では、`initial` と通常の `always` のプロセスが中断できます。 + +| 制御 | 対応範囲 | +| --- | --- | +| `#delay` | 整数の遅延、`#(min:typ:max)`(typ の値)、[時間リテラル](#time-literal-delays)。X / Z の遅延は 0 として扱う | +| `@(...)` | 変数、`posedge` / `negedge` / `edge`、`or` または `,` で並べた項目、ビット選択・部分選択・実行時添字の選択、pure な関数呼び出しを含む任意の式、文が読む変数を待つ `@*` / `@(*)` | +| `wait (condition)` | 任意の条件。X / Z の条件は偽として扱う | +| 代入 | ブロッキング代入とノンブロッキング代入。ノンブロッキング代入はそのタイムスロットの NBA 領域で反映 | + +`always @(a or b)` のように `@*` 以外のセンシティビティリストを持つ `always` も +プロセスとして実行します。`Simulator` はプロセスを実行しないため、そこではこのプロセス抜きで +シミュレーションされます。`Simulation` を使うか、`always @*` / `always_comb` で記述してください +([#1712](https://github.com/celox-sim/celox/issues/1712))。 + ### 時間待ちを含む task `initial` と通常の `always` から、`#delay`・`@(event)`・`wait (condition)` を 含む task を呼び出せます。task のネストも可能です。呼び出しは呼び出し元の状態機械に インライン展開されます。エッジ待ちの `always` は task の完了後に次のエッジを待ちます。 -function・`always_comb`・`always @*`・`always_ff` からの時間待ち task 呼び出しは拒否します。 +function・`always_comb`・`always_ff` からの時間待ち task 呼び出しは拒否します。 +`always @*` からの呼び出しも現在は拒否します([#1710](https://github.com/celox-sim/celox/issues/1710))。 automatic な引数とローカル変数は呼び出しごとに独立し、中断中も保持されます。 module 内の static task の引数は共有されます。input/inout は呼び出し時にコピーされ、output/inout は @@ -67,11 +84,11 @@ package/`$unit` の static 引数を持つ時間待ち task と、static task `with` 制約、class メソッド、enum 変数、unpacked 配列、net、定数、 select・連結式の引数は未対応として拒否します。 -### 時間リテラルによる遅延 +### 時間リテラルによる遅延 {#time-literal-delays} 遅延制御の時間リテラルは `#5ns`、`#(2.75ns)`、`#40ps` など、`fs` から `s` の6単位に 対応します。宣言スコープの時間精度で丸めてから scheduler の tick に変換します -(5.8、3.14.1)。実数の算術式は引き続き未対応です。 +(5.8、3.14.1)。実数の遅延はまだ未対応です([#1707](https://github.com/celox-sim/celox/issues/1707))。 ### 組み込み関数とタスク @@ -97,15 +114,23 @@ SystemVerilog に対しても、共有の Veryl 適合性スイートを実行 - interface のポート、`inout` / `ref` / 式を使う modport、virtual interface など。 interface 自体と入れ子の interface は対応しています。型パラメータはインスタンスごとに解決し、modport ポート経由でも伝搬します。 再帰する特殊化と64段を超える入れ子は拒否します。細かな制約は[英語版の一覧](/guide/systemverilog-reference#interface-restrictions)を参照してください。 -- 振る舞い記述・検証向けの構文:`final`、代入内のタイミング制御、遅延付き継続代入([#444](https://github.com/celox-sim/celox/issues/444))、 - named event、`fork` / `join`、並行アサーション、`force` / `release`。 -- `always_latch` 内のノンブロッキング代入([#431](https://github.com/celox-sim/celox/issues/431))。対応するラッチではブロッキング代入を使用してください。`@*` 以外のレベルセンシティブなセンシティビティリストは未対応です。 +- 振る舞い記述・検証向けの構文:`final`、代入内のタイミング制御(`a = #1 b`)、遅延付き継続代入([#444](https://github.com/celox-sim/celox/issues/444))、 + named event と `->`、`fork` / `join`、`wait fork` / `disable fork`、並行アサーション、`force` / `release`。 +- プロセス内のタイミング制御:`iff` 修飾([#1444](https://github.com/celox-sim/celox/issues/1444))、 + 実数の遅延([#1707](https://github.com/celox-sim/celox/issues/1707))、package スコープの遅延値 + ([#1710](https://github.com/celox-sim/celox/issues/1710))、イベント式内の impure な関数呼び出し、 + static task 引数を読む `wait` 条件とイベント式。プロセス内のノンブロッキング代入は、 + unpacked 配列の要素、実行時に決まる位置、代入先の範囲外の定数位置をまだ代入先にできません + ([#1709](https://github.com/celox-sim/celox/issues/1709))。 +- `always_latch` 内のノンブロッキング代入([#431](https://github.com/celox-sim/celox/issues/431))。対応するラッチではブロッキング代入を使用してください。 - `always_comb` の暗黙のラッチ推論はデフォルトで拒否します。`celox.toml` の `[diagnostics]` で `inferred_latch = "warn"` または `"allow"` を指定すると許可できます。通常の `always @*` と明示的な `always_latch` にはこの設定は不要です。 - ポートとインスタンス:non-ANSI 形式のポート宣言([#426](https://github.com/celox-sim/celox/issues/426))、`ref` ポート([#427](https://github.com/celox-sim/celox/issues/427))、 ワイルドカード接続 `.*`([#442](https://github.com/celox-sim/celox/issues/442))、ゲートプリミティブ([#457](https://github.com/celox-sim/celox/issues/457))、`bind`。 - 宣言:interface 配列のメンバーの変数宣言の初期化子、ANSI ポートの既定値、tagged union、soft packed union、packed union の assignment pattern、ドライバを持たない内部ネット([#460](https://github.com/celox-sim/celox/issues/460))、unpacked 構造体、文字列、`real`。 - 順序回路のプロセス:イベントリストの `iff` 修飾([#452](https://github.com/celox-sim/celox/issues/452))と単純な信号以外のエッジ - オペランド([#464](https://github.com/celox-sim/celox/issues/464))。 + オペランド([#464](https://github.com/celox-sim/celox/issues/464))。このようなエッジ、複数ビットのエッジ信号、リセットを持たない + 複数のエッジを持つ通常の `always` も、プロセスとして実行できるようになるまで拒否します + ([#1708](https://github.com/celox-sim/celox/issues/1708))。 - 組み合わせ回路のプロセス:`always_comb` 内のノンブロッキング代入([#453](https://github.com/celox-sim/celox/issues/453))。 - ループ:手続き的なループの展開は 10,000 回までです。反復回数が実行時に決まる組み合わせ 回路のループは、カウンタ形式の `for` である必要があります。loop-generate は 10,000 回を @@ -216,6 +241,24 @@ Rust の `.allow_inferred_latches(true)` と JavaScript の `allowInferredLatche 感度に寄与します(IEEE 1800-2023 9.4.2.2、9.2.2.2.1)。 ノンブロッキング代入(`<=`)には NBA スケジューリングが必要であり、推論を許可しても未対応です。 +### イベント待ちとレベル待ち {#timing-semantics} + +- イベント制御は、開始した後に起きた変化を待ちます(IEEE 1800-2023 9.4.2)。 + `a = 1; @(a ^ b);` の `a` への書き込みはこの待ちのイベントにならず、 + その後に `a` か `b` が変化したときに再開します。 + Icarus 13.0 は先の書き込みで起床し、Verilator 5.052 は Celox と同じ結果になります。 +- 複数ビットの式の `posedge` / `negedge` は最下位ビットで判定します(Table 9-2)。 + `@(posedge v)` は `v[3]` を無視し、`@(posedge v[3])` は `v[3]` に従います。 + X / Z を経由する遷移も同表に従い、`0` から `x` は `posedge` です。 +- 継続代入、組み合わせ回路のプロセス、イベント式は、書き込んだプロセスがタイミング制御に + 達するか終了した時点でその書き込みを参照します。`b = 1; a = 1;` の後でも `a ^ b` は + 変化しておらず、パルス `a = 1; a = 0;` は `@(a)` を起こしますが `@(a ^ b)` は起こしません。 + パルスを見せるには書き込みの間に `#0` を入れてください。この順序は IEEE 1800-2023 4.7 で + 許されています。Icarus は書き込みごとに式を評価します。 +- `always_comb`、エッジで起動する `always`、`always_ff` の1回の評価の中で書いてから上書きした値 + (`y = 0; if (a) y = 1;` など)は、まだ待ち側から見えません + ([#1706](https://github.com/celox-sim/celox/issues/1706))。`always @*` ではすでに見えます。 + ### 変数の寿命 変数の寿命は IEEE 1800-2023 6.21 に従います。プロセスのブロック、関数、タスクの中で宣言した diff --git a/docs/ja/guide/systemverilog.md b/docs/ja/guide/systemverilog.md index 597911784a7..c341643e4eb 100644 --- a/docs/ja/guide/systemverilog.md +++ b/docs/ja/guide/systemverilog.md @@ -52,15 +52,15 @@ assert_eq!(sim.get(q), 1u8.into()); | テストで行いたいこと | API | | --- | --- | | Rust から入力を設定し、論理を評価してクロックイベントを進める | `Simulator::from_sv_sources` | -| シミュレーション時刻を進め、対応する `initial` プロセスを実行する | `Simulation::from_sv_sources` | +| シミュレーション時刻を進め、タイミング制御を持つ `initial` / `always` プロセスを実行する | `Simulation::from_sv_sources` | | Veryl と SystemVerilog のソースを一緒に扱う | `Simulator::from_mixed_sources` | `Simulator::tick` は指定イベントの立ち上がりエッジを駆動します。 `Simulation` は時刻を管理し、スケジュールされたエッジを実行します。 -定数による初期化はどちらにも適用されますが、デザインの状態を読む、またはシステムタスクを呼ぶ -`initial` ブロックをプロセスとして実行するには `Simulation` が必要です。 -SV の `initial` 内のタイミング制御には制約があるため、 -[未対応の構文](./systemverilog-reference#what-is-not-supported)も確認してください。 +定数による初期化はどちらにも適用されます。デザインの状態を読む、またはシステムタスクを呼ぶ +`initial` ブロック、タイミング制御を持つプロセス、`@*` 以外のセンシティビティリストを持つ +`always` はプロセスとして実行するため `Simulation` が必要です。`Simulator` はこれらを実行しません +([#1712](https://github.com/celox-sim/celox/issues/1712))。 X/Z を扱う場合は builder に `.four_state(true)` を指定します。 状態モデルは [4 値シミュレーション](./four-state)、時刻、`$stop`、メモリの読み込みなどは @@ -75,6 +75,7 @@ X/Z を扱う場合は builder に `.four_state(true)` を指定します。 | デザイン構造 | モジュール階層、パラメータ、generate、package、interface と modport | | データ | packed ベクタ、多次元 packed 配列、構造体、enum、unpacked メモリ | | RTL のプロセス | `assign`、`always_comb`、`always @*`、ブロッキング代入の `always_latch`、エッジで起動する `always` と `always_ff` | +| 時間を持つプロセス | `#delay`(`#5ns` などの時間リテラルを含む)、変数・エッジ・選択・式・`@*` に対する `@(...)`、`wait (...)`、ノンブロッキング代入、タイミング制御を持つ task 呼び出しを使う `initial` と `always` | | 演算と制御 | 算術、部分選択、assignment pattern、分岐、ループ、関数 | | シミュレーション補助 | 即時アサーション、表示タスク、`$readmemh` / `$readmemb`、時刻の取得、乱数 | @@ -85,7 +86,9 @@ X/Z を扱う場合は builder に `.four_state(true)` を指定します。 デザインの変更が必要になりやすいのは、次の機能です。 -- クラスを使う検証、並行アサーション、タイミング制御を持つ task。 +- クラスを使う検証、並行アサーション。 +- `fork` / `join`、named event、`a = #1 b` のような代入内のタイミング制御、 + イベント制御の `iff`([#1444](https://github.com/celox-sim/celox/issues/1444))、実数の遅延([#1707](https://github.com/celox-sim/celox/issues/1707))。 - ラッチ内のノンブロッキング代入、複数ドライバ、トライステートバス。`always_comb` の暗黙のラッチ推論は 共通の `[diagnostics]` 設定で `inferred_latch = "warn"` または `"allow"` を指定して許可します。 - 非 ANSI モジュールポート、ワイルドカード `.*` 接続、ゲートプリミティブ、`bind`。 - 文字列、`real`、unpacked 構造体、interface の一部の機能。 @@ -113,6 +116,7 @@ C と SV の型を一致させる必要があるため、どちらも `unsafe` A ## 個別の挙動を調べる {#知っておくべき挙動} - [初期化、スコープ、変数の寿命、メモリファイル](./systemverilog-reference#semantics-worth-knowing) +- [プロセス内のイベント待ちとレベル待ち](./systemverilog-reference#timing-semantics) - [時間単位、精度、時刻の取得](./systemverilog-reference#time-and-precision) - [乱数のシードと再現性](./systemverilog-reference#random-numbers)