@@ -91,13 +91,16 @@ struct SynthGowinPass : public ScriptPass
9191 log (" The following families are supported:\n " );
9292 log (" 'gw1n', 'gw2a', 'gw5a'.\n " );
9393 log (" \n " );
94+ log (" -nodsp\n " );
95+ log (" do not infer DSP multipliers.\n " );
96+ log (" \n " );
9497 log (" The following commands are executed by this synthesis command:\n " );
9598 help_script ();
9699 log (" \n " );
97100 }
98101
99102 string top_opt, vout_file, json_file, family;
100- bool retime, nobram, nolutram, flatten, nodffe, nowidelut, abc9, noiopads, noalu, no_rw_check;
103+ bool retime, nobram, nolutram, flatten, nodffe, nowidelut, abc9, noiopads, noalu, no_rw_check, nodsp ;
101104
102105 void clear_flags () override
103106 {
@@ -115,6 +118,7 @@ struct SynthGowinPass : public ScriptPass
115118 noiopads = false ;
116119 noalu = false ;
117120 no_rw_check = false ;
121+ nodsp = false ;
118122 }
119123
120124 void execute (std::vector<std::string> args, RTLIL::Design *design) override
@@ -193,6 +197,10 @@ struct SynthGowinPass : public ScriptPass
193197 no_rw_check = true ;
194198 continue ;
195199 }
200+ if (args[argidx] == " -nodsp" ) {
201+ nodsp = true ;
202+ continue ;
203+ }
196204 break ;
197205 }
198206 extra_args (args, argidx, design);
@@ -208,6 +216,24 @@ struct SynthGowinPass : public ScriptPass
208216 log_pop ();
209217 }
210218
219+ // DSP mapping rules for mul2dsp
220+ struct DSPRule {
221+ int a_maxwidth;
222+ int b_maxwidth;
223+ int a_minwidth;
224+ int b_minwidth;
225+ std::string prim;
226+ };
227+
228+ // gw1n and gw2a
229+ const std::vector<DSPRule> dsp_rules = {
230+ {36 , 36 , 18 , 18 , " $__MUL36X36" },
231+ {18 , 18 , 10 , 4 , " $__MUL18X18" },
232+ {18 , 18 , 4 , 10 , " $__MUL18X18" },
233+ { 9 , 9 , 4 , 4 , " $__MUL9X9" },
234+ };
235+ // TODO: gw5a (MULT12X12, MULT27x36)
236+
211237 void script () override
212238 {
213239 std::string no_rw_check_opt = " " ;
@@ -233,6 +259,23 @@ struct SynthGowinPass : public ScriptPass
233259
234260 if (check_label (" coarse" ))
235261 {
262+ if (help_mode)
263+ {
264+ run (" techmap -map +/mul2dsp.v [...]" , " (unless -nodsp)" );
265+ run (" techmap -map +/gowin/dsp_map.v [...]" , " (unless -nodsp)" );
266+ } else if (!nodsp) {
267+ if (family == " gw1n" || family == " gw2a" )
268+ {
269+ for (const auto &rule : dsp_rules)
270+ {
271+ run (stringf (" techmap -map +/mul2dsp.v -D DSP_A_MAXWIDTH=%d -D DSP_B_MAXWIDTH=%d -D DSP_A_MINWIDTH=%d -D DSP_B_MINWIDTH=%d -D DSP_NAME=%s" ,
272+ rule.a_maxwidth , rule.b_maxwidth , rule.a_minwidth , rule.b_minwidth , rule.prim .c_str ()));
273+ run (" chtype -set $mul t:$__soft_mul" );
274+ }
275+ run (" techmap -map +/gowin/dsp_map.v" );
276+ }
277+ }
278+
236279 run (" synth -run coarse" + no_rw_check_opt);
237280 }
238281
0 commit comments