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

Any way to warn about & in if? #555

Closed
RobertBaruch opened this issue Dec 5, 2020 · 2 comments
Closed

Any way to warn about & in if? #555

RobertBaruch opened this issue Dec 5, 2020 · 2 comments

Comments

@RobertBaruch
Copy link
Contributor

After having used nMigen for many many months, I've found that one of my most common mistakes is doing this:

        with m.If(self._instr_phase == 0 & ~self._execute_trap):  # Oops, wrong precedence for & vs ==
            m.d.comb += self._load_instr.eq(1)

where instead I should do this:

        with m.If((self._instr_phase == 0) & ~self._execute_trap):
            m.d.comb += self._load_instr.eq(1)

I undestand why we can't use and, because there's no dunder for that. And I also understand that 0 & x can look just like 0xFFFE & x, where you meant to do that, so y == 0 & x might look the same as y == 0xFFFE & x.

I just wish there were some way of telling you that what you did might not be what you wanted. Just planting the thought.

@whitequark
Copy link
Member

#380?

@RobertBaruch
Copy link
Contributor Author

Closed as duplicate, will comment further in #380.

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