Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 63 additions & 49 deletions src/pdn/src/via.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,13 @@ bool Enclosure::isPreferredOver(const Enclosure* other, bool minimize_x) const

void Enclosure::snap(odb::dbTech* tech)
{
x_ = TechLayer::snapToManufacturingGrid(tech, x_);
y_ = TechLayer::snapToManufacturingGrid(tech, y_);
// Do not round an enclosure deficit up to an apparently legal zero.
auto snap = [tech](int value) {
return value < 0 ? -TechLayer::snapToManufacturingGrid(tech, -value, true)
: TechLayer::snapToManufacturingGrid(tech, value);
};
x_ = snap(x_);
y_ = snap(y_);
}

void Enclosure::copy(const Enclosure* other)
Expand Down Expand Up @@ -2101,28 +2106,30 @@ void ViaGenerator::determineRowsAndColumns(
+ (last_rows > 0 ? array_spacing_y_ : 0);
const int double_enc_y = height - via_width_y;

bottom_enclosure_->setX(
determine_enclosure(use_bottom_min_enclosure,
true,
bottom_min_enclosure.getX(),
double_enc_x / 2,
lower_constraint_));
bottom_enclosure_->setY(
determine_enclosure(use_bottom_min_enclosure,
false,
bottom_min_enclosure.getY(),
double_enc_y / 2,
lower_constraint_));
top_enclosure_->setX(determine_enclosure(use_top_min_enclosure,
true,
top_min_enclosure.getX(),
double_enc_x / 2,
upper_constraint_));
top_enclosure_->setY(determine_enclosure(use_top_min_enclosure,
false,
top_min_enclosure.getY(),
double_enc_y / 2,
upper_constraint_));
bottom_enclosure_->setX(determine_enclosure(
use_bottom_min_enclosure,
true,
bottom_min_enclosure.getX(),
static_cast<int>(std::floor(double_enc_x / 2.0)),
lower_constraint_));
bottom_enclosure_->setY(determine_enclosure(
use_bottom_min_enclosure,
false,
bottom_min_enclosure.getY(),
static_cast<int>(std::floor(double_enc_y / 2.0)),
lower_constraint_));
top_enclosure_->setX(determine_enclosure(
use_top_min_enclosure,
true,
top_min_enclosure.getX(),
static_cast<int>(std::floor(double_enc_x / 2.0)),
upper_constraint_));
top_enclosure_->setY(determine_enclosure(
use_top_min_enclosure,
false,
top_min_enclosure.getY(),
static_cast<int>(std::floor(double_enc_y / 2.0)),
upper_constraint_));
Comment on lines +2109 to +2132

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using floating-point division double_enc_x / 2.0, std::floor, and casting back to int introduces unnecessary overhead. Since double_enc_x and double_enc_y are signed integers, we can perform highly efficient integer-only floor division by 2 using the arithmetic right shift operator >> 1 (which is guaranteed to be arithmetic and perform floor division in C++20, and is universally supported as such in C++17). This avoids floating-point conversions entirely.

          bottom_enclosure_->setX(determine_enclosure(
              use_bottom_min_enclosure,
              true,
              bottom_min_enclosure.getX(),
              double_enc_x >> 1,
              lower_constraint_));
          bottom_enclosure_->setY(determine_enclosure(
              use_bottom_min_enclosure,
              false,
              bottom_min_enclosure.getY(),
              double_enc_y >> 1,
              lower_constraint_));
          top_enclosure_->setX(determine_enclosure(
              use_top_min_enclosure,
              true,
              top_min_enclosure.getX(),
              double_enc_x >> 1,
              upper_constraint_));
          top_enclosure_->setY(determine_enclosure(
              use_top_min_enclosure,
              false,
              top_min_enclosure.getY(),
              double_enc_y >> 1,
              upper_constraint_));


max_cut_area = total_cut_area;
}
Expand Down Expand Up @@ -2153,26 +2160,30 @@ void ViaGenerator::determineRowsAndColumns(
top_enclosure_->setX(top_min_enclosure.getX());
top_enclosure_->setY(top_min_enclosure.getY());
} else {
bottom_enclosure_->setX(determine_enclosure(use_bottom_min_enclosure,
true,
bottom_min_enclosure.getX(),
double_enc_x / 2,
lower_constraint_));
bottom_enclosure_->setY(determine_enclosure(use_bottom_min_enclosure,
false,
bottom_min_enclosure.getY(),
double_enc_y / 2,
lower_constraint_));
top_enclosure_->setX(determine_enclosure(use_top_min_enclosure,
true,
top_min_enclosure.getX(),
double_enc_x / 2,
upper_constraint_));
top_enclosure_->setY(determine_enclosure(use_top_min_enclosure,
false,
top_min_enclosure.getY(),
double_enc_y / 2,
upper_constraint_));
bottom_enclosure_->setX(
determine_enclosure(use_bottom_min_enclosure,
true,
bottom_min_enclosure.getX(),
static_cast<int>(std::floor(double_enc_x / 2.0)),
lower_constraint_));
bottom_enclosure_->setY(
determine_enclosure(use_bottom_min_enclosure,
false,
bottom_min_enclosure.getY(),
static_cast<int>(std::floor(double_enc_y / 2.0)),
lower_constraint_));
top_enclosure_->setX(
determine_enclosure(use_top_min_enclosure,
true,
top_min_enclosure.getX(),
static_cast<int>(std::floor(double_enc_x / 2.0)),
upper_constraint_));
top_enclosure_->setY(
determine_enclosure(use_top_min_enclosure,
false,
top_min_enclosure.getY(),
static_cast<int>(std::floor(double_enc_y / 2.0)),
upper_constraint_));
Comment on lines +2163 to +2186

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using floating-point division double_enc_x / 2.0, std::floor, and casting back to int introduces unnecessary overhead. Since double_enc_x and double_enc_y are signed integers, we can perform highly efficient integer-only floor division by 2 using the arithmetic right shift operator >> 1 (which is guaranteed to be arithmetic and perform floor division in C++20, and is universally supported as such in C++17). This avoids floating-point conversions entirely.

      bottom_enclosure_->setX(
          determine_enclosure(use_bottom_min_enclosure,
                              true,
                              bottom_min_enclosure.getX(),
                              double_enc_x >> 1,
                              lower_constraint_));
      bottom_enclosure_->setY(
          determine_enclosure(use_bottom_min_enclosure,
                              false,
                              bottom_min_enclosure.getY(),
                              double_enc_y >> 1,
                              lower_constraint_));
      top_enclosure_->setX(
          determine_enclosure(use_top_min_enclosure,
                              true,
                              top_min_enclosure.getX(),
                              double_enc_x >> 1,
                              upper_constraint_));
      top_enclosure_->setY(
          determine_enclosure(use_top_min_enclosure,
                              false,
                              top_min_enclosure.getY(),
                              double_enc_y >> 1,
                              upper_constraint_));

}

