aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorgatecat <gatecat@ds0.me>2021-07-11 08:10:57 +0100
committerGitHub <noreply@github.com>2021-07-11 08:10:57 +0100
commiteecc6147dfd560e28d630ef4fa82bcebb28e48a2 (patch)
tree193fcaa0c0438382317759337ba2c5182fc556ec
parent8531658019a5d8f7834c6054e10c8438d8006505 (diff)
parent76070a7647b9c8b9d15a914b255298bf1b6b83b6 (diff)
downloadnextpnr-eecc6147dfd560e28d630ef4fa82bcebb28e48a2.tar.gz
nextpnr-eecc6147dfd560e28d630ef4fa82bcebb28e48a2.tar.bz2
nextpnr-eecc6147dfd560e28d630ef4fa82bcebb28e48a2.zip
Merge pull request #758 from YosysHQ/gatecat/hist-oob
timing: Fix out-of-bounds histogram bins in all cases
-rw-r--r--common/timing.cc7
1 files changed, 6 insertions, 1 deletions
diff --git a/common/timing.cc b/common/timing.cc
index 30054e83..6a91b6e5 100644
--- a/common/timing.cc
+++ b/common/timing.cc
@@ -1363,7 +1363,12 @@ void timing_analysis(Context *ctx, bool print_histogram, bool print_fmax, bool p
std::vector<unsigned> bins(num_bins);
unsigned max_freq = 0;
for (const auto &i : slack_histogram) {
- auto &bin = bins[(i.first - min_slack) / bin_size];
+ int bin_idx = int((i.first - min_slack) / bin_size);
+ if (bin_idx < 0)
+ bin_idx = 0;
+ else if (bin_idx >= int(num_bins))
+ bin_idx = num_bins - 1;
+ auto &bin = bins.at(bin_idx);
bin += i.second;
max_freq = std::max(max_freq, bin);
}