amaranth icon indicating copy to clipboard operation
amaranth copied to clipboard

Tighter bounds for integer negation of 1-bit signals

Open CatsAreFluffy opened this issue 2 months ago • 1 comments

>>> 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).

CatsAreFluffy avatar Oct 08 '25 02:10 CatsAreFluffy

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.

whitequark avatar Oct 12 '25 11:10 whitequark