Skip to content

Commit

Permalink
Replace std::set of points pairs with boost flat hashmap
Browse files Browse the repository at this point in the history
Signed-off-by: Szymon Gizler <[email protected]>
  • Loading branch information
sgizler committed Nov 28, 2024
1 parent 13839b9 commit b9f8bef
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 14 deletions.
3 changes: 1 addition & 2 deletions src/drt/src/db/infra/frPoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ class Point3D : public Point
friend std::size_t hash_value(Point3D const& p)
{
std::size_t seed = 0;
boost::hash_combine(seed, p.getX());
boost::hash_combine(seed, p.getY());
boost::hash_combine(seed, hash_value(((Point)p)));
boost::hash_combine(seed, p.getZ());
return seed;
}
Expand Down
11 changes: 6 additions & 5 deletions src/drt/src/gc/FlexGC_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "dr/FlexDR.h"
#include "frDesign.h"
#include "gc/FlexGC.h"
#include <boost/unordered/unordered_flat_set.hpp>

namespace odb {
class dbTechLayerCutSpacingTableDefRule;
Expand Down Expand Up @@ -191,31 +192,31 @@ class FlexGCWorker::Impl
void initNet_pins_polygonEdges(gcNet* net);
void initNet_pins_polygonEdges_getFixedPolygonEdges(
gcNet* net,
std::vector<std::set<std::pair<Point, Point>>>& fixedPolygonEdges);
std::vector<boost::unordered_flat_set<std::pair<Point, Point>>>& fixedPolygonEdges);
void initNet_pins_polygonEdges_helper_outer(
gcNet* net,
gcPin* pin,
gcPolygon* poly,
frLayerNum i,
const std::vector<std::set<std::pair<Point, Point>>>& fixedPolygonEdges);
const std::vector<boost::unordered_flat_set<std::pair<Point, Point>>>& fixedPolygonEdges);
void initNet_pins_polygonEdges_helper_inner(
gcNet* net,
gcPin* pin,
const gtl::polygon_90_data<frCoord>& hole_poly,
frLayerNum i,
const std::vector<std::set<std::pair<Point, Point>>>& fixedPolygonEdges);
const std::vector<boost::unordered_flat_set<std::pair<Point, Point>>>& fixedPolygonEdges);
void initNet_pins_polygonCorners(gcNet* net);
void initNet_pins_polygonCorners_helper(gcNet* net, gcPin* pin);
void initNet_pins_maxRectangles(gcNet* net);
void initNet_pins_maxRectangles_getFixedMaxRectangles(
gcNet* net,
std::vector<std::set<std::pair<Point, Point>>>& fixedMaxRectangles);
std::vector<boost::unordered_flat_set<std::pair<Point, Point>>>& fixedMaxRectangles);
void initNet_pins_maxRectangles_helper(
gcNet* net,
gcPin* pin,
const gtl::rectangle_data<frCoord>& rect,
frLayerNum i,
const std::vector<std::set<std::pair<Point, Point>>>& fixedMaxRectangles);
const std::vector<boost::unordered_flat_set<std::pair<Point, Point>>>& fixedMaxRectangles);

void initRegionQuery();

Expand Down
14 changes: 7 additions & 7 deletions src/drt/src/gc/FlexGC_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ void FlexGCWorker::Impl::initNet_pins_polygon(gcNet* net)