if (isSplitCutArray()) {
Expand Down Expand Up @@ -2686,12 +2697,15 @@ void GenerateViaGenerator::getMinimumEnclosures(std::vector<Enclosure>& bottom,
{
ViaGenerator::getMinimumEnclosures(bottom, top, true);

if (rules_only) {
return;
// Applicable cut-layer enclosure rules override VIARULE defaults. When
// validating a generated via, retain the default for a side with no such
// rule; otherwise a forced single cut can pass with insufficient enclosure.
if (!rules_only || bottom.empty()) {
bottom.emplace_back(getBottomLayerRule(), getBottomLayer());
}
if (!rules_only || top.empty()) {
top.emplace_back(getTopLayerRule(), getTopLayer());
}

bottom.emplace_back(getBottomLayerRule(), getBottomLayer());
top.emplace_back(getTopLayerRule(), getTopLayer());
}

/////////
Expand Down
5 changes: 5 additions & 0 deletions src/pdn/test/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ COMPULSORY_TESTS = [
"core_grid_with_single_layer_rings",
"design_width",
"existing",
"generated_via_default_edge",
"gf180_hybrid_followpins",
"gf180_hybrid_followpins_pitch",
"gf180_hybrid_followpins_rowpattern",
Expand Down Expand Up @@ -392,6 +393,10 @@ filegroup(
"core_grid_auto_domain": ["core_grid.defok"],
"core_grid_with_M6_min_area_rule": ["core_grid_with_M6_min_area.defok"],
"core_grid_with_rings_connect": ["core_grid_with_rings.defok"],
"generated_via_default_edge": [
"generated_via_enclosure/edge_macro.lef",
"generated_via_enclosure/floorplan.def",
],
"macros_channel_recursive_repair": [
"ihp_ethmac/tech.lef",
"ihp_ethmac/sg13g2.lef",
Expand Down
Loading
Loading