From 7e8bafd21726eaf84802863d3d9300236b8a37b5 Mon Sep 17 00:00:00 2001 From: Geza Lore Date: Tue, 12 Jul 2022 18:37:26 +0100 Subject: [PATCH] Remove static data use from PartContraction::siblingPairFromRelatives Use std::sort with lambda rather than qsort with static function and static data. Verilation performance neutral. --- src/V3Partition.cpp | 28 ++++++++-------------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/src/V3Partition.cpp b/src/V3Partition.cpp index a4177c214..53f101ae3 100644 --- a/src/V3Partition.cpp +++ b/src/V3Partition.cpp @@ -30,6 +30,7 @@ #include "V3Stats.h" #include "V3UniqueNames.h" +#include #include #include #include @@ -1529,20 +1530,6 @@ private: } } - static const GraphWay* s_shortestWaywardCpInclusiveWay; - static int shortestWaywardCpInclusive(const void* vap, const void* vbp) { - const GraphWay* const wp = s_shortestWaywardCpInclusiveWay; - const LogicMTask* const ap = *reinterpret_cast(vap); - const LogicMTask* const bp = *reinterpret_cast(vbp); - const uint32_t aCp = ap->critPathCost(*wp) + ap->stepCost(); - const uint32_t bCp = bp->critPathCost(*wp) + bp->stepCost(); - if (aCp < bCp) return -1; - if (aCp > bCp) return 1; - if (ap->id() < bp->id()) return -1; - if (ap->id() > bp->id()) return 1; - return 0; - } - void siblingPairFromRelatives(GraphWay way, V3GraphVertex* mtaskp, bool exhaustive) { std::vector shortestPrereqs; @@ -1556,10 +1543,13 @@ private: if (shortestPrereqs.empty()) return; - // qsort_r would be nice here, but it isn't portable - s_shortestWaywardCpInclusiveWay = &way; - qsort(&shortestPrereqs[0], shortestPrereqs.size(), sizeof(LogicMTask*), - &shortestWaywardCpInclusive); + std::sort(shortestPrereqs.begin(), shortestPrereqs.end(), + [way](const LogicMTask* ap, const LogicMTask* bp) { + const uint32_t aCp = ap->critPathCost(way) + ap->stepCost(); + const uint32_t bCp = bp->critPathCost(way) + bp->stepCost(); + if (aCp != bCp) return aCp < bCp; + return ap->id() < bp->id(); + }); // Don't make all NxN/2 possible pairs of prereqs, that's a lot // to cart around. Just make a few pairs. @@ -1691,8 +1681,6 @@ private: VL_UNCOPYABLE(PartContraction); }; -const GraphWay* PartContraction::s_shortestWaywardCpInclusiveWay = nullptr; - //###################################################################### // DpiImportCallVisitor