void FlexGCWorker::Impl::initNet_pins_polygonEdges_getFixedPolygonEdges(
gcNet* net,
std::vector<std::set<std::pair<Point, Point>>>& fixedPolygonEdges)
std::vector<boost::unordered_flat_set<std::pair<Point, Point>>>& fixedPolygonEdges)
{
int numLayers = getTech()->getLayers().size();
std::vector<gtl::polygon_90_with_holes_data<frCoord>> polys;
Expand Down Expand Up @@ -552,7 +552,7 @@ void FlexGCWorker::Impl::initNet_pins_polygonEdges_helper_outer(
gcPin* pin,
gcPolygon* poly,
frLayerNum i,
const std::vector<std::set<std::pair<Point, Point>>>& fixedPolygonEdges)
const std::vector<boost::unordered_flat_set<std::pair<Point, Point>>>& fixedPolygonEdges)
{
Point bp, ep, firstPt;
gtl::point_data<frCoord> bp1, ep1, firstPt1;
Expand Down Expand Up @@ -626,7 +626,7 @@ void FlexGCWorker::Impl::initNet_pins_polygonEdges_helper_inner(
gcPin* pin,
const gtl::polygon_90_data<frCoord>& hole_poly,
frLayerNum i,
const std::vector<std::set<std::pair<Point, Point>>>& fixedPolygonEdges)
const std::vector<boost::unordered_flat_set<std::pair<Point, Point>>>& fixedPolygonEdges)
{
Point bp, ep, firstPt;
gtl::point_data<frCoord> bp1, ep1, firstPt1;
Expand Down Expand Up @@ -698,7 +698,7 @@ void FlexGCWorker::Impl::initNet_pins_polygonEdges_helper_inner(
void FlexGCWorker::Impl::initNet_pins_polygonEdges(gcNet* net)
{
int numLayers = getTech()->getLayers().size();
std::vector<std::set<std::pair<Point, Point>>> fixedPolygonEdges(numLayers);
std::vector<boost::unordered_flat_set<std::pair<Point, Point>>> fixedPolygonEdges(numLayers);
// get all fixed polygon edges
initNet_pins_polygonEdges_getFixedPolygonEdges(net, fixedPolygonEdges);

Expand Down Expand Up @@ -852,7 +852,7 @@ void FlexGCWorker::Impl::initNet_pins_polygonCorners(gcNet* net)

void FlexGCWorker::Impl::initNet_pins_maxRectangles_getFixedMaxRectangles(
gcNet* net,
std::vector<std::set<std::pair<Point, Point>>>& fixedMaxRectangles)
std::vector<boost::unordered_flat_set<std::pair<Point, Point>>>& fixedMaxRectangles)
{
int numLayers = getTech()->getLayers().size();
std::vector<gtl::rectangle_data<frCoord>> rects;
Expand All @@ -878,7 +878,7 @@ void FlexGCWorker::Impl::initNet_pins_maxRectangles_helper(
gcPin* pin,
const gtl::rectangle_data<frCoord>& rect,
frLayerNum i,
const std::vector<std::set<std::pair<Point, Point>>>& fixedMaxRectangles)
const std::vector<boost::unordered_flat_set<std::pair<Point, Point>>>& fixedMaxRectangles)
{
auto rectangle = std::make_unique<gcRect>();
rectangle->setRect(rect);
Expand Down Expand Up @@ -916,7 +916,7 @@ void FlexGCWorker::Impl::initNet_pins_maxRectangles_helper(
void FlexGCWorker::Impl::initNet_pins_maxRectangles(gcNet* net)
{
int numLayers = getTech()->getLayers().size();
std::vector<std::set<std::pair<Point, Point>>> fixedMaxRectangles(numLayers);
std::vector<boost::unordered_flat_set<std::pair<Point, Point>>> fixedMaxRectangles(numLayers);
// get all fixed max rectangles
initNet_pins_maxRectangles_getFixedMaxRectangles(net, fixedMaxRectangles);

Expand Down
14 changes: 14 additions & 0 deletions src/odb/include/odb/geom.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include "isotropy.h"
#include "odb.h"
#include "utl/Logger.h"
#include <boost/functional/hash.hpp>

namespace odb {

Expand Down Expand Up @@ -90,6 +91,19 @@ class Point
int y_ = 0;
};

inline std::size_t hash_value(Point const& p)
{
size_t hash = 0;
if constexpr (sizeof(size_t) == 8 && sizeof(size_t) == 2*sizeof(int)) {
// Use fast identity hash if possible. We don't care about avalanching since it will be mixed later by flat_map anyway
return ((size_t)p.getX() << 32) | p.getY();
} else {
boost::hash_combine(hash, p.x());
boost::hash_combine(hash, p.y());
}
return hash;
}

std::ostream& operator<<(std::ostream& os, const Point& pIn);

/*
Expand Down

0 comments on commit b9f8bef

Please sign in to comment.