Skip to content

Commit 3b19727

Browse files
committed
Replace std::set of points pairs with boost flat hashmap
Signed-off-by: Szymon Gizler <[email protected]>
1 parent d12ccce commit 3b19727

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;
@@ -191,31 +192,31 @@ class FlexGCWorker::Impl
191192
void initNet_pins_polygonEdges(gcNet* net);
192193
void initNet_pins_polygonEdges_getFixedPolygonEdges(
193194
gcNet* net,
194-
std::vector<std::set<std::pair<Point, Point>>>& fixedPolygonEdges);
195+
std::vector<boost::unordered_flat_set<std::pair<Point, Point>>>& fixedPolygonEdges);
195196
void initNet_pins_polygonEdges_helper_outer(
196197
gcNet* net,
197198
gcPin* pin,
198199
gcPolygon* poly,
199200
frLayerNum i,
200-
const std::vector<std::set<std::pair<Point, Point>>>& fixedPolygonEdges);
201+
const std::vector<boost::unordered_flat_set<std::pair<Point, Point>>>& fixedPolygonEdges);
201202
void initNet_pins_polygonEdges_helper_inner(
202203
gcNet* net,
203204
gcPin* pin,
204205
const gtl::polygon_90_data<frCoord>& hole_poly,
205206
frLayerNum i,
206-
const std::vector<std::set<std::pair<Point, Point>>>& fixedPolygonEdges);
207+
const std::vector<boost::unordered_flat_set<std::pair<Point, Point>>>& fixedPolygonEdges);
207208
void initNet_pins_polygonCorners(gcNet* net);
208209
void initNet_pins_polygonCorners_helper(gcNet* net, gcPin* pin);
209210
void initNet_pins_maxRectangles(gcNet* net);
210211
void initNet_pins_maxRectangles_getFixedMaxRectangles(
211212
gcNet* net,
212-
std::vector<std::set<std::pair<Point, Point>>>& fixedMaxRectangles);
213+
std::vector<boost::unordered_flat_set<std::pair<Point, Point>>>& fixedMaxRectangles);
213214
void initNet_pins_maxRectangles_helper(
214215
gcNet* net,
215216
gcPin* pin,
216217
const gtl::rectangle_data<frCoord>& rect,
217218
frLayerNum i,
218-
const std::vector<std::set<std::pair<Point, Point>>>& fixedMaxRectangles);
219+
const std::vector<boost::unordered_flat_set<std::pair<Point, Point>>>& fixedMaxRectangles);
219220

220221
void initRegionQuery();
221222

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

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

853853
void FlexGCWorker::Impl::initNet_pins_maxRectangles_getFixedMaxRectangles(
854854
gcNet* net,
855-
std::vector<std::set<std::pair<Point, Point>>>& fixedMaxRectangles)
855+
std::vector<boost::unordered_flat_set<std::pair<Point, Point>>>& fixedMaxRectangles)
856856
{
857857
int numLayers = getTech()->getLayers().size();
858858
std::vector<gtl::rectangle_data<frCoord>> rects;
@@ -878,7 +878,7 @@ void FlexGCWorker::Impl::initNet_pins_maxRectangles_helper(
878878
gcPin* pin,
879879
const gtl::rectangle_data<frCoord>& rect,
880880
frLayerNum i,
881-
const std::vector<std::set<std::pair<Point, Point>>>& fixedMaxRectangles)
881+
const std::vector<boost::unordered_flat_set<std::pair<Point, Point>>>& fixedMaxRectangles)
882882
{
883883
auto rectangle = std::make_unique<gcRect>();
884884
rectangle->setRect(rect);
@@ -916,7 +916,7 @@ void FlexGCWorker::Impl::initNet_pins_maxRectangles_helper(
916916
void FlexGCWorker::Impl::initNet_pins_maxRectangles(gcNet* net)
917917
{
918918
int numLayers = getTech()->getLayers().size();
919-
std::vector<std::set<std::pair<Point, Point>>> fixedMaxRectangles(numLayers);
919+
std::vector<boost::unordered_flat_set<std::pair<Point, Point>>> fixedMaxRectangles(numLayers);
920920
// get all fixed max rectangles
921921
initNet_pins_maxRectangles_getFixedMaxRectangles(net, fixedMaxRectangles);
922922

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)