From cccd01e81e4fed7aa224f36297ed26522c2baa50 Mon Sep 17 00:00:00 2001 From: Robert Jordens Date: Thu, 22 Jun 2017 01:35:17 +0800 Subject: [PATCH] sawg: cleanup sat_add logic --- artiq/gateware/dsp/tools.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/artiq/gateware/dsp/tools.py b/artiq/gateware/dsp/tools.py index 82eb30165..504c245c5 100644 --- a/artiq/gateware/dsp/tools.py +++ b/artiq/gateware/dsp/tools.py @@ -44,13 +44,15 @@ class SatAddMixin: full.eq(reduce(add, a)), ] if limits is None: + sign = Signal() 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), limited.eq(full), ).Else( - clip.eq(Cat(full[-1], ~full[-1])), - limited.eq(Cat(Replicate(~full[-1], length - 1), full[-1])), + clip.eq(Cat(sign, ~sign)), + limited.eq(Cat(Replicate(~sign, length - 1), sign)), ) ] else: