dsp/tools/SatAdd: fix reuse of clipped signal

This commit is contained in:
Robert Jördens 2017-06-21 14:32:36 +02:00
parent 4b3aad2563
commit 570f2cc1ff
1 changed files with 6 additions and 9 deletions

View File

@ -37,28 +37,25 @@ class SatAddMixin:
carry = log2_int(len(a), need_pow2=False) carry = log2_int(len(a), need_pow2=False)
full = Signal((length + carry, True)) full = Signal((length + carry, True))
limited = Signal((length, True)) limited = Signal((length, True))
if clipped is None: clip = Signal(2)
clipped = Signal(2) if clipped is not None:
self.comb += clipped.eq(clip)
self.comb += [ self.comb += [
full.eq(reduce(add, a)), full.eq(reduce(add, a)),
] ]
if limits is None: if limits is None:
self.comb += [ self.comb += [
If(full[-1-carry:] == Replicate(full[-1], carry + 1), If(full[-1-carry:] == Replicate(full[-1], carry + 1),
clip.eq(0),
limited.eq(full), limited.eq(full),
clipped.eq(0),
).Else( ).Else(
clip.eq(Cat(full[-1], ~full[-1])),
limited.eq(Cat(Replicate(~full[-1], length - 1), full[-1])), limited.eq(Cat(Replicate(~full[-1], length - 1), full[-1])),
clipped.eq(Cat(full[-1], ~full[-1])),
) )
] ]
else: else:
self.comb += [ self.comb += [
clip.eq(Cat(full < limits[0], full > limits[1])), clip.eq(Cat(full < limits[0], full > limits[1])),
Case(clip, { limited.eq(Array([full, limits[0], limits[1], 0])[clip]),
0b01, limited.eq(limits[0]),
0b10, limited.eq(limits[1]),
"default": limited.eq(full),
})
] ]
return limited return limited