`.
-- `sim.tick()` advances the simulation by one clock cycle.
- Clock domains derived from that clock run in the same tick when their clock
- rises: a gated `clk & en` together with `clk`'s own domain, a
- register-driven divider after it. A tick is the clock's active edge only:
- domains clocked by its opposite edge, such as `~clk`, do not run.
+- `sim.tick()` advances the simulation by one clock period: the clock's
+ active edge, then its inactive edge. Every domain sensitive to either edge
+ runs, including clocks derived from it, such as a gated `clk & en`, a
+ register-driven divider or `~clk`. See
+ [Execution Semantics](./execution-semantics.md) for the SystemVerilog a
+ tick is equivalent to.
- `sim.dispose()` frees the native resources.
::: tip Combinational logic
@@ -65,9 +66,8 @@ For purely combinational modules (`always_comb` only), `tick()` is not required.
### Clock edges
-`tick()` stands for a clock's active edge and leaves the clock signal alone.
-When a design also reacts to the other edge, for example a register on `~clk`
-or on a falling `clk & en`, drive the edges themselves:
+`tick()` drives a whole clock period. To stop between the two edges, or to
+drive a reset, move the signals edge by edge:
```typescript
const clk = sim.event("clk");
@@ -76,7 +76,6 @@ sim.posedge(clk); // clk = 1: domains sensitive to its rising edge run
sim.negedge(clk); // clk = 0: domains sensitive to its falling edge run
sim.activeEdge(clk); // the clock's own edge: rising for a posedge clock
sim.inactiveEdge(clk); // the opposite edge
-sim.cycle(clk); // activeEdge(), then inactiveEdge()
// Several clocks at one instant: every domain samples the state before them.
sim.edges([
@@ -95,8 +94,8 @@ Veryl's abstract `clock` type, `activeEdge()` follows the build's clock type
(`clockType: "negedge"` makes it the falling edge). Reset ports work the same
way: `negedge(rst)` asserts an active-low asynchronous reset.
-`cycle()` gives the same results as two timed steps of the clock, a rising
-and a falling one.
+`tick()` is `activeEdge()` followed by `inactiveEdge()`, and gives the same
+results as two timed steps of the clock, a rising and a falling one.
## Time-Based Simulation
diff --git a/docs/internals/cascade-limitations.md b/docs/internals/cascade-limitations.md
index af32fc922d7..1c1913960f9 100644
--- a/docs/internals/cascade-limitations.md
+++ b/docs/internals/cascade-limitations.md
@@ -99,26 +99,22 @@ optimization and does not change the ordering model above.
## Event-based ticks
-`Simulator::tick` applies the same rules to one active edge of an event.
-Gated clocks of the event are judged from the state before the edge and
-evaluate with the ticked domain; after the commit, the rounds above run the
-domains whose clocks are computed from state and the gated clocks the commit
-moves. `Simulator::tick_events` does
-the same for coincident events, and the native testbench's `clock.next()` and
-the N-API `tick` use the same mechanism.
-
-A tick is the event's active edge only, without simulation time, and does not
-change the event's signal. Domains that react to the signal's opposite edge,
-such as one clocked by `~clk` or by a falling edge of `clk & en`, do not run on
-a tick; the timed `Simulation`, which drives both levels of a clock, runs them.
-
-`Simulator::posedge`, `negedge`, `active_edge`, `inactive_edge`, `cycle` and the
-coincident `edges` move the signal instead and apply the same rules to the
-transition they make, as a timed step does: the event's own domain runs on its
-active edge, gated clocks of either polarity are judged at the transition, and
-the signal stays at its new level. `cycle` is equivalent to the two timed
-steps of one clock period. The N-API handles and the WASM bridge of the
-TypeScript package use the same plans.
+`Simulator::posedge`, `negedge`, `active_edge`, `inactive_edge` and the
+coincident `edges` apply the same rules to the transition of an event signal
+they make, as a timed step does: the event's own domain runs on its active
+edge, gated clocks of either polarity are judged at the transition, and the
+signal stays at its new level. Gated clocks are judged from the state before
+the edge and evaluate with the event's own domain; after the commit, the
+rounds above run the domains whose clocks are computed from state and the
+gated clocks the commit moves.
+
+`Simulator::tick` is one clock period, the active edge followed by the
+inactive edge, and is equivalent to the two timed steps of that period;
+`Simulator::tick_events` does the same for coincident events, and the
+native testbench's `clock.next()` takes the same two edges. The
+[execution semantics](../guide/execution-semantics.md) define them by
+SystemVerilog. The N-API handles and the WASM bridge of the TypeScript
+package use the same plans.
Which derived domains an event can reach is computed once when the design is
built, together with a small program for each gate where its combinational
diff --git a/docs/ja/guide/execution-semantics.md b/docs/ja/guide/execution-semantics.md
new file mode 100644
index 00000000000..9959e4717c9
--- /dev/null
+++ b/docs/ja/guide/execution-semantics.md
@@ -0,0 +1,197 @@
+# 実行の意味論
+
+Celox のクロックを駆動する操作は IEEE 1800 のスケジューリングで定義されて
+います。イベントベースの `Simulator` では、ホストの各呼び出しが 1 つの
+タイムスロットで、その中で決まった SystemVerilog の文が実行されます。Veryl
+ネイティブテストベンチのクロック・リセットコンポーネントは、決まった
+SystemVerilog のコードです。そのコードを IEEE 1800 準拠のシミュレータで
+実行すると、Celox と同じ値が観測されます。
+
+以下のコードで、`s` はイベント(クロックまたはリセットのポート)の信号、
+`A` はそのアクティブレベル、`I` は非アクティブレベルです。`A` は
+立ち上がりエッジのクロックと active-high リセットで 1、立ち下がりエッジの
+クロックと active-low リセットで 0 です。Veryl の抽象 `clock` 型と `reset`
+型では、ビルドのクロック種別とリセット種別に従います。
+
+リセットの極性と同期・非同期は設計側の性質で、ここの規則には現れません。
+Veryl は `always_ff (clk, rst) { if_reset ... }` を、非同期 active-low
+リセットなら `always_ff @(posedge clk, negedge rst_n) if (!rst_n) ...`
+に、同期リセットなら `always_ff @(posedge clk) if (!rst_n) ...` に出力し、
+IEEE 1800 のスケジューラが信号の動きだけからそれぞれの振る舞いを作ります。
+
+## `Simulator` API
+
+`Simulator` にはシミュレーション時刻がありませんが、スケジューリングは
+IEEE 1800 のシミュレーションと同じです。ホストの各呼び出しは 1 つの
+タイムスロット(IEEE 1800-2023 4.4)です。呼び出しの文はそのスロットで
+実行され、スロットはすべての領域が空になるまで進み、次の呼び出しは後の
+スロットで始まります。呼び出しと呼び出しの間の読み出し(`get`、
+`sim.dut.x`)は、完了したスロットの状態を見ます。
+
+| 呼び出し | スロットの文 |
+|---|---|
+| `set(x, v)`、`sim.dut.x = v` | `x = v;` |
+| `edge(e, Rising)`、`posedge(e)` | `s <= 1;` |
+| `edge(e, Falling)`、`negedge(e)` | `s <= 0;` |
+| `active_edge(e)` / `inactive_edge(e)` | `s <= A;` / `s <= I;` |
+| `edges([(e1, l1), …, (ek, lk)])` | `s1 <= l1; … sk <= lk;` |
+| `tick(e)` | `s <= A;` そして次のスロットで `s <= I;` |
+| `tick(e, n)` | `tick(e)` を `n` 回 |
+| `tick_events([e1, …, ek])` | `s1 <= A1; … sk <= Ak;` そして次のスロットで `s1 <= I1; … sk <= Ik;` |
+
+ホストは設計内のプロセスではないので、上の表に遅延は現れません。スロットは
+設計が 1 つの文に応答する単位です。同じ列を SystemVerilog シミュレータで
+実行するには、文を 1 つの `initial` プロセスに並べ、各文の後に時間精度 1
+単位の遅延を置きます。`Simulator` は遅延を含む設計を受け付けないので、
+その単位の長さは観測できません。
+
+ここから次のことが従います。
+
+- tick はクロック 1 周期です。どちらかのエッジに反応するドメインはすべて
+ 実行されます。イベント自身のドメインはアクティブエッジで、逆エッジの
+ ドメイン(`@(negedge clk)`、`~clk` をクロックとするレジスタ)や
+ `clk & en` のように信号から計算されるクロックは、それぞれが見るエッジで
+ 実行されます。信号は非アクティブレベルで終わります。
+- すでにアクティブレベルにある信号では、`s <= A` は何も変えないので
+ アクティブエッジは起きません。2 値で 0 から始まる active-low リセットを
+ tick すると、解除されるだけです。リセットをアサートするには
+ `negedge(rst)` か `active_edge(rst)` を使います。
+- 1 つのスロットで起動されたドメインは、ノンブロッキング代入と同じく、
+ スロット前の状態をサンプルしてからまとめて更新します。複数クロックの
+ 同時エッジ(`edges`、`tick_events`)では、共有スロットの前の値を互いに
+ サンプルします。レジスタによる分周クロックのように、そのスロット自身が
+ 動かすクロックは、コミットの後にスロット内で立ち上がり、そのドメインも
+ 同じスロットで実行されます。
+- 4 値の設計では、不定レベルはどちらのレベルとしても扱われます。`x` から
+ 1 は立ち上がりエッジ、`x` から 0 は立ち下がりエッジです
+ (IEEE 1800-2023 Table 9-2)。
+
+`set` や `sim.dut` 経由の書き込みで、イベント信号や、それから計算される
+クロックを動かしてはいけません。Celox がドメインを実行するのは上の
+エッジ操作だけです。これらの信号は `edge` や `tick` とその派生で駆動して
+ください。
+
+### ホストからのリセット
+
+クロック `n` 周期のリセットは、リセットのアクティブエッジ、クロックの
+`n` 回の tick、リセットの非アクティブエッジです。
+
+```typescript
+sim.activeEdge(rst);
+sim.tick(clk, n);
+sim.inactiveEdge(rst);
+```
+
+非同期リセットのドメインは最初のスロットで、クロックエッジの前に実行
+されます。同期リセットは最初の tick でリセットされます。この列は、後述の
+テストベンチの `rst.assert(n)` と同じスロット列です。
+
+### 複数のクロック
+
+tick はそのイベントの 1 周期なので、2 つのクロック入力の位相関係は表せ
+ません。`clk` と、その 2 倍の周期をもつ `clk_half` のように周波数比のある
+クロックは、`edges` で瞬間ごとに駆動します。
+
+```typescript
+sim.edges([[clk, "posedge"], [clkHalf, "posedge"]]);
+sim.edges([[clk, "negedge"]]);
+sim.edges([[clk, "posedge"], [clkHalf, "negedge"]]);
+sim.edges([[clk, "negedge"]]);
+```
+
+または、入力ごとに `addClock` した timed
+[`Simulation`](./writing-tests.md#タイムベースシミュレーション) を使います。
+`tick_events([clk, clk_half])` と `tick(clk)` を交互に呼ぶ方法は、
+立ち上がりエッジだけを見るドメインに対してのみ同じ結果になります。
+`clk_half` が次の立ち上がりではなく `clk` の立ち下がりと同時に立ち下がる
+からです。
+
+## Veryl ネイティブテストベンチ
+
+Veryl テストベンチの initial ブロックは SystemVerilog の `initial`
+プロセスで、`$finish()` は `$finish` です。ホストと違い、これらの
+プロセスにはシミュレーション時刻があります。以下のコンポーネントは
+SystemVerilog のコードで、その遅延はテストベンチの時間です。
+
+### `$tb::clock_gen`
+
+`inst clk: $tb::clock_gen #(period: P);` は、待つプロセスがあるかどうかに
+かかわらず時刻 0 から動くクロック生成器です。`P` の既定値は 2 で、最小値も
+2 です。`H = ceil(P / 2)`、`L = floor(P / 2)` として:
+
+```systemverilog
+bit clk = 1'b0;
+initial forever begin
+ clk <= 1'b1; #H;
+ clk <= 1'b0; #L;
+end
+```
+
+### `clk.next(n)`
+
+```systemverilog
+task automatic clk_next(int unsigned n);
+ if (n != 0) begin
+ repeat (n) @(posedge clk);
+ #P;
+ end
+endtask
+```
+
+`clk.next()` は `clk.next(1)` です。
+
+- プロセスは、待っていた `n` 回目の立ち上がりエッジから 1 周期後、次の
+ 立ち上がりの直前に再開します。そのため、その周期の両エッジの後の状態を
+ 観測します。クロックは Low で、立ち下がりエッジのドメインは実行済みです。
+- クロックはノンブロッキング代入で立ち上がり、同じ時刻に再開した
+ プロセスの実行後に立ち上がります。そのため、2 つの `next` の間で
+ プロセスが書き込んだ値は、競合なく次の立ち上がりエッジでサンプルされます。
+- 複数の initial プロセスや周期の異なる複数のクロックに、追加の規則は
+ ありません。これらは並行する SystemVerilog のプロセスです。誰も待って
+ いないクロックも動き続け、そのドメインを駆動します。
+
+### `$tb::reset_gen`
+
+`inst rst: $tb::reset_gen #(cycles: C) (clk);` は、テストベンチの `reset`
+型のリセットネットで、時刻 0 から非アサート状態です。
+
+```systemverilog
+bit rst = I;
+```
+
+### `rst.assert(n)`
+
+`P` を生成器に渡したクロックの周期として:
+
+```systemverilog
+task automatic rst_assert(int unsigned n);
+ if (n == 0) n = 1;
+ rst = A;
+ repeat (n) @(posedge clk);
+ #P;
+ rst = I;
+endtask
+```
+
+`rst.assert()` は `rst.assert(C)` で、`C` の既定値は 3 です。
+
+- アサートは、他のテストベンチの書き込みと同じく、プロセスが到達した
+ 時点でのブロッキング書き込みです。非同期リセットのドメインは、クロック
+ エッジなしに、そのクロックが動いているかどうかにかかわらず、その瞬間に
+ 実行されます。同期リセットのドメインは次の立ち上がりエッジでリセット
+ されます。
+- レベルは `clk` の `n` 周期保持されます。次の立ち上がりエッジ、または
+ 同じ瞬間の立ち上がりエッジ(クロックはプロセスの書き込み後に立ち上がる
+ ため)から始まる `n` 回の立ち上がりエッジと、その最後のエッジの後の 1
+ 周期です。どちらの種類のリセットも `n` 回のリセットエッジを見て、
+ `n + 1` 回目のエッジの前に解除されます。
+- プロセスの再開とリセットの解除は、`next` が再開するのと同じ位相、つまり
+ 最後に待ったエッジから 1 周期後、次のエッジの直前です。その後の書き込みは
+ 競合なくそのエッジでサンプルされ、`rst.assert(n); clk.next(m);` は
+ `n + m` 周期です。
+- `rst.assert(0)` は `rst.assert(1)` です。アサートしたスロットで解除される
+ リセットは SystemVerilog ではグリッチなので、意味を与えません。
+
+このページが定義するのは `$tb::clock_gen`、`clk.next`、`$tb::reset_gen`、
+`rst.assert` です。他のテストベンチコンポーネント `$tb::file` と
+`$tb::random` はスケジューリングに関与しません。
diff --git a/docs/ja/guide/writing-tests.md b/docs/ja/guide/writing-tests.md
index 23152ebf14b..19b1c132a27 100644
--- a/docs/ja/guide/writing-tests.md
+++ b/docs/ja/guide/writing-tests.md
@@ -52,7 +52,7 @@ module Reg (
- `Simulator.create(Module)` は Veryl モジュール定義からシミュレータインスタンスを作成します。
- シグナル値は `sim.dut.<ポート名>` で読み書きします。
-- `sim.tick()` でシミュレーションを 1 クロックサイクル進めます。
+- `sim.tick()` でシミュレーションを 1 クロック周期進めます。クロックのアクティブエッジ、続いて非アクティブエッジで、どちらかに反応するドメインはすべて実行されます。tick と等価な SystemVerilog は[実行の意味論](./execution-semantics.md)を参照してください。
- `sim.dispose()` でネイティブリソースを解放します。
::: tip 組み合わせ回路の場合
diff --git a/packages/celox/src/simulator-edges-addon.test.ts b/packages/celox/src/simulator-edges-addon.test.ts
index 070265934d8..1b313a565c6 100644
--- a/packages/celox/src/simulator-edges-addon.test.ts
+++ b/packages/celox/src/simulator-edges-addon.test.ts
@@ -66,10 +66,11 @@ describe("explicit clock edges", () => {
sim.negedge(clk);
expect(counters()).toEqual([1n, 1n, 1n]);
sim.dut.en = 0n;
- sim.cycle(clk);
+ sim.tick(clk);
expect(counters()).toEqual([2n, 2n, 1n]);
+ sim.dut.en = 1n;
sim.tick(clk);
- expect(counters()).toEqual([3n, 2n, 1n]);
+ expect(counters()).toEqual([3n, 3n, 2n]);
} finally {
sim.dispose();
}
@@ -159,7 +160,7 @@ module Top (
reset(sim);
const observed = enables.map((enable) => {
sim.dut.en_in = enable;
- sim.cycle(clk);
+ sim.tick(clk);
return [sim.dut.a_out, sim.dut.b_out, sim.dut.d_out];
});
expect(observed).toEqual(expected);
diff --git a/packages/celox/src/simulator.ts b/packages/celox/src/simulator.ts
index d174b5f54df..73f761011e5 100644
--- a/packages/celox/src/simulator.ts
+++ b/packages/celox/src/simulator.ts
@@ -449,7 +449,13 @@ export class Simulator> {
}
/**
- * Trigger a clock edge.
+ * Run clock periods of an event's signal.
+ *
+ * One tick is the event's active edge, then its inactive edge: every
+ * domain sensitive to either runs, including domains of the opposite edge
+ * and clocks derived from the signal, and the signal ends at its inactive
+ * level. See the execution semantics guide for the SystemVerilog this is
+ * equivalent to.
*
* A single numeric argument is the tick count for the default event. When a
* second argument is not `undefined`, a numeric first argument is treated as
@@ -555,12 +561,6 @@ export class Simulator
> {
this.edges([[id, this.activeIsRising(id) ? "negedge" : "posedge"]]);
}
- /** One clock cycle: `activeEdge()`, then `inactiveEdge()`. */
- cycle(event?: EventHandle | number): void {
- this.activeEdge(event);
- this.inactiveEdge(event);
- }
-
/**
* Move several event signals at one instant. Every domain sensitive to
* one of the edges evaluates against the state before them, then all of
diff --git a/packages/celox/src/wasm-bridge.ts b/packages/celox/src/wasm-bridge.ts
index b5810fcaca4..f3d5aeb6182 100644
--- a/packages/celox/src/wasm-bridge.ts
+++ b/packages/celox/src/wasm-bridge.ts
@@ -263,7 +263,7 @@ export function createWasmSimulatorBridge(
);
const handle: NativeSimulatorHandle = {
tick(eventId: number): void {
- if (edges?.hasDerived(eventId)) {
+ if (edges) {
edges.tick(eventId);
return;
}
@@ -345,7 +345,7 @@ export async function createWasmSimulatorBridgeAsync(
);
const handle: NativeSimulatorHandle = {
tick(eventId: number): void {
- if (edges?.hasDerived(eventId)) {
+ if (edges) {
edges.tick(eventId);
return;
}
diff --git a/packages/celox/src/wasm-edges.test.ts b/packages/celox/src/wasm-edges.test.ts
index e82a48d3c38..8968c0daf7c 100644
--- a/packages/celox/src/wasm-edges.test.ts
+++ b/packages/celox/src/wasm-edges.test.ts
@@ -143,28 +143,28 @@ test("the WASM bridge ticks and moves clocks as the native simulator does", () =
sharedMemory[EN] = 1;
handle.evalComb();
- // A tick is the active edge only: the gate passes it, `~clk` does not
- // rise, and `clk` stays low.
+ // A tick is a clock period: the gate passes its rising edge, `~clk`
+ // rises on its falling edge, and `clk` ends low.
handle.tick(0);
- expect(counters()).toEqual([1, 1, 0]);
+ expect(counters()).toEqual([1, 1, 1]);
expect(sharedMemory[CLK]).toBe(0);
expect(handle.activeEdgeIsRising?.(0)).toBe(true);
expect(handle.edges?.([0], [true])).toBe(true);
- expect(counters()).toEqual([2, 2, 0]);
+ expect(counters()).toEqual([2, 2, 1]);
expect(sharedMemory[CLK]).toBe(1);
// Already high: no edge.
handle.edges?.([0], [true]);
- expect(counters()).toEqual([2, 2, 0]);
- handle.edges?.([0], [false]);
expect(counters()).toEqual([2, 2, 1]);
+ handle.edges?.([0], [false]);
+ expect(counters()).toEqual([2, 2, 2]);
// A closed gate passes no edge.
sharedMemory[EN] = 0;
handle.evalComb();
handle.edges?.([0], [true]);
handle.edges?.([0], [false]);
- expect(counters()).toEqual([3, 2, 2]);
+ expect(counters()).toEqual([3, 2, 3]);
});
test("a bridge without edge plans keeps the plain tick", () => {
diff --git a/packages/celox/src/wasm-edges.ts b/packages/celox/src/wasm-edges.ts
index 9e4c1cc966a..6a088098cda 100644
--- a/packages/celox/src/wasm-edges.ts
+++ b/packages/celox/src/wasm-edges.ts
@@ -13,8 +13,8 @@
* - After the commit, every domain whose clock then moved to its active edge
* runs, in rounds, until no further edge appears: domains clocked from
* state, and gates the commit moved.
- * - `tick` is the event's active edge without moving its signal. An edge
- * moves the signal and leaves it at its new level.
+ * - An edge moves the signal and leaves it at its new level. `tick` is a
+ * clock period: the active edge, then the inactive edge.
*
* Gates are judged by settling the design with the signal at each level.
*
@@ -180,31 +180,22 @@ export class WasmEdgeRunner {
return this.plan(eventId)?.edge !== "negedge";
}
- /** The event's active edge without moving its signal, as `tick`. */
+ /** A clock period of the event's signal, as `tick`. */
tick(eventId: number): void {
const name = this.name(eventId);
const plan = this.plan(eventId);
- if (!plan || !this.hasDerived(eventId)) {
+ if (!plan) {
this.evalComb();
this.kernels(name)?.evalApply();
this.evalComb();
return;
}
- const active = plan.edge === "negedge" ? 0 : 1;
- const levers: Lever[] =
- plan.gated.length > 0
- ? [{ signal: plan.signal, from: active ^ 1, to: active }]
- : [];
- this.run(
- [name],
- plan.domains,
- plan.gated.map((g) => [g, 0]),
- levers,
- {
- settle: true,
- persist: false,
- },
- );
+ const rising = plan.edge !== "negedge";
+ let settled = this.edges([eventId], [rising]);
+ settled = this.edges([eventId], [!rising], !settled);
+ if (!settled) {
+ this.evalComb();
+ }
}
/**
diff --git a/packages/playground/src/playground-simulator.ts b/packages/playground/src/playground-simulator.ts
index 1fd89e7e534..30f42e11848 100644
--- a/packages/playground/src/playground-simulator.ts
+++ b/packages/playground/src/playground-simulator.ts
@@ -106,7 +106,7 @@ class PlaygroundInstance {
if (this.dirty) this.evalComb();
}
- /** The event's active edge without moving its signal, as `tick`. */
+ /** A clock period of the event's signal, as `tick`. */
tickOne(eventId: number): void {
this.runner.tick(eventId);
this.dirty = false;
@@ -269,11 +269,6 @@ export function createPlaygroundSimulator(
const id = resolveEventId(event);
sim.edges([[id, design.activeIsRising(id) ? "negedge" : "posedge"]]);
},
- /** One clock cycle: `activeEdge()`, then `inactiveEdge()`. */
- cycle(event?: PlaygroundEvent) {
- sim.activeEdge(event);
- sim.inactiveEdge(event);
- },
event(name: string): PlaygroundEventHandle {
return { name, id: design.resolveEvent(name) };
},
diff --git a/packages/playground/test/playground-dts.test.ts b/packages/playground/test/playground-dts.test.ts
index 87ea9c8ce94..a70e9f7b1f4 100644
--- a/packages/playground/test/playground-dts.test.ts
+++ b/packages/playground/test/playground-dts.test.ts
@@ -45,7 +45,7 @@ describe("celox declarations for Monaco", () => {
"negedge(",
"activeEdge(",
"inactiveEdge(",
- "cycle(",
+ "tick(",
"edges(",
]) {
expect(simulator?.content).toContain(method);
diff --git a/packages/playground/test/playground-simulator-wasm.test.ts b/packages/playground/test/playground-simulator-wasm.test.ts
index 985912eb06a..a0817dce6a8 100644
--- a/packages/playground/test/playground-simulator-wasm.test.ts
+++ b/packages/playground/test/playground-simulator-wasm.test.ts
@@ -95,20 +95,20 @@ describe.skipIf(!isWasm)("playground runtime (WASM)", () => {
expect(counts()).toEqual([1, 0, 1, 1]);
sim.negedge(clk);
expect(counts()).toEqual([1, 1, 1, 1]);
- sim.cycle(clk);
+ // A tick is a clock period: both edges of the clock.
+ sim.tick(clk);
expect(counts()).toEqual([2, 2, 2, 1]);
- // A tick is the active edge without moving the clock.
sim.tick(clk);
- expect(counts()).toEqual([3, 2, 3, 2]);
+ expect(counts()).toEqual([3, 3, 3, 2]);
sim.dut.en = 0n;
- sim.cycle(clk);
- expect(counts()).toEqual([4, 3, 3, 2]);
+ sim.tick(clk);
+ expect(counts()).toEqual([4, 4, 3, 2]);
// The clock is already at its inactive level: no edge.
sim.inactiveEdge(clk);
- expect(counts()).toEqual([4, 3, 3, 2]);
+ expect(counts()).toEqual([4, 4, 3, 2]);
sim.activeEdge();
sim.edges([[clk, "negedge"]]);
- expect(counts()).toEqual([5, 4, 3, 3]);
+ expect(counts()).toEqual([5, 5, 3, 3]);
expect(() => sim.edges([[clk, "sideways" as "posedge"]])).toThrow(
RangeError,
);
@@ -118,8 +118,8 @@ describe.skipIf(!isWasm)("playground runtime (WASM)", () => {
const sim = createPlaygroundSimulator(compile(LEVER, "Lever"));
const clk = sim.event("clk");
sim.dut.en = 1n;
- sim.cycle(clk);
- sim.cycle(clk);
+ sim.tick(clk);
+ sim.tick(clk);
expect(sim.dut.count).toBe(2n);
sim.tick(clk);
expect(sim.dut.count).toBe(3n);
@@ -129,7 +129,7 @@ describe.skipIf(!isWasm)("playground runtime (WASM)", () => {
const sim = Simulator.fromSource(LEVER, "Lever");
const clk = sim.event("clk");
sim.dut.en = 1n;
- sim.cycle(clk);
+ sim.tick(clk);
sim.tick(clk);
expect(sim.dut.count).toBe(2n);
sim.dispose();