Skip to content

grt: add prevent division by zero and overflow when computing resistance cost#10034

Merged
maliberty merged 2 commits intoThe-OpenROAD-Project:masterfrom
eder-matheus:grt_res_aware_guard
Apr 6, 2026
Merged

grt: add prevent division by zero and overflow when computing resistance cost#10034
maliberty merged 2 commits intoThe-OpenROAD-Project:masterfrom
eder-matheus:grt_res_aware_guard

Conversation

@eder-matheus
Copy link
Copy Markdown
Member

@eder-matheus eder-matheus commented Apr 2, 2026

Summary

Check if default_resistance and final_resistance values are valid for the division performed later. This shouldn't impact any of our designs, but acts as a guard for cases where resistance is not defined for a specific routing/via layer.

Type of Change

  • Bug fix

Impact

No impact on ORFS designs.

Verification

  • I have verified that the local build succeeds (./etc/Build.sh).
  • I have run the relevant tests and they pass.
  • My code follows the repository's formatting guidelines.
  • I have signed my commits (DCO).

Related Issues

[Link issues here]

…nce cost

Signed-off-by: Eder Monteiro <emrmonteiro@precisioninno.com>
@eder-matheus eder-matheus requested a review from maliberty April 2, 2026 16:00
@eder-matheus
Copy link
Copy Markdown
Member Author

@jfgava FYI.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 2, 2026

clang-tidy review says "All clean, LGTM! 👍"

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces safety checks in getWireCost and getViaCost to prevent division by zero and handle large resistance values. Feedback highlights a remaining risk of integer overflow when the divisor is a very small positive number and suggests calculating the cost as a double with explicit clamping to BIG_INT before casting to an integer.

@Divinesoumyadip
Copy link
Copy Markdown
Contributor

Nice fix @eder-matheus Just one thing I noticed that if final_resistance is a very small positive float (not zero but close to it), the ceil result could still overflow when implicitly cast to int.
Something like this might be safer:
return static_cast<int>(std::min(std::ceil(final_resistance / default_resistance), static_cast<double>(BIG_INT)));
Same edge case applies to the via cost path too. Rest looks clean.

Signed-off-by: Eder Monteiro <emrmonteiro@precisioninno.com>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 3, 2026

clang-tidy review says "All clean, LGTM! 👍"

@maliberty maliberty enabled auto-merge April 6, 2026 14:34
@maliberty
Copy link
Copy Markdown
Member

Is this for some sort of benchmark? It would be odd to have no layer resistance in a production pdk.

@eder-matheus
Copy link
Copy Markdown
Member Author

Is this for some sort of benchmark? It would be odd to have no layer resistance in a production pdk.

I faced this issue on a private PDK I'm working on. I added this guard to prevent crash/errors on it.

@maliberty maliberty merged commit 77806f9 into The-OpenROAD-Project:master Apr 6, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants