55# Note: Migen translates the "out of range" pc mux selector to the last valid mux input.
66
77from ast import Constant
8-
98from migen import *
109
1110N_COEFF = 3 # [b0, b1, a1] number of coefficients for a first order iir
@@ -16,9 +15,9 @@ def __init__(self):
1615 # xilinx dsp architecture (subset)
1716 self .a = a = Signal ((25 , True ), reset_less = True )
1817 self .b = b = Signal ((18 , True ), reset_less = True )
19- self .c = c = Signal ((len ( a ) + len ( b ) , True ), reset_less = True )
18+ self .c = c = Signal ((41 , True ), reset_less = True )
2019 self .mux_p = mux_p = Signal () # accumulator mux
21- self .m = m = Signal ((len ( a ) + len ( b ) , True ), reset_less = True )
20+ self .m = m = Signal ((43 , True ), reset_less = True )
2221 self .p = p = Signal ((48 , True ), reset_less = True )
2322 self .sync += [m .eq (a * b ), p .eq (m + c ), If (mux_p , p .eq (m + p ))]
2423
@@ -78,7 +77,7 @@ def __init__(self, w_coeff, w_data, log2_a0, n_profiles, n_channels):
7877 self .submodules .dsp = dsp = Dsp ()
7978 assert w_data <= len (dsp .b )
8079 assert w_coeff <= len (dsp .a )
81- shift_c = len (dsp .a ) + len (dsp .b ) - w_data
80+ shift_c = len (dsp .a ) + len (dsp .b ) - w_data - ( w_data - log2_a0 )
8281 shift_a = len (dsp .a ) - w_coeff
8382 shift_b = len (dsp .b ) - w_data
8483 # +1 from standard sign bit
@@ -133,7 +132,7 @@ def __init__(self, w_coeff, w_data, log2_a0, n_profiles, n_channels):
133132 ch_profile_last_ch .eq (ch_profile [channel_index - 1 ]),
134133 [o .eq (y1 [ch_profile [ch ]][ch ]) for ch , o in enumerate (outp )],
135134 # clipping to positive output range
136- y0_clipped .eq (dsp .p >> ( shift_c - ( w_data - log2_a0 )) ),
135+ y0_clipped .eq (dsp .p >> shift_c ),
137136 If (
138137 dsp .p [- n_sign :] != 0 , # if out of output range
139138 y0_clipped .eq ((1 << w_data - 1 ) - 1 ),
0 commit comments