Skip to content

Commit

Permalink
fhdl/verilog: fix representation of negative integers
Browse files Browse the repository at this point in the history
Give the explicit two's complement representation for the given bit width.

This results in less readable code compared to using unary minus,
but fixes a bug when trying to represent the most negative integer.
  • Loading branch information
Sebastien Bourdeauducq committed Dec 11, 2013
1 parent d6cb981 commit 135a4fe
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion migen/fhdl/verilog.py
Expand Up @@ -27,7 +27,8 @@ def _printintbool(node):
if node >= 0:
return str(bits_for(node)) + "'d" + str(node), False
else:
return "-" + str(bits_for(node)) + "'sd" + str(-node), True
nbits = bits_for(node)
return str(nbits) + "'sd" + str(2**nbits + node), True
else:
raise TypeError

Expand Down

0 comments on commit 135a4fe

Please sign in to comment.