From ca6a25e41ee2c3f424ead91c0d390f9d788db224 Mon Sep 17 00:00:00 2001 From: gatecat Date: Mon, 4 May 2026 16:44:45 +0200 Subject: [PATCH] static: Fix exponent overflow on big designs Signed-off-by: gatecat --- common/place/placer_static.cc | 10 +++++----- common/place/static_util.h | 34 +++++++++++++++++++--------------- 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/common/place/placer_static.cc b/common/place/placer_static.cc index 66c045b7..79fafc4c 100644 --- a/common/place/placer_static.cc +++ b/common/place/placer_static.cc @@ -129,11 +129,11 @@ struct PlacerBin struct PlacerPort { // for wirelength data - static constexpr float invalid = std::numeric_limits::lowest(); + static constexpr double invalid = std::numeric_limits::lowest(); PortRef ref; - RealPair max_exp{invalid, invalid}; - RealPair min_exp{invalid, invalid}; + DoublePair max_exp{invalid, invalid}; + DoublePair min_exp{invalid, invalid}; bool has_max_exp(Axis axis) const { return max_exp.at(axis) != invalid; } bool has_min_exp(Axis axis) const { return min_exp.at(axis) != invalid; } }; @@ -143,8 +143,8 @@ struct PlacerNet NetInfo *ni; bool skip = false; RealPair b1, b0; // real bounding box - RealPair min_exp, x_min_exp; - RealPair max_exp, x_max_exp; + DoublePair min_exp, x_min_exp; + DoublePair max_exp, x_max_exp; RealPair wa_wl; // lines up with user indexes; plus one for driver std::vector ports; diff --git a/common/place/static_util.h b/common/place/static_util.h index ece951b1..64dc6e03 100644 --- a/common/place/static_util.h +++ b/common/place/static_util.h @@ -35,34 +35,38 @@ enum class Axis Y }; -struct RealPair +template +struct RealPairTempl { - RealPair() : x(0), y(0) {}; - RealPair(float x, float y) : x(x), y(y) {}; - explicit RealPair(Loc l, float bias = 0.0f) : x(l.x + bias), y(l.y + bias) {}; - float x, y; - RealPair &operator+=(const RealPair &other) + RealPairTempl() : x(0), y(0) {}; + RealPairTempl(T x, T y) : x(x), y(y) {}; + explicit RealPairTempl(Loc l, T bias = 0.0f) : x(l.x + bias), y(l.y + bias) {}; + T x, y; + RealPairTempl &operator+=(const RealPairTempl &other) { x += other.x; y += other.y; return *this; } - RealPair &operator/=(float factor) + RealPairTempl &operator/=(T factor) { x /= factor; y /= factor; return *this; } - friend RealPair operator+(RealPair a, RealPair b); - friend RealPair operator-(RealPair a, RealPair b); - RealPair operator*(float factor) const { return RealPair(x * factor, y * factor); } - RealPair operator/(float factor) const { return RealPair(x / factor, y / factor); } + template friend RealPairTempl operator+(RealPairTempl a, RealPairTempl b); + template friend RealPairTempl operator-(RealPairTempl a, RealPairTempl b); + RealPairTempl operator*(T factor) const { return RealPairTempl(x * factor, y * factor); } + RealPairTempl operator/(T factor) const { return RealPairTempl(x / factor, y / factor); } // to simplify axis-generic code - inline float &at(Axis axis) { return (axis == Axis::Y) ? y : x; } - inline const float &at(Axis axis) const { return (axis == Axis::Y) ? y : x; } + inline T &at(Axis axis) { return (axis == Axis::Y) ? y : x; } + inline const T &at(Axis axis) const { return (axis == Axis::Y) ? y : x; } }; -inline RealPair operator+(RealPair a, RealPair b) { return RealPair(a.x + b.x, a.y + b.y); } -inline RealPair operator-(RealPair a, RealPair b) { return RealPair(a.x - b.x, a.y - b.y); } +template inline RealPairTempl operator+(RealPairTempl a, RealPairTempl b) { return RealPairTempl(a.x + b.x, a.y + b.y); } +template inline RealPairTempl operator-(RealPairTempl a, RealPairTempl b) { return RealPairTempl(a.x - b.x, a.y - b.y); } + +using RealPair = RealPairTempl; +using DoublePair = RealPairTempl; // array2d; but as ourafft wants it struct FFTArray