@@ -2267,34 +2267,57 @@ struct SynthRapidSiliconPass : public ScriptPass {
2267
2267
2268
2268
for (auto &chain : carry_chains)
2269
2269
{
2270
- const std::vector<Cell *> &chain_ = chain.second ;
2271
- int extra_carry = chain_.size () - max_carry_length;
2272
- if (extra_carry > 0 )
2270
+ std::vector<Cell*> original_chain = chain.second ;
2271
+ std::reverse (original_chain.begin (), original_chain.end ());
2272
+
2273
+ std::vector<std::vector<Cell*>> sub_chains;
2274
+
2275
+ size_t i = 0 ;
2276
+ size_t first_chunk_size = std::min (max_carry_length, static_cast <int >(original_chain.size ()));
2277
+ std::vector<Cell*> first_chain_chunk (original_chain.begin (), original_chain.begin () + first_chunk_size);
2278
+ sub_chains.push_back (first_chain_chunk);
2279
+
2280
+ for (i = first_chunk_size; i < original_chain.size (); i += (max_carry_length - 1 ))
2273
2281
{
2274
- std::vector<Cell *> ExcessCarry;
2275
- ExcessCarry.reserve (extra_carry);
2276
- std::copy (chain_.begin (), chain_.begin () + extra_carry, std::back_inserter (ExcessCarry));
2282
+ size_t chunk_size = std::min (max_carry_length - 1 , static_cast <int >(original_chain.size () - i));
2277
2283
2278
- for (auto it = ExcessCarry.begin (); it != ExcessCarry.end ();)
2279
- {
2280
- Cell *ec = *it;
2281
-
2282
- log (" Converting %s to logic.\n " , log_id (ec->name ));
2283
- RTLIL::Module *top_module = _design->top_module ();
2284
- RTLIL::SigSpec np = top_module->addWire (NEW_ID, 1 );
2285
- RTLIL::SigSpec and1 = top_module->addWire (NEW_ID, 1 );
2286
- RTLIL::SigSpec and2 = top_module->addWire (NEW_ID, 1 );
2287
- RTLIL::SigSpec c_out = top_module->addWire (NEW_ID, 1 );
2288
- top_module->addXor (NEW_ID, ec->getPort (RTLIL::escape_id (" P" )), ec->getPort (RTLIL::escape_id (" CIN" )), ec->getPort (RTLIL::escape_id (" O" )));
2289
- top_module->addNot (NEW_ID, ec->getPort (RTLIL::escape_id (" P" )), np);
2290
- top_module->addAnd (NEW_ID, ec->getPort (RTLIL::escape_id (" P" )), ec->getPort (RTLIL::escape_id (" CIN" )), and1);
2291
- top_module->addAnd (NEW_ID, np, ec->getPort (RTLIL::escape_id (" G" )), and2);
2292
- top_module->addOr (NEW_ID, and1, and2, ec->getPort (RTLIL::escape_id (" COUT" )));
2293
-
2294
- top_module->remove (ec);
2295
- it = ExcessCarry.erase (it);
2284
+ std::vector<Cell*> chain_chunk;
2285
+ chain_chunk.reserve (chunk_size + 1 );
2286
+
2287
+ chain_chunk.push_back (sub_chains.back ().back ());
2288
+
2289
+ std::copy (original_chain.begin () + i, original_chain.begin () + i + chunk_size, std::back_inserter (chain_chunk));
2290
+
2291
+ sub_chains.push_back (chain_chunk);
2292
+ }
2293
+
2294
+ bool ignore_chain1 = false ;
2295
+ for (auto _chain_ : sub_chains){
2296
+ if (!ignore_chain1){
2297
+ ignore_chain1=true ;
2298
+ continue ;
2296
2299
}
2297
- ExcessCarry.clear ();
2300
+
2301
+ RTLIL::Cell* cell_next = _chain_[1 ];
2302
+ RTLIL::Cell* cell_prev = _chain_[0 ];
2303
+ RTLIL::Module *top_module = _design->top_module ();
2304
+ RTLIL::IdString newName = top_module->uniquify (stringf (" $first_adder%s" ,
2305
+ log_id (cell_next->name )));
2306
+ RTLIL::Cell* newcell = top_module->addCell (NEW_ID, " \\ CARRY" );
2307
+ newcell->set_bool_attribute (ID::keep);
2308
+
2309
+ RTLIL::SigSpec cin = top_module->addWire (NEW_ID, 1 );
2310
+ RTLIL::SigSpec O = top_module->addWire (NEW_ID, 1 );
2311
+ newcell->setPort (RTLIL::escape_id (" CIN" ), {});
2312
+ newcell->setPort (RTLIL::escape_id (" O" ), O);
2313
+ newcell->setPort (RTLIL::escape_id (" G" ), cell_prev->getPort (RTLIL::escape_id (" COUT" )));
2314
+ newcell->setPort (RTLIL::escape_id (" P" ), State::S0);
2315
+
2316
+ RTLIL::SigSpec cout = top_module->addWire (NEW_ID, 1 );
2317
+ newcell->setPort (RTLIL::escape_id (" COUT" ), cout);
2318
+ cell_next->unsetPort (RTLIL::escape_id (" CIN" ));
2319
+ cell_next->setPort (RTLIL::escape_id (" CIN" ),cout);
2320
+
2298
2321
}
2299
2322
}
2300
2323
}
@@ -9045,9 +9068,9 @@ void collect_clocks (RTLIL::Module* module,
9045
9068
break ;
9046
9069
}
9047
9070
}
9048
- if (cec) {
9049
- run (" write_verilog -noexpr -noattr - nohex after_tech_map.v" );
9050
- }
9071
+ // if (cec) {
9072
+ run (" write_verilog -noexpr -nohex after_tech_map.v" );
9073
+ // }
9051
9074
// sec_check("after_tech_map", false);
9052
9075
sec_check (" after_tech_map" , true , true );
9053
9076
0 commit comments