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
3 changes: 2 additions & 1 deletion crates/celox-sv-analyzer/src/system_functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -748,10 +748,11 @@ impl StringOp {
}

/// The width and signedness of the result; a string is a 32-bit handle.
/// A character is a `byte`, which is signed (6.16, 6.11).
pub fn result_type(self) -> (usize, bool) {
match self {
Self::Compare | Self::ICompare | Self::Len | Self::Atoi(_) => (32, true),
Self::Getc => (8, false),
Self::Getc => (8, true),
_ => (32, false),
}
}
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 @@ -548,7 +548,7 @@ four-state expectations; the assertions remain enabled on all Celox variants.
| `sv_icarus_interface_array_connections` | compile | icarus | 3 | Icarus 13.0 rejects distributed unpacked actuals and multidimensional instances, and aborts on interface array ports. See the focused interface-array evidence above. |
| `sv_icarus_interfaces` | compile | icarus | 16 | Icarus 13.0 rejects interface port declarations (syntax error in port declarations), modport function imports ("sorry: modport task/function ports are not yet supported") and multidimensional interface instance arrays ("sorry: Multi-dimensional arrays of instances are not yet supported"). Verilator passes these cases. The implicit named interface cases have [focused pre-exclusion evidence](verification/sv/limitations/implicit-interface-ports-icarus.json). The mixed module-contract/local-interface case retains its [port-declaration diagnostics](verification/repros/sv_mixed_interface_connections_icarus.json). |
| `sv_icarus_packed_inner_index_range` | execute | icarus | 1 | Icarus 13.0 flattens an out-of-range inner index of a multidimensional packed array into the neighbouring element: a read gives a known value instead of X, and a write lands in that element; IEEE 1800-2023 7.4.6 and 11.5.1 make the select out of range. Verilator cannot check four-state values, and it truncates out-of-range packed indices. |
| `sv_icarus_string_methods` | compile | icarus | 3 | Icarus 13.0 does not implement the string methods getc, putc, compare, icompare, toupper, tolower, substr, atoi/atohex/atooct/atobin and itoa/hextoa/octtoa/bintoa ("Method getc is not a string method"), and requires a constant replication count for a string ("A reference to a net or variable is not allowed in a constant expression"). IEEE 1800-2023 6.16 defines the methods and 11.4.12.2 permits a non-constant count for a string replication. Verilator passes the cases. |
| `sv_icarus_string_methods` | compile | icarus | 4 | Icarus 13.0 does not implement the string methods getc, putc, compare, icompare, toupper, tolower, substr, atoi/atohex/atooct/atobin and itoa/hextoa/octtoa/bintoa ("Method getc is not a string method"), and requires a constant replication count for a string ("A reference to a net or variable is not allowed in a constant expression"). IEEE 1800-2023 6.16 defines the methods and 11.4.12.2 permits a non-constant count for a string replication. Verilator passes the cases. |
| `sv_icarus_unpacked_subroutine_ports` | compile | icarus | 2 | Icarus 13.0 reports that subroutine ports with unpacked dimensions are not yet supported. Verilator passes the valid case. |
| `sv_icarus_classes` | compile | icarus | 5 | Icarus 13.0 does not support extern methods ("sorry: External methods are not yet supported") or string methods called on a class property ("Can't find task itoa in class Named") or comparisons of class handles ("SORRY: Compare class handles not implemented"), aborts on a failed assertion in dup_expr.cc while compiling objects_referring_to_objects, and crashes with a segmentation fault while compiling implicit_constructors_and_this. IEEE 1800-2023 8.4, 8.7, 8.8 and 8.24 define these constructs. Verilator passes all but the string-method case, see sv_verilator_class_property_string_methods. |
| `sv_icarus_nested_class_members` | execute | icarus | 1 | Icarus 13.0 reads an empty string through a nested property path (kept.inner.text) after reporting "sorry: Nested member path not yet supported for class properties" for its assignment. IEEE 1800-2023 8.5 permits accessing a property of an object referred to by a property. Verilator passes the case. |
Expand Down Expand Up @@ -620,6 +620,7 @@ four-state expectations; the assertions remain enabled on all Celox variants.
| `sv_verilator_program_items` | compile | verilator | 2 | Verilator 5.052 rejects an `always` procedure and a module instance in a program with syntax errors, which the run cannot count as language rejections. Both are illegal (IEEE 1800-2023 24.3); Icarus 13.0 rejects them with diagnostics that name the rule. |
| `sv_icarus_iff_event_controls` | compile | icarus | 15 | Icarus 13.0 rejects `iff` in an event control with "syntax error" and "Malformed event control expression." IEEE 1800-2023 9.4.2.3 and A.6.5 permit `@(posedge clk iff en)`; [Standalone probe](verification/repros/sv_iff_event_controls_icarus.json); Verilator 5.052 runs the cases and gives the asserted counts. |
| `sv_verilator_iff_late_conditions` | execute | verilator | 4 | Verilator 5.052 judges an `iff` condition after the process that writes the event signal suspends, not at the write: with `clk = 1; en = 0;` from en = 1 it counts no event, with nonblocking updates `clk <= 1; en <= 0;` from en = 1 it counts none either, and an always_comb that writes `en = a; clk = a; en = 0;` gives no event of its `clk` write while `en` is 1. IEEE 1800-2023 9.4.2.3 judges the condition when the event occurs, and 10.4.2 applies nonblocking updates in issue order, so all three are events. [Standalone probes](verification/repros/sv_iff_late_conditions_verilator.json) print n=0, n=1 and n=0 in Verilator where the spec gives 1, 2 and 1; Icarus 13.0 rejects `iff` in event controls. |
| `sv_verilator_string_character_signedness` | execute | verilator | 1 | Verilator 5.052 reads a string character (`s[i]`, `s.getc(i)`) as unsigned, so code 255 converts to `int` 255. IEEE 1800-2023 6.16 makes a character a `byte`, which 6.11 makes signed (-1); xezim 0.11.3 agrees, Icarus 13.0 also reads 255. [Standalone probe](verification/repros/sv_string_character_signedness.json). |

