From 9f9ad0b4ab5f39e3f57f7c7e887328fab34986be Mon Sep 17 00:00:00 2001 From: James Cherry Date: Sun, 14 Sep 2025 11:43:59 -0700 Subject: [PATCH] clkInfoCmp, tagCmp Signed-off-by: James Cherry --- include/sta/MinMaxValues.hh | 30 ++++++++++++++++++++++++++++-- search/ClkInfo.cc | 23 +++++++++++++++++------ search/Tag.cc | 4 ++-- 3 files changed, 47 insertions(+), 10 deletions(-) diff --git a/include/sta/MinMaxValues.hh b/include/sta/MinMaxValues.hh index 60c06b78..85741be9 100644 --- a/include/sta/MinMaxValues.hh +++ b/include/sta/MinMaxValues.hh @@ -149,8 +149,8 @@ public: exists_[mm_index] = false; } - static bool equal(MinMaxValues *values1, - MinMaxValues *values2) + static bool equal(const MinMaxValues *values1, + const MinMaxValues *values2) { return ((!values1->exists_[MinMax::minIndex()] && !values2->exists_[MinMax::minIndex()]) @@ -166,6 +166,32 @@ public: == values2->values_[MinMax::maxIndex()])); } + static bool less(const MinMaxValues *values1, + const MinMaxValues *values2) + { + if (!values1->exists_[MinMax::minIndex()] + && values2->exists_[MinMax::minIndex()]) + return -1; + if (values1->exists_[MinMax::minIndex()] + && !values2->exists_[MinMax::minIndex()]) + return 1; + if (!values1->exists_[MinMax::maxIndex()] + && values2->exists_[MinMax::maxIndex()]) + return -1; + if (values1->exists_[MinMax::maxIndex()] + && !values2->exists_[MinMax::maxIndex()]) + return 1; + if (values1->values_[MinMax::minIndex()] < values2->values_[MinMax::minIndex()]) + return -1; + if (values1->values_[MinMax::minIndex()] > values2->values_[MinMax::minIndex()]) + return 1; + if (values1->values_[MinMax::maxIndex()] < values2->values_[MinMax::maxIndex()]) + return -1; + if (values1->values_[MinMax::maxIndex()] > values2->values_[MinMax::maxIndex()]) + return 1; + return 0; + } + private: TYPE values_[MinMax::index_count]; bool exists_[MinMax::index_count]; diff --git a/search/ClkInfo.cc b/search/ClkInfo.cc index c8677efe..bae9b5b3 100644 --- a/search/ClkInfo.cc +++ b/search/ClkInfo.cc @@ -271,18 +271,23 @@ clkInfoCmp(const ClkInfo *clk_info1, if (path_ap_index1 > path_ap_index2) return 1; + const Network *network = sta->network(); const Pin *clk_src1 = clk_info1->clkSrc(); const Pin *clk_src2 = clk_info2->clkSrc(); - if (clk_src1 < clk_src2) + int clk_src_id1 = clk_src1 ? network->id(clk_src1) : -1; + int clk_src_id2 = clk_src2 ? network->id(clk_src2) : -1; + if (clk_src_id1 < clk_src_id2) return -1; - if (clk_src1 > clk_src2) + if (clk_src_id1 > clk_src_id2) return 1; const Pin *gen_clk_src1 = clk_info1->genClkSrc(); const Pin *gen_clk_src2 = clk_info2->genClkSrc(); - if (gen_clk_src1 < gen_clk_src2) + int gen_clk_src_id1 = gen_clk_src1 ? network->id(gen_clk_src1) : -1; + int gen_clk_src_id2 = gen_clk_src2 ? network->id(gen_clk_src2) : -1; + if (gen_clk_src_id1 < gen_clk_src_id2) return -1; - if (gen_clk_src1 > gen_clk_src2) + if (gen_clk_src_id1 > gen_clk_src_id2) return 1; bool crpr_on = sta->crprActive(); @@ -296,9 +301,15 @@ clkInfoCmp(const ClkInfo *clk_info1, const ClockUncertainties *uncertainties1 = clk_info1->uncertainties(); const ClockUncertainties *uncertainties2 = clk_info2->uncertainties(); - if (uncertainties1 < uncertainties2) + if (uncertainties1 == nullptr && uncertainties2) return -1; - if (uncertainties1 > uncertainties2) + if (uncertainties1 && uncertainties2 == nullptr) + return 1; + if (uncertainties1 && uncertainties2 + && MinMaxValues::less(uncertainties1, uncertainties2)) + return -1; + if (uncertainties1 && uncertainties2 + && MinMaxValues::less(uncertainties2, uncertainties1)) return 1; const Arrival &insert1 = clk_info1->insertion(); diff --git a/search/Tag.cc b/search/Tag.cc index ca246ad8..3db771b3 100644 --- a/search/Tag.cc +++ b/search/Tag.cc @@ -338,8 +338,8 @@ tagCmp(const Tag *tag1, InputDelay *input_delay1 = tag1->inputDelay(); InputDelay *input_delay2 = tag2->inputDelay(); - int input_delay_index1 = input_delay1 ? input_delay1->index() : 0; - int input_delay_index2 = input_delay2 ? input_delay2->index() : 0; + int input_delay_index1 = input_delay1 ? input_delay1->index() : -1; + int input_delay_index2 = input_delay2 ? input_delay2->index() : -1; if (input_delay_index1 < input_delay_index2) return -1; if (input_delay_index1 > input_delay_index2)