Skip to content

verilog backend: preserve signed on wire and port declarations#5880

Open
alaindargelas wants to merge 1 commit into
YosysHQ:mainfrom
alainmarcel:write-verilog-signed-port
Open

verilog backend: preserve signed on wire and port declarations#5880
alaindargelas wants to merge 1 commit into
YosysHQ:mainfrom
alainmarcel:write-verilog-signed-port

Conversation

@alaindargelas
Copy link
Copy Markdown

dump_wire had no code path that emits the signed keyword for wires/ports whose RTLIL is_signed flag is set. Reading

module top(input signed [9:0] in, output signed [31:0] o);
assign o = in;
endmodule

and writing it back via write_verilog produced

input [9:0] in;
output [31:0] o;

losing the declared signedness even though wire->is_signed was tracked correctly in RTLIL throughout the round trip. The IEEE 1364-2001 grammar (Annex A.2.1.2 / A.2.1.3) allows signed after the direction / net-type keyword, which is the dialect write_verilog targets by default — so the fix is to emit signed between the direction/net-type and the range when wire->is_signed.

Closes the half of chipsalliance/synlig#2425 that lives in Yosys: the SystemVerilog frontend correctly produces a signed wire for output int, but the Verilog backend dropped it on write.

Adds tests/various/write_verilog_signed_port.ys, which round-trips a module with signed inputs, outputs, and an internal wire and greps for the keyword on each declaration — fails without the fix, passes with it.

If your work is part of a larger effort, please discuss your general plans on Discourse first to align your vision with maintainers.

What are the reasons/motivation for this change?

Explain how this is achieved.

Make sure your change comes with tests. If not possible, share how a reviewer might evaluate it.

These template prompts can be deleted when you're done responding to them.

`dump_wire` had no code path that emits the `signed` keyword for
wires/ports whose RTLIL `is_signed` flag is set.  Reading

  module top(input signed [9:0] in, output signed [31:0] o);
    assign o = in;
  endmodule

and writing it back via `write_verilog` produced

  input  [9:0]  in;
  output [31:0] o;

losing the declared signedness even though `wire->is_signed` was
tracked correctly in RTLIL throughout the round trip.  The IEEE
1364-2001 grammar (Annex A.2.1.2 / A.2.1.3) allows `signed` after the
direction / net-type keyword, which is the dialect `write_verilog`
targets by default — so the fix is to emit ` signed` between the
direction/net-type and the range when `wire->is_signed`.

Closes the half of chipsalliance/synlig#2425 that lives in Yosys: the
SystemVerilog frontend correctly produces a signed wire for `output int`,
but the Verilog backend dropped it on write.

Adds `tests/various/write_verilog_signed_port.ys`, which round-trips a
module with `signed` inputs, outputs, and an internal wire and greps
for the keyword on each declaration — fails without the fix, passes
with it.
@widlarizer
Copy link
Copy Markdown
Collaborator

@Goubermouche does #5771 cover this too?

@widlarizer widlarizer self-requested a review May 13, 2026 08:17
@widlarizer widlarizer self-assigned this May 13, 2026
@Goubermouche
Copy link
Copy Markdown
Contributor

@widlarizer Seems like it, the provided test cases passes under #5771 too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants