Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 30 additions & 5 deletions crates/celox-frontend-sv/src/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5092,11 +5092,36 @@ fn lower_initial_processes(
.zip(slots)
.enumerate()
.map(|(index, ((process, random_seed), slots))| {
let kernel = ff::Ff::new(&mut pm, random_seed).lower_initial_kernel(
process.body(),
slots,
index,
)?;
// `always @(list) statement` waits for a change (IEEE 1800-2023
// 9.4.2). In two-state mode its outputs would then start as a
// real 0, so it runs once at time zero, after the time-zero
// statements of the initial blocks, before it waits, as
// Verilator settles it: `#0; forever begin statement; @(list); end`.
let settled;
let body = match process.level_sensitive().filter(|_| !four_state) {
Some((items, statements)) => {
let mut looped = statements.to_vec();
looped.push(sv::ir::Stmt::WaitEvent(items.to_vec()));
settled = [
sv::ir::Stmt::Delay {
amount: sv::ir::Expr::Literal("0".to_string()),
ticks_per_unit: 1,
ticks_per_precision: 1,
},
sv::ir::Stmt::Loop {
kind: sv::ir::LoopKind::Forever,
init: Vec::new(),
condition: None,
step: Vec::new(),
body: looped,
},
];
&settled[..]
}
None => process.body(),
};
let kernel =
ff::Ff::new(&mut pm, random_seed).lower_initial_kernel(body, slots, index)?;
wait_sites.extend(kernel.wait_sites);
nba_sites.extend(kernel.nba_sites);
nba_switches.extend(kernel.nba_switches);
Expand Down
12 changes: 9 additions & 3 deletions crates/celox-frontend-sv/src/lowering/ff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3950,6 +3950,11 @@ impl<'p, 'a> Ff<'p, 'a> {
arena: &mut SLTNodeArena<SourceVarId>,
) -> Result<Vec<LogicPath<SourceVarId>>, sv::AnalyzerError> {
let always_comb = kind != sv::ir::CombProcessKind::AlwaysStar;
// `always @*` and a sensitivity list wait for a change (IEEE
// 1800-2023 9.2.2.2). In two-state mode their outputs would then
// start as a real 0, so they run once at time zero, after the
// `initial` blocks, like `always_comb`, as Verilator settles them.
let runs_at_time_zero = always_comb || !self.m.four_state;
self.direct = true;
let mut reads = self.m.implicit_reads(body, always_comb);
reads.extend(self.m.implicit_reads(sensitivity_body, always_comb));
Expand Down Expand Up @@ -4113,7 +4118,7 @@ impl<'p, 'a> Ff<'p, 'a> {
counter_snapshots.push((counter, saved_counter));
}
let run = self.b.alloc_bit(1, false);
if always_comb {
if runs_at_time_zero {
let first = self.b.alloc_bit(1, false);
self.b
.emit(SIRInstruction::Unary(first, UnaryOp::LogicNot, init));
Expand Down Expand Up @@ -4227,7 +4232,7 @@ impl<'p, 'a> Ff<'p, 'a> {
target: LogicPathTarget::Process {
process: initialized,
sensitivity_counters: sensitivity_counters.clone(),
startup: (!always_comb).then(|| celox_slt::CombStartup {
startup: (!runs_at_time_zero).then(|| celox_slt::CombStartup {
initialized,
counters: counter_snapshots.clone(),
inputs: sources
Expand All @@ -4239,7 +4244,8 @@ impl<'p, 'a> Ff<'p, 'a> {
after_initials: matches!(
kind,
sv::ir::CombProcessKind::AlwaysComb | sv::ir::CombProcessKind::AlwaysLatch
),
) || (kind == sv::ir::CombProcessKind::AlwaysStar
&& !self.m.four_state),
target,
unit: Box::new(unit.clone()),
},
Expand Down
3 changes: 2 additions & 1 deletion crates/celox-test-suite/LIMITATIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ including its positive check that changing the argument does wake the procedures
The [standalone comparison](verification/repros/wildcard_task_sensitivity_verilator.json)
records both executions. Only this Verilator case is excluded for this reason.

The SystemVerilog suite's exclusions are listed in [`verification/sv/limitations.json`](verification/sv/limitations.json), with the failures observed before them in [`verification/sv/limitations/`](verification/sv/limitations). A case is excluded for a tool only when the expected value follows IEEE 1800 and the tool either cannot run the design or disagrees with the standard; where the two tools disagree with each other, the entry says so.
The SystemVerilog suite's exclusions are listed in [`verification/sv/limitations.json`](verification/sv/limitations.json), with the failures observed before them in [`verification/sv/limitations/`](verification/sv/limitations). A case is excluded for a tool only when the expected value follows IEEE 1800 and the tool either cannot run the design or disagrees with the standard; where the two tools disagree with each other, the entry says so. A case tagged with an expectation stronger than SV (see the [tag table](README.md)) may also be excluded for a tool whose state model cannot produce it.

The interface-array connection cases cover packed distribution, unpacked
connections and array ports, and multidimensional instance arrays (IEEE
Expand Down Expand Up @@ -541,6 +541,7 @@ four-state expectations; the assertions remain enabled on all Celox variants.
| `sv_icarus_unpacked_array_patterns` | compile | icarus | 1 | Icarus 13.0 reports that an assignment pattern with unpacked array items assigned to a multidimensional unpacked array is not yet supported ("Procedural assignment of array or array slice"), so the run cannot count it as a language rejection. The design is invalid (IEEE 1800-2023 7.6, 10.8). |
| `sv_icarus_display_field_width` | execute | icarus | 1 | Icarus 13.0 zero-pads a value wider than an explicit field width of %h or %o to the argument's full width (%3h of 32'h1234 prints 00001234); IEEE 1800-2023 21.2.1.2 expands the field to the value without leading zeros (1234). Verilator agrees with the expected value. |
| `sv_verilator_constant_unknown_bits` | execute | verilator | 1 | Verilator 5.052 is two-state: unknown bits in constant system function arguments ($onehot(2'bx1)) are not kept unknown, so a generate condition differs from IEEE 1800-2023 20.9. Icarus agrees with the expected values. |
| `sv_icarus_two_state_time_zero_settle` | execute | icarus | 2 | Icarus 13.0 simulates the emitted design in four-state SV, where `always @*` and a sensitivity-list process wait for a change (IEEE 1800-2023 9.2.2.2, 9.4.2), so an output whose inputs never change stays X. The case's two-state oracle follows Verilator 5.052, which runs these processes once at time zero after the initial blocks, as Celox's two-state mode does; a [standalone probe](verification/repros/sv_two_state_time_zero_settle.json) prints `1 ffff 1` in Verilator and `x xxxx x` in Icarus. |
| `sv_verilator_generate_case_unknown_label` | compile | verilator | 1 | Verilator 5.052 rejects an x or ? digit in a case-generate label ("no such thing as generate casez"). Icarus passes the case. |
| `sv_verilator_self_determined_index` | execute | verilator | 1 | Verilator 5.052 does not wrap a self-determined index expression (2'd3 + 2'd1) to its width before selecting; IEEE 1800-2023 11.5.1 and 11.6.1 make the index 0. Icarus agrees with the expected value. |
| `sv_verilator_short_circuit_calls` | execute | verilator | 1 | Verilator 5.052 runs a function call in the right operand of && in a select index when the left operand is false, so its output argument is written; IEEE 1800-2023 11.4.7 does not evaluate that operand. Icarus cannot compile the design (sv_icarus_function_outputs). |
Expand Down
1 change: 1 addition & 0 deletions crates/celox-test-suite/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ case still runs its original assertions by default.
| `eager_assertion_messages` | Veryl `$assert` / `$assert_continue` message argument effects occur even on success; these calls have no standard SV counterpart |
| `two_state_zero_division` | The suite's two-state model returns zero for division/remainder by zero, including four-state `logic` destinations in emitted SV (11.3.4, 11.4.3) |
| `two_state_initialization` | An explicit check of zero-initialized storage even for emitted four-state `logic` (6.8, Table 6-7) |
| `two_state_time_zero_settle` | Two-state `always @*` and sensitivity-list processes run once at time zero, after the initial blocks, as Verilator settles them, whereas SV has them wait for a change (9.2.2.2, 9.4.2) |

The initial review tags 21 cases; cases may carry multiple tags. Matching a
word such as `source_order` in a case name is insufficient: the two output
Expand Down
5 changes: 5 additions & 0 deletions crates/celox-test-suite/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ pub enum TestTag {
EagerAssertionMessages,
TwoStateZeroDivision,
TwoStateInitialization,
TwoStateTimeZeroSettle,
}

impl TestTag {
Expand All @@ -101,6 +102,7 @@ impl TestTag {
Self::EagerAssertionMessages => "eager_assertion_messages",
Self::TwoStateZeroDivision => "two_state_zero_division",
Self::TwoStateInitialization => "two_state_initialization",
Self::TwoStateTimeZeroSettle => "two_state_time_zero_settle",
}
}

Expand All @@ -125,6 +127,9 @@ impl TestTag {
Self::TwoStateInitialization => {
"Explicitly requires the suite's zero-initialized two-state storage even for emitted four-state logic; SV default initialization depends on the declared type (IEEE 1800-2023 6.8, Table 6-7)."
}
Self::TwoStateTimeZeroSettle => {
"Requires two-state `always @*` and sensitivity-list processes to run once at time zero, after the initial blocks, as Verilator settles them; SV has them wait for a change (IEEE 1800-2023 9.2.2.2, 9.4.2)."
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions crates/celox-test-suite/src/script/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ fn tag(name: &str, pos: Pos) -> Result<TestTag, ScriptError> {
"eager_assertion_messages" => TestTag::EagerAssertionMessages,
"two_state_zero_division" => TestTag::TwoStateZeroDivision,
"two_state_initialization" => TestTag::TwoStateInitialization,
"two_state_time_zero_settle" => TestTag::TwoStateTimeZeroSettle,
_ => return error(pos, format!("unknown tag `{name}`")),
})
}
Expand Down
63 changes: 63 additions & 0 deletions crates/celox-test-suite/src/sv/cases/always_comb.vtest
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,66 @@
(modify (set a 10))
(assert_eq y 15)
(assert_eq z 5))

; In two-state mode, `always @*` and a sensitivity list run once at time
; zero, after the initial blocks, as Verilator settles them: C906's memory
; enable would otherwise start as a real 0, a write enable (#2021). IEEE
; 1800-2023 9.2.2.2 has them wait for a change, which four-state mode keeps.
(case two_state_sensitivity_lists_run_at_time_zero
(tags two_state_time_zero_settle)
(source "time_zero.sv" #"
module Top;
localparam logic [1:0] READ = 2'd1;
logic [1:0] cur_state;
logic wvalid, wready;
logic [15:0] wstrb;
logic cen;
logic [15:0] wen;
logic [3:0] st = 4'd2;
logic hit;
always @(cur_state or wvalid or wready or wstrb[15:0]) begin
if (cur_state == READ) begin
cen = 1'b0;
wen = 16'hffff;
end else if (wvalid && wready) begin
cen = 1'b0;
wen = ~wstrb;
end else begin
cen = 1'b1;
wen = 16'hffff;
end
end
always @* hit = (st == 4'd2);
initial begin
#1 $display("%b %h %b", cen, wen, hit);
$finish;
end
endmodule
"#)
(top Top)
(run_to_finish)
(expect_output "1 ffff 1\n"))

; Two-state mode also runs a sensitivity list that does not name exactly the
; reads of its statement once at time zero, after the initial blocks, and then
; waits at it, as Verilator settles it (#2026): `y` lists a variable it does
; not read, and `z` reads `b` without listing it.
(case two_state_other_sensitivity_lists_run_at_time_zero
(tags two_state_time_zero_settle)
(source "time_zero_lists.sv" #"
module Top;
logic [3:0] a, b;
logic [3:0] y, z;
always @(a or b) y = a + 4'd1;
always @(a) z = a + b + 4'd2;
initial begin
b = 4'd5;
#1 $display("%0d %0d", y, z);
$finish;
end
endmodule
"#)
(top Top)
(run_to_finish)
(expect_output "1 7\n"))

12 changes: 12 additions & 0 deletions crates/celox-test-suite/src/sv/cases/latch.vtest
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ endmodule
(top Top)
(run_to_finish))

; `always @*` waits for a change in four-state mode only; two-state mode runs
; it at time zero (#2021).
(case classic_star_declaration_startup
(source "declaration_startup.sv" #"
module Top;
Expand All @@ -120,6 +122,7 @@ module Top;
endmodule
"#)
(top Top)
(four_state)
(run_to_finish))

(case classic_star_initial_startup
Expand Down Expand Up @@ -178,6 +181,8 @@ endmodule
(top Top)
(run_to_finish))

; `always @*` waits for a change in four-state mode only; two-state mode runs
; it at time zero (#2021).
(case same_activation_change_return
(source "change_return.sv" #"
module Top;
Expand All @@ -201,8 +206,11 @@ module Top;
endmodule
"#)
(top Top)
(four_state)
(run_to_finish))

; `always @*` waits for a change in four-state mode only; two-state mode runs
; it at time zero (#2021).
(case hierarchy_same_activation_change_return
(source "hierarchy_change_return.sv" #"
module Latch(input wire a, output wire [7:0] q);
Expand All @@ -224,6 +232,7 @@ module Top(output wire [7:0] q);
endmodule
"#)
(top Top)
(four_state)
(run_to_finish))

(case star_select_sensitivity
Expand All @@ -245,6 +254,8 @@ endmodule
(top Top)
(run_to_finish))

; `always @*` waits for a change in four-state mode only; two-state mode runs
; it at time zero (#2021).
(case star_complete_declaration_startup
(source "star_complete_declaration_startup.sv" #"
module Top;
Expand All @@ -260,6 +271,7 @@ module Top;
endmodule
"#)
(top Top)
(four_state)
(run_to_finish))

(case task_call_sensitivity
Expand Down
3 changes: 3 additions & 0 deletions crates/celox-test-suite/src/sv/cases/program.vtest
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
; A program's nonblocking assignment updates in the Re-NBA region, after the
; design's NBA region; the design processes the update wakes run in the
; active region set that follows.
; Four-state, so that `always @(r)` waits for a change; two-state mode would
; also run it once at time zero (#2026).
(case program_nonblocking_updates_follow_design_updates
(source "program_renba.sv" #"
module Top;
Expand All @@ -58,6 +60,7 @@
endprogram
"#)
(top Top)
(four_state)
(run_to_finish)
(expect_output "design sees r=1 count=0\nprogram count=1 r=1\ndesign sees r=11 count=1\nprogram count=2 r=11\ndesign sees r=12 count=2\n"))

Expand Down
9 changes: 7 additions & 2 deletions crates/celox-test-suite/src/sv/cases/timing.vtest
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,9 @@
(assert_eq y 9))

(case explicit_list_of_every_read_waits_for_a_change
; Like `always @*`, the list waits before its first run: neither the
; declaration initializers nor the write of `y` wake it (9.4.2).
; In four-state mode, like `always @*`, the list waits before its first
; run: neither the declaration initializers nor the write of `y` wake it
; (9.4.2). Two-state mode runs it at time zero (#2021).
(source "level_list.sv" #"
module Top(output logic [7:0] y);
logic [7:0] a = 8'd0;
Expand All @@ -187,6 +188,7 @@
endmodule
"#)
(top Top)
(four_state)
(run_until 1)
(assert_eq y 1)
(run_until 3)
Expand Down Expand Up @@ -217,6 +219,8 @@
(run_to_finish)
(assert_eq y 9))

; In four-state mode the list waits for a change; two-state mode also runs
; it once at time zero (#2026).
(case list_with_an_extra_signal_wakes_on_it
(source "extra_signal.sv" #"
module Top;
Expand All @@ -232,6 +236,7 @@
endmodule
"#)
(top Top)
(four_state)
(run_to_finish)
(expect_output "sum=3\nsum=3\n"))

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"standard": "IEEE 1800-2023 9.2.2.2 and 9.4.2",
"expected": "In four-state SV, `always @*` and a sensitivity-list process wait at their event control until an input changes, so an output whose inputs never change stays X. The suite case's two-state oracle follows Verilator, which runs these processes once at time zero after the initial blocks.",
"probes": [
{
"name": "time_zero_settle",
"note": "The suite case always_comb::two_state_sensitivity_lists_run_at_time_zero.",
"source": "module Top;\n localparam logic [1:0] READ = 2'd1;\n logic [1:0] cur_state;\n logic wvalid, wready;\n logic [15:0] wstrb;\n logic cen;\n logic [15:0] wen;\n logic [3:0] st = 4'd2;\n logic hit;\n always @(cur_state or wvalid or wready or wstrb[15:0]) begin\n if (cur_state == READ) begin\n cen = 1'b0;\n wen = 16'hffff;\n end else if (wvalid && wready) begin\n cen = 1'b0;\n wen = ~wstrb;\n end else begin\n cen = 1'b1;\n wen = 16'hffff;\n end\n end\n always @* hit = (st == 4'd2);\n initial begin\n #1 $display(\"%b %h %b\", cen, wen, hit);\n $finish;\n end\nendmodule\n",
"verilator_compile": {
"command": "verilator --binary --timing -Wno-fatal --top-module Top --Mdir <repro>/obj <repro>/probe.sv",
"exit_code": 0
},
"verilator_run": {
"command": "<repro>/obj/VTop",
"exit_code": 0,
"output": "1 ffff 1\n- <repro>/probe.sv:25: Verilog $finish\n- S i m u l a t i o n R e p o r t: Verilator 5.052 2026-09-05\n- Verilator: $finish at 1ps; walltime 0.000 s; speed 36.075 ns/s\n- Verilator: cpu 0.000 s on 1 threads; allocated 4 MB\n"
},
"icarus_compile": {
"command": "iverilog -g2012 -s Top -o <repro>/probe.vvp <repro>/probe.sv",
"exit_code": 0
},
"icarus_run": {
"command": "vvp <repro>/probe.vvp",
"exit_code": 0,
"output": "x xxxx x\n<repro>/probe.sv:25: $finish called at 1 (1s)\n"
}
},
{
"name": "other_lists",
"note": "The suite case always_comb::two_state_other_sensitivity_lists_run_at_time_zero: lists that do not name exactly the reads of their statement.",
"source": "module Top;\n logic [3:0] a, b;\n logic [3:0] y, z;\n always @(a or b) y = a + 4'd1;\n always @(a) z = a + b + 4'd2;\n initial begin\n b = 4'd5;\n #1 $display(\"%0d %0d\", y, z);\n $finish;\n end\nendmodule\n",
"verilator_compile": {
"command": "verilator --binary --timing -Wno-fatal --top-module Top --Mdir <repro>/obj <repro>/probe.sv",
"exit_code": 0
},
"verilator_run": {
"command": "<repro>/obj/VTop",
"exit_code": 0,
"output": "1 7\n- <repro>/probe.sv:9: Verilog $finish\n- S i m u l a t i o n R e p o r t: Verilator 5.052 2026-09-05\n- Verilator: $finish at 1ps; walltime 0.000 s; speed 37.509 ns/s\n- Verilator: cpu 0.000 s on 1 threads; allocated 4 MB\n"
},
"icarus_compile": {
"command": "iverilog -g2012 -s Top -o <repro>/probe.vvp <repro>/probe.sv",
"exit_code": 0
},
"icarus_run": {
"command": "vvp <repro>/probe.vvp",
"exit_code": 0,
"output": "x x\n<repro>/probe.sv:9: $finish called at 1 (1s)\n"
}
}
]
}
Loading
Loading