The [system-function edge-case evidence](verification/repros/system_function_edge_cases.json)
retains the failed Icarus runs and minimal sources. Cover comparisons enable
Expand Down
19 changes: 19 additions & 0 deletions crates/celox-test-suite/src/sv/cases/string.vtest
Original file line number Diff line number Diff line change
Expand Up @@ -171,3 +171,22 @@ endmodule
"#)
(top Top) (run_until 0) (assert_eq done 1) (assert_eq same 1)
(expect_output "[a longer name] [ab] [a longer name] 13\n"))

; 6.16, 6.16.3: a character of a string is a `byte`, which is signed: a
; character code above 127 reads as a negative value.
(case characters_are_signed_bytes
(source "string_bytes.sv" #"
module Top(output bit done);
string s;
int n, m;
initial begin
s = {string'(8'hff), "A"};
n = s[0];
m = s.getc(0);
$display("%0d %0d %0d %0d %0d", n, m, s[0], s.getc(1), s[0] < 0);
done = 1;
end
endmodule
"#)
(top Top) (run_until 0) (assert_eq done 1)
(expect_output "-1 -1 -1 65 1\n"))
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"case": "string::characters_are_signed_bytes",
"source": "src/sv/cases/string.vtest",
"method": "Standalone source run with verilator --binary, iverilog -g2012 -s Top / vvp -n, and xezim -s Top.",
"standard": "IEEE 1800-2023 6.16: a single character of a string variable is of type byte; 6.11: byte is signed; 6.16.3: getc returns byte.",
"reduced_source": "module Top;\n string s;\n int n;\n initial begin\n s = {string'(8'hff), \"A\"};\n n = s[0];\n $display(\"%0d %0d %0d\", n, s[0], s[0] < 0);\n end\nendmodule\n",
"observations": [
{
"tool": "verilator",
"version": "Verilator 5.052 2026-09-05 rev v5.052",
"stdout": "255 255 0\n"
},
{
"tool": "icarus",
"version": "Icarus Verilog 13.0",
"stdout": "255 255 0\n",
"note": "The shared case also calls getc, which Icarus does not implement (sv_icarus_string_methods)."
},
{
"tool": "xezim",
"version": "xezim 0.11.3",
"stdout": "-1 -1 1\n"
},
{
"tool": "celox",
"stdout": "-1 -1 1\n"
}
]
}
23 changes: 23 additions & 0 deletions crates/celox-test-suite/verification/sv/icarus/string.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,29 @@
"tag_reasons": {},
"tags": []
},
{
"category": "Types",
"detail": "Icarus 13.0 does not implement the string methods getc, putc, compare, icompare, toupper, tolower, substr, atoi/atohex/atooct/atobin and itoa/hextoa/octtoa/bintoa (\"Method getc is not a string method\"), and requires a constant replication count for a string (\"A reference to a net or variable is not allowed in a constant expression\"). IEEE 1800-2023 6.16 defines the methods and 11.4.12.2 permits a non-constant count for a string replication. Verilator passes the cases.",
"expectation": "Simulation",
"known_issue": {
"category": "simulator_disagreement",
"evidence": [
"verification/sv/limitations/icarus.json",
"LIMITATIONS.md#systemverilog-suite"
],
"id": "sv_icarus_string_methods",
"observed_version": "Celox SV frontend; Verilator 5.052 / Icarus 13.0",
"phase": "compile",
"reason": "Icarus 13.0 does not implement the string methods getc, putc, compare, icompare, toupper, tolower, substr, atoi/atohex/atooct/atobin and itoa/hextoa/octtoa/bintoa (\"Method getc is not a string method\"), and requires a constant replication count for a string (\"A reference to a net or variable is not allowed in a constant expression\"). IEEE 1800-2023 6.16 defines the methods and 11.4.12.2 permits a non-constant count for a string replication. Verilator passes the cases.",
"upstream": []
},
"name": "string::characters_are_signed_bytes",
"phase": "skip",
"status": "ignored",
"stronger_than_sv": false,
"tag_reasons": {},
"tags": []
},
{
"category": "Types",
"detail": "",
Expand Down
20 changes: 19 additions & 1 deletion crates/celox-test-suite/verification/sv/limitations.json
Original file line number Diff line number Diff line change
Expand Up @@ -1805,7 +1805,8 @@
"icarus": [
"string::character_access",
"string::concatenation_and_replication",
"string::methods"
"string::methods",
"string::characters_are_signed_bytes"
]
}
},
Expand Down Expand Up @@ -2846,5 +2847,22 @@
"concurrent_assertions::disable_iff_after_nba"
]
}
},
{
"id": "sv_verilator_string_character_signedness",
"category": "simulator_disagreement",
"phase": "execute",
"observed_version": "Verilator 5.052 2026-09-05 rev v5.052",
"reason": "Verilator 5.052 reads a string character, s[i] and s.getc(i), as an unsigned 8-bit value: a character code of 255 converts to int 255 and compares greater than 0. IEEE 1800-2023 6.16 makes a character a byte and 6.11 makes byte signed, so the code reads as -1; xezim 0.11.3 agrees with the expected values and Icarus 13.0 also reads it as 255.",
"upstream": [],
"evidence": [
"verification/repros/sv_string_character_signedness.json",
"LIMITATIONS.md#systemverilog-suite"
],
"cases": {
"verilator": [
"string::characters_are_signed_bytes"
]
}
}
]
23 changes: 23 additions & 0 deletions crates/celox-test-suite/verification/sv/verilator/string.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,29 @@
"tag_reasons": {},
"tags": []
},
{
"category": "Types",
"detail": "Verilator 5.052 reads a string character, s[i] and s.getc(i), as an unsigned 8-bit value: a character code of 255 converts to int 255 and compares greater than 0. IEEE 1800-2023 6.16 makes a character a byte and 6.11 makes byte signed, so the code reads as -1; xezim 0.11.3 agrees with the expected values and Icarus 13.0 also reads it as 255.",
"expectation": "Simulation",
"known_issue": {
"category": "simulator_disagreement",
"evidence": [
"verification/repros/sv_string_character_signedness.json",
"LIMITATIONS.md#systemverilog-suite"
],
"id": "sv_verilator_string_character_signedness",
"observed_version": "Verilator 5.052 2026-09-05 rev v5.052",
"phase": "execute",
"reason": "Verilator 5.052 reads a string character, s[i] and s.getc(i), as an unsigned 8-bit value: a character code of 255 converts to int 255 and compares greater than 0. IEEE 1800-2023 6.16 makes a character a byte and 6.11 makes byte signed, so the code reads as -1; xezim 0.11.3 agrees with the expected values and Icarus 13.0 also reads it as 255.",
"upstream": []
},
"name": "string::characters_are_signed_bytes",
"phase": "skip",
"status": "ignored",
"stronger_than_sv": false,
"tag_reasons": {},
"tags": []
},
{
"category": "Types",
"detail": "",
Expand Down
11 changes: 11 additions & 0 deletions crates/celox-test-suite/verification/sv/xezim/string.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,17 @@
"tag_reasons": {},
"tags": []
},
{
"category": "Types",
"detail": "",
"expectation": "Simulation",
"name": "string::characters_are_signed_bytes",
"phase": "execute",
"status": "passed",
"stronger_than_sv": false,
"tag_reasons": {},
"tags": []
},
{
"category": "Types",
"detail": "",
Expand Down
1 change: 1 addition & 0 deletions crates/celox/tests/frontends/systemverilog/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ sv_backends! {
fn string_concatenation_and_replication(sim) { @case "string::concatenation_and_replication"; }
fn string_character_access(sim) { @case "string::character_access"; }
fn string_methods(sim) { @case "string::methods"; }
fn string_characters_are_signed_bytes(sim) { @case "string::characters_are_signed_bytes"; }
fn string_casts_from_integral_values(sim) { @case "string::casts_from_integral_values"; }
fn strings_across_clock_edges(sim) { @case "string::strings_across_clock_edges"; }
}
Expand Down
3 changes: 2 additions & 1 deletion docs/guide/systemverilog-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,8 @@ same as for a 32-bit integer; operations that read or build text call into the
runtime. Strings are collected between time slots and after each `tick`.
As IEEE 1800-2023 6.16 requires, NUL bytes are removed when text becomes a
string, and an integral value assigned or cast to a string contributes its
bytes from the most significant one.
bytes from the most significant one. A character read as `s[i]` or `s.getc(i)` is a `byte`,
which is signed (6.16, 6.11): a code above 127 reads as a negative value.

Not yet supported: `$sformat` / `$sformatf`, `atoreal` / `realtoa`, string
arguments of `$value$plusargs`, file I/O and DPI-C, and string values in VPI,
Expand Down
Loading