sawg: cleanup sat_add logic

This commit is contained in:
Robert Jördens 2017-06-22 01:35:17 +08:00 committed by Robert Jordens
parent 5f6e665158
commit cccd01e81e
1 changed files with 5 additions and 3 deletions

View File

@ -44,13 +44,15 @@ class SatAddMixin:
full.eq(reduce(add, a)), full.eq(reduce(add, a)),
] ]
if limits is None: if limits is None:
sign = Signal()
self.comb += [ self.comb += [
If(full[-1-carry:] == Replicate(full[-1], carry + 1), sign.eq(full[-1]),
If(full[-1-carry:] == Replicate(sign, carry + 1),
clip.eq(0), clip.eq(0),
limited.eq(full), limited.eq(full),
).Else( ).Else(
clip.eq(Cat(full[-1], ~full[-1])), clip.eq(Cat(sign, ~sign)),
limited.eq(Cat(Replicate(~full[-1], length - 1), full[-1])), limited.eq(Cat(Replicate(~sign, length - 1), sign)),
) )
] ]
else: else: