Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dsp/tools: update satadd mixin
Browse files Browse the repository at this point in the history
jordens committed Jul 23, 2016

Verified

This commit was signed with the committer’s verified signature.
makenowjust Hiroya Fujinami
1 parent d83046d commit d928455
Showing 1 changed file with 13 additions and 16 deletions.
29 changes: 13 additions & 16 deletions artiq/gateware/dsp/tools.py
Original file line number Diff line number Diff line change
@@ -57,21 +57,18 @@ def eqh(a, b):
class SatAddMixin:
def sat_add(self, a):
a = list(a)
# assert all(len(a[0]) == len(ai) for ai in a)
# assert all(a[0].signed == ai.signed for ai in a)
assert all(ai.signed for ai in a)
n = max(len(ai) for ai in a)
o = log2_int(len(a))
o = log2_int(len(a), need_pow2=False)
s = Signal((n + o, True))
self.comb += s.eq(reduce(add, a))
if len(a) == 1:
return s
else:
s0 = Signal((n, True))
self.comb += [
If(s[-o:] == Replicate(s[-o-1], o),
s0.eq(s[:n]),
).Else(
s0.eq(Cat(Replicate(~s[-1], n - 1), s[-1])),
)
]
return s0
s0 = Signal((n, True))
self.comb += [
s.eq(reduce(add, a)),
s0[-1].eq(s[-1]),
If(s[-o-1:] == Replicate(s[-1], o + 1),
s0[:-1].eq(s[:n-1]),
).Else(
s0[:-1].eq(Replicate(~s[-1], n - 1)),
)
]
return s0

0 comments on commit d928455

Please sign in to comment.