From 06f94cafd8099b8a1bdd380ca5344c61d537657d Mon Sep 17 00:00:00 2001 From: Matt Liberty Date: Sun, 13 Jul 2025 17:59:51 +0000 Subject: [PATCH] Add a less operator to BddPortVarMap (#258) bdd_port_var_map_, of type BddPortVarMap, is iterated over in Power::evalBddActivity. Previously the map used pointer comparison so the iteration order was non-deterministic. The computed density was therefore non-deterministic due to the non-associativity of floating-point addition. Signed-off-by: Matt Liberty --- include/sta/Bdd.hh | 2 +- include/sta/LibertyClass.hh | 6 ++++++ liberty/Liberty.cc | 7 +++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/include/sta/Bdd.hh b/include/sta/Bdd.hh index e34a7bd7..b0497d25 100644 --- a/include/sta/Bdd.hh +++ b/include/sta/Bdd.hh @@ -34,7 +34,7 @@ struct DdManager; namespace sta { -typedef std::map BddPortVarMap; +typedef std::map BddPortVarMap; typedef std::map BddVarIdxPortMap; class Bdd : public StaState diff --git a/include/sta/LibertyClass.hh b/include/sta/LibertyClass.hh index b28d0765..06f2729f 100644 --- a/include/sta/LibertyClass.hh +++ b/include/sta/LibertyClass.hh @@ -145,6 +145,12 @@ enum class TableAxisVariable { enum class PathType { clk, data, clk_and_data }; const int path_type_count = 2; +class LibertyPortLess +{ +public: + bool operator()(const LibertyPort *port1, const LibertyPort *port2) const; +}; + class LibertyPortNameLess { public: diff --git a/liberty/Liberty.cc b/liberty/Liberty.cc index 9eeb9536..5a05c424 100644 --- a/liberty/Liberty.cc +++ b/liberty/Liberty.cc @@ -2833,6 +2833,13 @@ sortByName(const LibertyPortSet *set) return ports; } +bool +LibertyPortLess::operator()(const LibertyPort *port1, + const LibertyPort *port2) const +{ + return LibertyPort::less(port1, port2); +} + bool LibertyPortNameLess::operator()(const LibertyPort *port1, const LibertyPort *port2) const