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

Unused signal seems not to change #245

Closed
RobertBaruch opened this issue Oct 6, 2019 · 5 comments
Closed

Unused signal seems not to change #245

RobertBaruch opened this issue Oct 6, 2019 · 5 comments

Comments

@RobertBaruch
Copy link

Versions:

$ yosys -V
Yosys 0.9+932 (git sha1 10d0bad6, clang 6.0.0-1ubuntu2 -fPIC -Os)

$ pip3 show nmigen
Version: 0.1.dev700+g964c674

In this file, the signal unf is required to toggle on the negative clock, but doesn't, unless it is listed in the ports when calling main.

test_case.py:

from nmigen import *
from nmigen.cli import main
from nmigen.asserts import *


class TestCase(Elaboratable):
    def __init__(self):
        self.unf = Signal()
        self.value = Signal(4)

    def elaborate(self, platform):
        m = Module()
        m.d.pos += self.value.eq(self.value + 1)
        m.d.neg += self.unf.eq(~self.unf)
        return m


if __name__ == "__main__":
    clk = Signal()
    rst = Signal()

    pos = ClockDomain()
    pos.clk = clk
    pos.rst = rst

    neg = ClockDomain(clk_edge="neg")
    neg.clk = clk
    neg.rst = rst

    testcase = TestCase()

    m = Module()
    m.domains.pos = pos
    m.domains.neg = neg
    m.submodules.testcase = testcase

    count = Signal.range(0, 61, reset_less=True)

    with m.If(count < 60):
        m.d.pos += count.eq(count + 1)

    m.d.comb += Assume(rst == (count < 4))

    m.d.comb += Cover(testcase.value == 5)

    #    main(m, ports=[clk, rst, testcase.unf, testcase.value])
    main(m, ports=[clk, rst, testcase.value])

test_case.sby:

[tasks]
cover

[options]
cover: mode cover
cover: depth 61
multiclock on

[engines]
smtbmc boolector

[script]
read_ilang test_case.il
prep -top top

[files]
test_case.il

Running:

$ python3 test_case.py generate -t il > test_case.il
$ sby -f test_case.sby
$ gtkwave test_case_cover/engine_0/trace0.vcd

When unf is not in the list of ports:

unf_not_ported

When unf is in the list of ports:

unf_ported

This is very inconvenient, especially when you get down multiple levels of modules and some of the signals in the modules are for testing purposes, and need to be seen without having to port them out.

@whitequark
Copy link
Contributor

Yes. The RTLIL backend has intentionally never made any guarantees about the behavior of unused signals. But maybe that should be changed.

@whitequark
Copy link
Contributor

Actually, this case is a bit special: the signal is both read and written, so it's not really unused (it depends on itself). I am not sure why this happens.

@whitequark
Copy link
Contributor

I believe this is not an nMigen issue. As you can see, the RTLIL it emits contains your signal (edited for clarity):

(* \nmigen.hierarchy  = "top.testcase" *)
module testcase(value, clk, rst);
  (* src = "t.py:14" *)
  wire \$4 ;
  (* src = "t.py:19" *)
  input clk;
  (* src = "t.py:20" *)
  input rst;
  (* init = 1'h0 *)
  (* src = "t.py:8" *)
  reg unf = 1'h0;
  (* src = "t.py:8" *)
  reg \unf$next ;
  assign \$4  = ~ (* src = "t.py:14" *) unf;
  always @(negedge clk)
      unf <= \unf$next ;
  always @* begin
    \unf$next  = \$4 ;
    (* src = "/home/whitequark/Projects/nmigen/nmigen/hdl/xfrm.py:528" *)
    casez (rst)
      1'h1:
          \unf$next  = 1'h0;
    endcase
  end
endmodule

Can you please confirm, and raise the issue upstream?

@RobertBaruch
Copy link
Author

Submitted yosys issue 1441

@whitequark
Copy link
Contributor

Thanks. Closing as purely an upstream issue; will reopen if it turns out nMigen is involved.

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

No branches or pull requests

2 participants