mirror of https://github.com/m-labs/artiq.git
dsp/tools: clean up SatAddMixin logic
This commit is contained in:
parent
f369cb97f7
commit
b6569df02f
|
@ -37,9 +37,8 @@ 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))
|
||||||
clip = Signal(2)
|
if clipped is None:
|
||||||
if clipped is not None:
|
clipped = Signal(2)
|
||||||
clipped.eq(clip)
|
|
||||||
self.comb += [
|
self.comb += [
|
||||||
full.eq(reduce(add, a)),
|
full.eq(reduce(add, a)),
|
||||||
]
|
]
|
||||||
|
@ -47,15 +46,19 @@ class SatAddMixin:
|
||||||
self.comb += [
|
self.comb += [
|
||||||
If(full[-1-carry:] == Replicate(full[-1], carry + 1),
|
If(full[-1-carry:] == Replicate(full[-1], carry + 1),
|
||||||
limited.eq(full),
|
limited.eq(full),
|
||||||
clip.eq(0),
|
clipped.eq(0),
|
||||||
).Else(
|
).Else(
|
||||||
limited.eq(Cat(Replicate(~full[-1], length - 1), full[-1])),
|
limited.eq(Cat(Replicate(~full[-1], length - 1), full[-1])),
|
||||||
clip.eq(Cat(full[-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])),
|
||||||
limited.eq(Array([full, limits[0], limits[1], 0])[clip]),
|
Case(clip, {
|
||||||
|
0b01, limited.eq(limits[0]),
|
||||||
|
0b10, limited.eq(limits[1]),
|
||||||
|
"default": limited.eq(full),
|
||||||
|
})
|
||||||
]
|
]
|
||||||
return limited
|
return limited
|
||||||
|
|
Loading…
Reference in New Issue