x393  1.0
FPGAcodeforElphelNC393camera
dsp_ma_preadd.v
Go to the documentation of this file.
1 
39 `timescale 1ns/1ps
40 
41 module dsp_ma_preadd #(
42  parameter B_WIDTH = 18,
43  parameter A_WIDTH = 25,
44  parameter P_WIDTH = 48)
45 (
46  input clk,
47  input rst,
48  input signed [B_WIDTH-1:0] bin,
49  input ceb1, // load b1 register
50  input ceb2, // load b2 register
51  input selb, // 0 - select b1, 1 - select b2
52  input signed [A_WIDTH-1:0] ain,
53  input cea1, // clock enable a1 reg
54  input cea2, // clock enable a2 reg
55  input signed [A_WIDTH-1:0] din,
56  input ced, // enable d-reg
57  input cead, // enable ad register (after pre-adder)
58  input sela, // 0 - select a1, 1 - select a2
59  input en_a, // 1 - enable a input (0 - zero) ~inmode[1]
60  input en_d, // 1 - enable d input (0 - zero) ~inmode[2]
61  input sub_a, // 0 - pre-add (D+A), 1 - pre-subtract (D-A)
62  input neg_m, // 1 - negate multiplier result
63  input accum, // 0 - use multiplier result, 1 add to accumulator
64  output signed [P_WIDTH-1:0] pout
65 );
66 `ifdef INSTANTIATE_DSP48E1
67  wire [4:0] inmode = {~selb,
68  sub_a,
69  en_d,
70  ~en_a,
71  ~sela};
72  wire [3:0] alumode = {2'b0,
73  neg_m,
74  neg_m};
75  wire [6:0] opmode = {1'b0,
76  accum,
77  1'b0,
78  2'b01,
79  2'b01};
80 
82  .ACASCREG (1),
83  .ADREG (1),
84  .ALUMODEREG (1),
85  .AREG (1), // 2), // (1) - means number in series, so "2" always reads the second
86  .AUTORESET_PATDET ("NO_RESET"),
87  .A_INPUT ("DIRECT"),
88  .BCASCREG (1),
89  .BREG (1), // (2), // (1) - means number in series, so "2" always reads the second
90  .B_INPUT ("DIRECT"),
91  .CARRYINREG (1),
92  .CARRYINSELREG (1),
93  .CREG (0), //(1),
94  .DREG (1),
95  .INMODEREG (1),
96  .IS_ALUMODE_INVERTED (4'b0),
97  .IS_CARRYIN_INVERTED (1'b0),
98  .IS_CLK_INVERTED (1'b0),
99  .IS_INMODE_INVERTED (5'b0),
100  .IS_OPMODE_INVERTED (7'b0),
101  .MASK (48'hffffffffffff),
102  .MREG (1),
103  .OPMODEREG (1),
104  .PATTERN (48'h000000000000),
105  .PREG (1),
106  .SEL_MASK ("MASK"),
107  .SEL_PATTERN ("PATTERN"),
108  .USE_DPORT ("TRUE"), //("FALSE"),
109  .USE_MULT ("MULTIPLY"),
110  .USE_PATTERN_DETECT ("NO_PATDET"),
111  .USE_SIMD ("ONE48")
112  ) DSP48E1_i (
113  .ACOUT (), // output[29:0]
114  .BCOUT (), // output[17:0]
115  .CARRYCASCOUT (), // output
116  .CARRYOUT (), // output[3:0]
117  .MULTSIGNOUT (), // output
118  .OVERFLOW (), // output
119  .P (pout), // output[47:0]
120  .PATTERNBDETECT (), // output
121  .PATTERNDETECT (), // output
122  .PCOUT (), // output[47:0]
123  .UNDERFLOW (), // output
124  .A ({{30-A_WIDTH{ain[A_WIDTH-1]}}, ain}), // input[29:0]
125  .ACIN (30'b0), // input[29:0]
126  .ALUMODE (alumode), // input[3:0]
127  .B (bin), // input[17:0]
128  .BCIN (18'b0), // input[17:0]
129  .C (48'hffffffffffff), // input[47:0]
130  .CARRYCASCIN (1'b0), // input
131  .CARRYIN (1'b0), // input
132  .CARRYINSEL (3'h0), // input[2:0] // later modify?
133  .CEA1 (cea1), // input
134  .CEA2 (cea2), // input
135  .CEAD (cead), // input
136  .CEALUMODE (1'b1), // input
137  .CEB1 (ceb1), // input
138  .CEB2 (ceb2), // input
139  .CEC (1'b0), // input
140  .CECARRYIN (1'b0), // input
141  .CECTRL (1'b1), // input
142  .CED (ced), // input
143  .CEINMODE (1'b1), // input
144  .CEM (1'b1), // input
145  .CEP (1'b1), // input
146  .CLK (clk), // input
147  .D (din), // input[24:0]
148  .INMODE (inmode), // input[4:0]
149  .MULTSIGNIN (1'b0), // input
150  .OPMODE (opmode), // input[6:0]
151  .PCIN (48'b0), // input[47:0]
152  .RSTA (rst), // input
153  .RSTALLCARRYIN (rst), // input
154  .RSTALUMODE (rst), // input
155  .RSTB (rst), // input
156  .RSTC (rst), // input
157  .RSTCTRL (rst), // input
158  .RSTD (rst), // input
159  .RSTINMODE (rst), // input
160  .RSTM (rst), // input
161  .RSTP (rst) // input
162  );
163 
164 `else
165 // Will try to make it infer DSP48e1
166  reg signed [B_WIDTH-1:0] b1_reg;
167  reg signed [B_WIDTH-1:0] b2_reg;
168  reg signed [A_WIDTH-1:0] a1_reg;
169  reg signed [A_WIDTH-1:0] a2_reg;
170  reg signed [A_WIDTH-1:0] d_reg;
171  reg signed [A_WIDTH-1:0] ad_reg;
172  reg signed [P_WIDTH-1:0] m_reg;
173  reg signed [P_WIDTH-1:0] p_reg;
174  wire signed [A_WIDTH+B_WIDTH-1:0] m_wire;
175  wire signed [B_WIDTH-1:0] b_wire;
176  wire signed [A_WIDTH-1:0] a_wire;
177  wire signed [A_WIDTH-1:0] d_wire;
178  reg selb_r;
179  reg sela_r;
180  reg en_a_r;
181  reg en_d_r;
182  reg sub_a_r;
183  reg neg_m_r;
184  reg accum_r;
185  wire signed [P_WIDTH-1:0] m_reg_pm;
186  wire signed [P_WIDTH-1:0] p_reg_cond;
187 
188 
189  assign pout = p_reg;
190  assign b_wire = selb_r ? b2_reg : b1_reg;
191  assign a_wire = en_a_r ? (sela_r ? a2_reg : a1_reg) : {A_WIDTH{1'b0}};
192 // assign d_wire = en_d_r ? (sub_a_r ? -d_reg : d_reg) : {A_WIDTH{1'b0}};
193  assign d_wire = en_d_r ? d_reg : {A_WIDTH{1'b0}};
194  assign m_wire = ad_reg * b_wire;
195 
196  assign m_reg_pm = neg_m_r ? - m_reg : m_reg;
197  assign p_reg_cond = accum_r ? p_reg : 0;
198 
199  always @ (posedge clk) begin
200  if (rst) b1_reg <= 0;
201  else if (ceb1) b1_reg <= bin;
202 
203  if (rst) b2_reg <= 0;
204  else if (ceb2) b2_reg <= bin;
205 
206  if (rst) a1_reg <= 0;
207  else if (cea1) a1_reg <= ain;
208 
209  if (rst) a2_reg <= 0;
210  else if (cea2) a2_reg <= ain;
211 
212  if (rst) d_reg <= 0;
213  else if (ced) d_reg <= din;
214 
215  if (rst) ad_reg <= 0;
216  else if (cead) ad_reg <= sub_a_r? (d_wire - a_wire): (d_wire + a_wire);
217 
218  neg_m_r <= neg_m;
219  accum_r <= accum;
220 
221  selb_r <= selb;
222  sela_r <= sela;
223  en_a_r <= en_a;
224  en_d_r <= en_d;
225  sub_a_r <= sub_a;
226 
227  m_reg <= {{P_WIDTH - A_WIDTH - B_WIDTH{1'b0}}, m_wire};
228 
229  p_reg <= p_reg_cond + m_reg_pm;
230 
231  end
232 `endif
233 
234 endmodule
235 
236 
signed [B_WIDTH-1:0] 3383bin
Definition: dsp_ma_preadd.v:48
signed [A_WIDTH-1:0] 3390din
Definition: dsp_ma_preadd.v:55
3400inmodewire[4:0]
Definition: dsp_ma_preadd.v:67
signed [P_WIDTH-1:0] 3399pout
Definition: dsp_ma_preadd.v:64
3401alumodewire[3:0]
Definition: dsp_ma_preadd.v:72
signed [A_WIDTH-1:0] 3387ain
Definition: dsp_ma_preadd.v:52
DSP48E1_i DSP48E1
Definition: dsp_ma_preadd.v:81
3402opmodewire[6:0]
Definition: dsp_ma_preadd.v:75