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

Left shift + simulator = infinite (?) loop #588

Closed
hellow554 opened this issue Feb 2, 2021 · 4 comments
Closed

Left shift + simulator = infinite (?) loop #588

hellow554 opened this issue Feb 2, 2021 · 4 comments

Comments

@hellow554
Copy link

The following code does not complete (at least not in 1 minute, so I call it infinite ;) )

from nmigen import *
from nmigen.sim import *

class A(Elaboratable):
    def elaborate(self, _):
        m = Module()
        a = Signal(32)
        b = Signal(32)
        z = Signal(32)
        m.d.comb += z.eq(a << b)
        return m

m = Module()
m.submodules.a = A()
sim = Simulator(m)

The problem seems to be the a << b operation.

@rroohhh
Copy link
Contributor

rroohhh commented Feb 2, 2021

@hellow554 It is simply very slow, as a << b generates a 4294967327 bit wide intermediate wire. Converting this to verilog / rtlil already catches this.

Maybe a similar check should be added to the simulator backend.

@hellow554
Copy link
Author

And a right shift is okay, because there are only 32 possible values?
So the solution would be to shorten b to e.g. 5 bits?

@rroohhh
Copy link
Contributor

rroohhh commented Feb 2, 2021

Yep

@whitequark
Copy link
Member

Yep, the manual has this note. We could probably add a similar check to pysim as to the RTLIL backend.

@whitequark whitequark added this to the 0.3 milestone Dec 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants