From 7b7ea9675ef86b125213c584a9bee7cccd262154 Mon Sep 17 00:00:00 2001 From: James Cherry Date: Sat, 21 Dec 2024 16:53:48 -0700 Subject: [PATCH] Use double for tns, inspired by pr155 Signed-off-by: James Cherry --- graph/DelayNormal1.cc | 35 +++++++++++++++++++++++++++++++++ graph/DelayNormal2.cc | 39 +++++++++++++++++++++++++++++++++++++ include/sta/DelayFloat.hh | 2 ++ include/sta/DelayNormal1.hh | 25 ++++++++++++++++++++++++ include/sta/DelayNormal2.hh | 29 +++++++++++++++++++++++++++ include/sta/Search.hh | 3 ++- 6 files changed, 132 insertions(+), 1 deletion(-) diff --git a/graph/DelayNormal1.cc b/graph/DelayNormal1.cc index 294766c1..603c012d 100644 --- a/graph/DelayNormal1.cc +++ b/graph/DelayNormal1.cc @@ -63,6 +63,12 @@ Delay::Delay(const Delay &delay) : { } +Delay::Delay(const DelayDbl &delay) : + mean_(delay.mean_), + sigma2_(delay.sigma2_) +{ +} + Delay::Delay(float mean) : mean_(mean), sigma2_(0.0) @@ -173,6 +179,35 @@ Delay::operator==(const Delay &delay) const //////////////////////////////////////////////////////////////// +DelayDbl::DelayDbl() : + mean_(0.0), + sigma2_(0.0) +{ +} + +void +DelayDbl::operator=(float delay) +{ + mean_ = delay; + sigma2_ = 0.0; +} + +void +DelayDbl::operator+=(const Delay &delay) +{ + mean_ += delay.mean_; + sigma2_ += delay.sigma2_; +} + +void +DelayDbl::operator-=(const Delay &delay) +{ + mean_ -= delay.mean_; + sigma2_ += delay.sigma2_; +} + +//////////////////////////////////////////////////////////////// + Delay makeDelay(float delay, float sigma, diff --git a/graph/DelayNormal2.cc b/graph/DelayNormal2.cc index 4bdd482b..bd444e51 100644 --- a/graph/DelayNormal2.cc +++ b/graph/DelayNormal2.cc @@ -64,6 +64,13 @@ Delay::Delay(const Delay &delay) : sigma2_[EarlyLate::lateIndex()] = delay.sigma2_[EarlyLate::lateIndex()]; } +Delay::Delay(const DelayDbl &delay) : + mean_(delay.mean_) +{ + sigma2_[EarlyLate::earlyIndex()] = delay.sigma2_[EarlyLate::earlyIndex()]; + sigma2_[EarlyLate::lateIndex()] = delay.sigma2_[EarlyLate::lateIndex()]; +} + Delay::Delay(float mean) : mean_(mean), sigma2_{0.0, 0.0} @@ -196,6 +203,38 @@ Delay::operator==(const Delay &delay) const //////////////////////////////////////////////////////////////// +DelayDbl::DelayDbl() : + mean_(0.0), + sigma2_{0.0, 0.0} +{ +} + +void +DelayDbl::operator=(float delay) +{ + mean_ = delay; + sigma2_[early_index] = 0.0; + sigma2_[late_index] = 0.0; +} + +void +DelayDbl::operator+=(const Delay &delay) +{ + mean_ += delay.mean_; + sigma2_[early_index] += delay.sigma2_[early_index]; + sigma2_[late_index] += delay.sigma2_[late_index]; +} + +void +DelayDbl::operator-=(const Delay &delay) +{ + mean_ -= delay.mean_; + sigma2_[early_index] += delay.sigma2_[early_index]; + sigma2_[late_index] += delay.sigma2_[late_index]; +} + +//////////////////////////////////////////////////////////////// + Delay makeDelay(float delay, float sigma_early, diff --git a/include/sta/DelayFloat.hh b/include/sta/DelayFloat.hh index 68143025..800c7e03 100644 --- a/include/sta/DelayFloat.hh +++ b/include/sta/DelayFloat.hh @@ -25,6 +25,8 @@ namespace sta { class StaState; typedef float Delay; +// Delay double for accumulating Delays. +typedef double DelayDbl; const Delay delay_zero = 0.0; diff --git a/include/sta/DelayNormal1.hh b/include/sta/DelayNormal1.hh index a8bbacc8..103fe881 100644 --- a/include/sta/DelayNormal1.hh +++ b/include/sta/DelayNormal1.hh @@ -21,6 +21,7 @@ namespace sta { class Delay; +class DelayDbl; class StaState; // Normal distribution with std deviation. @@ -29,6 +30,7 @@ class Delay public: Delay(); Delay(const Delay &delay); + Delay(const DelayDbl &delay); Delay(float mean); Delay(float mean, float sigma2); @@ -53,6 +55,29 @@ private: float mean_; // Sigma^2 float sigma2_; + + friend class DelayDbl; +}; + +// Dwlay with doubles for accumulating delays. +class DelayDbl +{ +public: + DelayDbl(); + float mean() const { return mean_; } + float sigma() const; + // sigma^2 + float sigma2() const; + void operator=(float delay); + void operator+=(const Delay &delay); + void operator-=(const Delay &delay); + +private: + double mean_; + // Sigma^2 + double sigma2_; + + friend class Delay; }; const Delay delay_zero(0.0); diff --git a/include/sta/DelayNormal2.hh b/include/sta/DelayNormal2.hh index f7aac325..5f77eacd 100644 --- a/include/sta/DelayNormal2.hh +++ b/include/sta/DelayNormal2.hh @@ -21,6 +21,7 @@ namespace sta { class Delay; +class DelayDbl; class StaState; // Normal distribution with early(left)/late(right) std deviations. @@ -29,6 +30,7 @@ class Delay public: Delay(); Delay(const Delay &delay); + Delay(const DelayDbl &delay); Delay(float mean); Delay(float mean, float sigma2_early, @@ -60,6 +62,33 @@ private: float mean_; // Sigma^2 float sigma2_[EarlyLate::index_count]; + + friend class DelayDbl; +}; + +// Dwlay with doubles for accumulating delays. +class DelayDbl +{ +public: + DelayDbl(); + float mean() const { return mean_; } + float sigma() const; + // sigma^2 + float sigma2() const; + void operator=(float delay); + void operator+=(const Delay &delay); + void operator-=(const Delay &delay); + +protected: + static const int early_index = 0; + static const int late_index = 1; + +private: + double mean_; + // Sigma^2 + double sigma2_[EarlyLate::index_count]; + + friend class Delay; }; const Delay delay_zero(0.0); diff --git a/include/sta/Search.hh b/include/sta/Search.hh index 5b3d6772..8dce6775 100644 --- a/include/sta/Search.hh +++ b/include/sta/Search.hh @@ -60,6 +60,7 @@ typedef UnorderedSet TagGroupSet; typedef Map VertexSlackMap; typedef Vector VertexSlackMapSeq; typedef Vector WorstSlacksSeq; +typedef vector DelayDblSeq; class Search : public StaState { @@ -570,7 +571,7 @@ protected: // Endpoint vertices with slacks that have changed since tns was found. VertexSet *invalid_tns_; // Indexed by path_ap->index(). - SlackSeq tns_; + DelayDblSeq tns_; // Indexed by path_ap->index(). VertexSlackMapSeq tns_slacks_; std::mutex tns_lock_;