Skip to content

Commit 00e7666

Browse files
committed
Replace std::set of points pairs with boost flat hashmap
1 parent a5cab32 commit 00e7666

File tree

4 files changed

+28
-14
lines changed

4 files changed

+28
-14
lines changed

src/drt/src/db/infra/frPoint.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,7 @@ class Point3D : public Point
6868
friend std::size_t hash_value(Point3D const& p)
6969
{
7070
std::size_t seed = 0;
71-
boost::hash_combine(seed, p.getX());
72-
boost::hash_combine(seed, p.getY());
71+
boost::hash_combine(seed, hash_value(((Point)p)));
7372
boost::hash_combine(seed, p.getZ());
7473
return seed;
7574
}

src/drt/src/gc/FlexGC_impl.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "dr/FlexDR.h"
3535
#include "frDesign.h"
3636
#include "gc/FlexGC.h"
37+
#include <boost/unordered/unordered_flat_set.hpp>
3738

3839
namespace odb {
3940
class dbTechLayerCutSpacingTableDefRule;
@@ -189,31 +190,31 @@ class FlexGCWorker::Impl
189190
void initNet_pins_polygonEdges(gcNet* net);
190191
void initNet_pins_polygonEdges_getFixedPolygonEdges(
191192
gcNet* net,
192-
std::vector<std::set<std::pair<Point, Point>>>& fixedPolygonEdges);
193+
std::vector<boost::unordered_flat_set<std::pair<Point, Point>>>& fixedPolygonEdges);
193194
void initNet_pins_polygonEdges_helper_outer(
194195
gcNet* net,
195196
gcPin* pin,
196197
gcPolygon* poly,
197198
frLayerNum i,
198-
const std::vector<std::set<std::pair<Point, Point>>>& fixedPolygonEdges);
199+
const std::vector<boost::unordered_flat_set<std::pair<Point, Point>>>& fixedPolygonEdges);
199200
void initNet_pins_polygonEdges_helper_inner(
200201
gcNet* net,
201202
gcPin* pin,
202203
const gtl::polygon_90_data<frCoord>& hole_poly,
203204
frLayerNum i,
204-
const std::vector<std::set<std::pair<Point, Point>>>& fixedPolygonEdges);
205+
const std::vector<boost::unordered_flat_set<std::pair<Point, Point>>>& fixedPolygonEdges);
205206
void initNet_pins_polygonCorners(gcNet* net);
206207
void initNet_pins_polygonCorners_helper(gcNet* net, gcPin* pin);
207208
void initNet_pins_maxRectangles(gcNet* net);
208209
void initNet_pins_maxRectangles_getFixedMaxRectangles(
209210
gcNet* net,
210-
std::vector<std::set<std::pair<Point, Point>>>& fixedMaxRectangles);
211+
std::vector<boost::unordered_flat_set<std::pair<Point, Point>>>& fixedMaxRectangles);
211212
void initNet_pins_maxRectangles_helper(
212213
gcNet* net,
213214
gcPin* pin,
214215
const gtl::rectangle_data<frCoord>& rect,
215216
frLayerNum i,
216-
const std::vector<std::set<std::pair<Point, Point>>>& fixedMaxRectangles);
217+
const std::vector<boost::unordered_flat_set<std::pair<Point, Point>>>& fixedMaxRectangles);
217218

218219
void initRegionQuery();
219220

src/drt/src/gc/FlexGC_init.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ void FlexGCWorker::Impl::initNet_pins_polygon(gcNet* net)
486486

