@@ -1255,15 +1255,23 @@ int Tapcell::fillEndcapEdge(odb::dbRow* row,
12551255 const EdgeType edge_type,
12561256 const std::string& prefix)
12571257{
1258- auto pick_next_master = [x_end, &masters](int x) -> odb::dbMaster* {
1258+ // Consider only masters that can be legally placed in this row's
1259+ // orientation. masters is sorted widest first, so the last valid one is the
1260+ // narrowest, used as a fallback when none divides the span evenly.
1261+ auto pick_next_master
1262+ = [this , x_end, &masters, row](int x) -> odb::dbMaster* {
12591263 const int remaining = x_end - x;
1264+ odb::dbMaster* fallback = nullptr ;
12601265 for (auto * master : masters) {
1266+ if (!checkSymmetry (master, row->getOrient ())) {
1267+ continue ;
1268+ }
1269+ fallback = master;
12611270 if (remaining % master->getWidth () == 0 ) {
12621271 return master;
12631272 }
12641273 }
1265- // pick smallest if none will divide evenly
1266- return masters[masters.size () - 1 ];
1274+ return fallback;
12671275 };
12681276
12691277 const int row_lly = row->getBBox ().yMin ();
@@ -1272,19 +1280,9 @@ int Tapcell::fillEndcapEdge(odb::dbRow* row,
12721280 while (x < x_end) {
12731281 auto * master = pick_next_master (x);
12741282
1275- debugPrint (logger_,
1276- utl::TAP ,
1277- " Endcap" ,
1278- 3 ,
1279- " From {} -> {}: picked {}" ,
1280- x,
1281- x_end,
1282- master->getName ());
1283-
1284- // The master must be symmetric for this row and fit in the remaining
1285- // space; otherwise the boundary cannot be filled without a gap.
1286- if (!checkSymmetry (master, row->getOrient ())
1287- || x + master->getWidth () > x_end) {
1283+ // No symmetric master fits the remaining space: the boundary cannot be
1284+ // filled without leaving a gap.
1285+ if (master == nullptr || x + master->getWidth () > x_end) {
12881286 const double dbus = row->getBlock ()->getDbUnitsPerMicron ();
12891287 logger_->error (
12901288 utl::TAP ,
@@ -1296,6 +1294,15 @@ int Tapcell::fillEndcapEdge(odb::dbRow* row,
12961294 x_end / dbus);
12971295 }
12981296
1297+ debugPrint (logger_,
1298+ utl::TAP ,
1299+ " Endcap" ,
1300+ 3 ,
1301+ " From {} -> {}: picked {}" ,
1302+ x,
1303+ x_end,
1304+ master->getName ());
1305+
12991306 makeInstance (
13001307 db_->getChip ()->getBlock (),
13011308 master,
0 commit comments