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

Negative initialization produces incorrect verilog #142

Open
JohnSully opened this issue Oct 9, 2018 · 8 comments
Open

Negative initialization produces incorrect verilog #142

JohnSully opened this issue Oct 9, 2018 · 8 comments

Comments

@JohnSully
Copy link

Migen:
self.idx = Signal(max=depth, reset=-1)

Generated Verilog:
reg [3:0] sdram_bankmachine0_cmd_buffer_lookahead_idx = 4'd-1;

The assigned value should be -4'd1 instead to be valid Verilog. Not my favourite thing about the language.

@sbourdeauducq
Copy link
Member

sbourdeauducq commented Oct 9, 2018

Your signal must be signed for a negative value to be legitimate. Migen should print an error here instead of emitting invalid verilog, maybe at the minimum add an assert in _printconstant.

@sbourdeauducq
Copy link
Member

Though this isn't consistent with what happens when assigning a negative value to an unsigned signal; so maybe _printconstant should handle it.

@JohnSully
Copy link
Author

It's probably horrible practice, but I do it to set a signal to 0xFF regardless of its length. The rest of the code uses it unsigned.

@JohnSully
Copy link
Author

Signal(max=depth, ~0) produces the same incorrect code. What's the right way to initialize a signal to all 1s?

@sbourdeauducq
Copy link
Member

2**depth-1

@JohnSully
Copy link
Author

JohnSully commented Oct 9, 2018

I think it would have to be 2**(ceil(log2(depth))-1 right?

-1 or ~0 is much easier, and should be supported for this case in my opinion.

@sbourdeauducq
Copy link
Member

OK.
~0 == -1 in Python.

@whitequark
Copy link
Contributor

Triage: fixed in nMigen. In particular, ~0 and -1 initialization values for signed as well as unsigned signals produce the expected result.

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

3 participants