487487
void FlexGCWorker::Impl::initNet_pins_polygonEdges_getFixedPolygonEdges(
488488
gcNet* net,
489-
std::vector<std::set<std::pair<Point, Point>>>& fixedPolygonEdges)
489+
std::vector<boost::unordered_flat_set<std::pair<Point, Point>>>& fixedPolygonEdges)
490490
{
491491
int numLayers = getTech()->getLayers().size();
492492
std::vector<gtl::polygon_90_with_holes_data<frCoord>> polys;
@@ -552,7 +552,7 @@ void FlexGCWorker::Impl::initNet_pins_polygonEdges_helper_outer(
552552
gcPin* pin,
553553
gcPolygon* poly,
554554
frLayerNum i,
555-
const std::vector<std::set<std::pair<Point, Point>>>& fixedPolygonEdges)
555+
const std::vector<boost::unordered_flat_set<std::pair<Point, Point>>>& fixedPolygonEdges)
556556
{
557557
Point bp, ep, firstPt;
558558
gtl::point_data<frCoord> bp1, ep1, firstPt1;
@@ -626,7 +626,7 @@ void FlexGCWorker::Impl::initNet_pins_polygonEdges_helper_inner(
626626
gcPin* pin,
627627
const gtl::polygon_90_data<frCoord>& hole_poly,
628628
frLayerNum i,
629-
const std::vector<std::set<std::pair<Point, Point>>>& fixedPolygonEdges)
629+
const std::vector<boost::unordered_flat_set<std::pair<Point, Point>>>& fixedPolygonEdges)
630630
{
631631
Point bp, ep, firstPt;
632632
gtl::point_data<frCoord> bp1, ep1, firstPt1;
@@ -698,7 +698,7 @@ void FlexGCWorker::Impl::initNet_pins_polygonEdges_helper_inner(
698698
void FlexGCWorker::Impl::initNet_pins_polygonEdges(gcNet* net)
699699
{
700700
int numLayers = getTech()->getLayers().size();
701-
std::vector<std::set<std::pair<Point, Point>>> fixedPolygonEdges(numLayers);
701+
std::vector<boost::unordered_flat_set<std::pair<Point, Point>>> fixedPolygonEdges(numLayers);
702702
// get all fixed polygon edges
703703
initNet_pins_polygonEdges_getFixedPolygonEdges(net, fixedPolygonEdges);
704704

@@ -820,7 +820,7 @@ void FlexGCWorker::Impl::initNet_pins_polygonCorners(gcNet* net)
820820

821821
void FlexGCWorker::Impl::initNet_pins_maxRectangles_getFixedMaxRectangles(
822822
gcNet* net,
823-
std::vector<std::set<std::pair<Point, Point>>>& fixedMaxRectangles)
823+
std::vector<boost::unordered_flat_set<std::pair<Point, Point>>>& fixedMaxRectangles)
824824
{
825825
int numLayers = getTech()->getLayers().size();
826826
std::vector<gtl::rectangle_data<frCoord>> rects;
@@ -846,7 +846,7 @@ void FlexGCWorker::Impl::initNet_pins_maxRectangles_helper(
846846
gcPin* pin,
847847
const gtl::rectangle_data<frCoord>& rect,
848848
frLayerNum i,
849-
const std::vector<std::set<std::pair<Point, Point>>>& fixedMaxRectangles)
849+
const std::vector<boost::unordered_flat_set<std::pair<Point, Point>>>& fixedMaxRectangles)
850850
{
851851
auto rectangle = std::make_unique<gcRect>();
852852
rectangle->setRect(rect);
@@ -884,7 +884,7 @@ void FlexGCWorker::Impl::initNet_pins_maxRectangles_helper(
884884
void FlexGCWorker::Impl::initNet_pins_maxRectangles(gcNet* net)
885885
{
886886
int numLayers = getTech()->getLayers().size();
887-
std::vector<std::set<std::pair<Point, Point>>> fixedMaxRectangles(numLayers);
887+
std::vector<boost::unordered_flat_set<std::pair<Point, Point>>> fixedMaxRectangles(numLayers);
888888
// get all fixed max rectangles
889889
initNet_pins_maxRectangles_getFixedMaxRectangles(net, fixedMaxRectangles);
890890

src/odb/include/odb/geom.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#include "isotropy.h"
4141
#include "odb.h"
4242
#include "utl/Logger.h"
43+
#include <boost/functional/hash.hpp>
4344

4445
namespace odb {
4546

@@ -90,6 +91,19 @@ class Point
9091
int y_ = 0;
9192
};
9293

94+
inline std::size_t hash_value(Point const& p)
95+
{
96+
size_t hash = 0;
97+
if constexpr (sizeof(size_t) == 8 && sizeof(size_t) == 2*sizeof(int)) {
98+
// Use fast identity hash if possible. We don't care about avalanching since it will be mixed later by flat_map anyway
99+
return ((size_t)p.getX() << 32) | p.getY();
100+
} else {
101+
boost::hash_combine(hash, p.x());
102+
boost::hash_combine(hash, p.y());
103+
}
104+
return hash;
105+
}
106+
93107
std::ostream& operator<<(std::ostream& os, const Point& pIn);
94108

95109
/*

0 commit comments

Comments
 (0)