Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conditional assignment to a slice can generate invalid Verilog #717

Closed
daniestevez opened this issue Sep 23, 2022 · 3 comments
Closed

Conditional assignment to a slice can generate invalid Verilog #717

daniestevez opened this issue Sep 23, 2022 · 3 comments

Comments

@daniestevez
Copy link
Contributor

The following code

from amaranth import *
import amaranth.back.verilog

m = Module()
output = Signal(2)
enable = Signal()
with m.If(enable):
    m.d.comb += output[0].eq(1)

with open('test.v', 'w') as f:
    f.write(amaranth.back.verilog.convert(
        m, ports=[enable, output],
        emit_src=False))

generates this Verilog

/* Generated by Yosys 0.21+18 (git sha1 0ab726e20, clang 10.0.0-4ubuntu1 -fPIC -Os) */

(* \amaranth.hierarchy  = "top" *)
(* top =  1  *)
(* generator = "Amaranth" *)
module top(\output , enable);
  reg \$auto$verilog_backend.cc:2083:dump_module$1  = 0;
  input enable;
  wire enable;
  output [1:0] \output ;
  reg [1:0] \output ;
  always @* begin
    if (\$auto$verilog_backend.cc:2083:dump_module$1 ) begin end
    \output [0] = 1'h0;
    casez (enable)
      /* src = "/home/user/test.py:9" */
      1'h1:
          \output [0] = 1'h1;
    endcase
  end
  assign \output [1] = 1'h0;
endmodule

I think that this is invalid, because \output is a reg but there is a continuous assignment for \output[1] (Vivado rejects this code).

As a workaround, we can add

with m.If(enable):
    m.d.comb += output[1].eq(0)

which doesn't change the behaviour (because the reset value of output is zero) but makes the assign disappear from the Verilog output.

@whitequark
Copy link
Member

This is unfortunately an upstream Yosys bug that is quite difficult to address. I do have a plan for it but it's more long-term than anything.

@whitequark
Copy link
Member

whitequark commented Feb 27, 2024

Triage: still an issue with NIR on a586df8.

@whitequark
Copy link
Member

Will be fixed by YosysHQ/yosys#4314.

@whitequark whitequark added this to the 0.5 milestone Apr 3, 2024
@whitequark whitequark mentioned this issue Apr 3, 2024
77 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants