From 35bb3f3a8d608f92a1bfffc27a04b6bb178c33ae Mon Sep 17 00:00:00 2001 From: Rowan Goemans Date: Wed, 18 Sep 2024 00:33:33 +0200 Subject: [PATCH] timing: Add safe zero check function for delay_t --- common/kernel/nextpnr_types.h | 10 ++++++++++ common/kernel/timing.cc | 4 ++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/common/kernel/nextpnr_types.h b/common/kernel/nextpnr_types.h index c806c186..095329c7 100644 --- a/common/kernel/nextpnr_types.h +++ b/common/kernel/nextpnr_types.h @@ -78,6 +78,16 @@ struct PortRef IdString port; }; +// Zero checking which works regardless if delay_t is floating or integer +inline bool is_zero_delay(delay_t delay) +{ + if constexpr (std::is_floating_point::value) { + return std::fpclassify(delay) == FP_ZERO; + } else { + return delay == 0; + } +} + // minimum and maximum delay struct DelayPair { diff --git a/common/kernel/timing.cc b/common/kernel/timing.cc index 7504ead2..ce4ef9a0 100644 --- a/common/kernel/timing.cc +++ b/common/kernel/timing.cc @@ -985,7 +985,7 @@ CriticalPath TimingAnalyser::build_critical_path_report(domain_id_t domain_pair, if (related_clock) { delay_t clock_delay = clock_delays.at(clock_pair); - if (clock_delay != 0) { + if (!is_zero_delay(clock_delay)) { CriticalPath::Segment seg_c2c; seg_c2c.type = CriticalPath::Segment::Type::CLK_TO_CLK; seg_c2c.delay = DelayPair(clock_delay); @@ -1005,7 +1005,7 @@ CriticalPath TimingAnalyser::build_critical_path_report(domain_id_t domain_pair, delay_t clock_skew = clock_delay_launch - clock_delay_capture; - if (clock_skew != 0) { + if (!is_zero_delay(clock_skew)) { CriticalPath::Segment seg_skew; seg_skew.type = CriticalPath::Segment::Type::CLK_SKEW; seg_skew.delay = DelayPair(clock_skew);