gpl, pdn: fix NaN clamp bypass and -min_width_layers edge cases#10734
gpl, pdn: fix NaN clamp bypass and -min_width_layers edge cases#10734ranaumarnadeem wants to merge 1 commit into
Conversation
Signed-off-by: ranaumarnadeemgit config --global user.name ranaumarnadeem <ranaumarnadeem632@gmail.com>
There was a problem hiding this comment.
Code Review
This pull request introduces NaN handling for the skew_fraction parameter in replace.cpp, clamping it to a default value of 0.10f when NaN. In connect.cpp, it adds validation to ensure layers are intermediate routing layers before inserting them, and updates via rectangle generation to snap coordinates to the manufacturing grid. The review feedback suggests optimizing the NaN check in replace.cpp by using a local variable and replacing the magic number 0.10f with a named constant. Additionally, a null check is recommended in connect.cpp to prevent potential null pointer dereferences when iterating over layers.
| if (std::isnan(skew_fraction) || skew_fraction < 0.0f | ||
| || skew_fraction > 1.0f) { | ||
| log_->warn(GPL, | ||
| 165, | ||
| "virtual_cts_max_skew_fraction {} out of range [0, 1]; " | ||
| "clamping.", | ||
| skew_fraction); | ||
| skew_fraction = std::clamp(skew_fraction, 0.0f, 1.0f); | ||
| skew_fraction = std::isnan(skew_fraction) | ||
| ? 0.10f | ||
| : std::clamp(skew_fraction, 0.0f, 1.0f); | ||
| } |
There was a problem hiding this comment.
The std::isnan(skew_fraction) check is performed twice: once in the if condition and once in the ternary operator. Storing the result of std::isnan(skew_fraction) in a local boolean variable avoids redundant calls and improves code readability. Additionally, avoid using hardcoded magic numbers like 0.10f for default values; define them as named constants instead.
| if (std::isnan(skew_fraction) || skew_fraction < 0.0f | |
| || skew_fraction > 1.0f) { | |
| log_->warn(GPL, | |
| 165, | |
| "virtual_cts_max_skew_fraction {} out of range [0, 1]; " | |
| "clamping.", | |
| skew_fraction); | |
| skew_fraction = std::clamp(skew_fraction, 0.0f, 1.0f); | |
| skew_fraction = std::isnan(skew_fraction) | |
| ? 0.10f | |
| : std::clamp(skew_fraction, 0.0f, 1.0f); | |
| } | |
| constexpr float default_skew_fraction = 0.10f; | |
| const bool is_nan = std::isnan(skew_fraction); | |
| if (is_nan || skew_fraction < 0.0f | |
| || skew_fraction > 1.0f) { | |
| log_->warn(GPL, | |
| 165, | |
| "virtual_cts_max_skew_fraction {} out of range [0, 1]; " | |
| "clamping.", | |
| skew_fraction); | |
| skew_fraction = is_nan | |
| ? default_skew_fraction | |
| : std::clamp(skew_fraction, 0.0f, 1.0f); | |
| } |
References
- Define tunable parameters as named constants instead of using hardcoded magic numbers.
| for (auto* layer : layers) { | ||
| const bool is_intermediate | ||
| = std::ranges::find(intermediate_routing_layers_, layer) | ||
| != intermediate_routing_layers_.end(); |
There was a problem hiding this comment.
If any element in the layers vector is nullptr, dereferencing it via layer->getName() will cause a segmentation fault. Adding a null check for layer before processing ensures robustness.
for (auto* layer : layers) {
if (layer == nullptr) {
continue;
}
const bool is_intermediate
= std::ranges::find(intermediate_routing_layers_, layer)
!= intermediate_routing_layers_.end();|
Please don't lump unrelated changes into one PR. Is there a real issue with that generated the snap change? |
Summary
NaNpassed to-virtual_cts_max_skew_fractionbypassed the[0, 1]range guard entirely. Both ordered comparisons (
< 0.0f,> 1.0f) arefalse for
NaN, sostd::clampwas never reached and the rawNaNvalue was stored in
max_skew_fraction_. This caused every subsequentsetClockLatencycall to receive aNaNdelay, silently corruptingtiming-driven placement with no diagnostic.
Fix: add an explicit
std::isnancheck before the existing range guard.NaNis reset to the default0.10and the existingGPL-0165warningis fired, consistent with how out-of-range values are already handled.
Type of Change
Impact
Designs using
-virtual_cts_max_skew_fraction NaN(or any expressionthat evaluates to
NaN) no longer silently corrupt timing analysis.A
[WARNING GPL-0165]is emitted and the value clamps to0.10.All valid inputs are unaffected.
Verification
./etc/Build.sh).Related Issues
Introduced by #10294 (gpl: virtual CTS).