amaranth
amaranth copied to clipboard
Tighter bounds for integer negation of 1-bit signals
>>> from amaranth import *
>>> (-Signal(unsigned(1))).shape()
signed(2)
>>> (-Signal(signed(1))).shape()
signed(2)
The first one can be signed(1), and the second one can be unsigned(1).
In general, the Amaranth arithmetic rules are conservative; it was never the goal to compute the tightest possible bounds, only to compute correct bounds. Changing this requires an RFC per backwards compatibility statement; in particular the width calculation rules are exposed in the documentation so every additional bit of complexity will be a burden on every reader who wishes to understand them.