From e457cf5234ecdc2a9b7ec5b605ddb01074a35793 Mon Sep 17 00:00:00 2001 From: Kamil Danecki Date: Fri, 13 Feb 2026 14:38:27 +0100 Subject: [PATCH] Add comments explaining negative exponent handling Signed-off-by: Kamil Danecki --- src/V3Randomize.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/V3Randomize.cpp b/src/V3Randomize.cpp index cbcc5fb20..ddd6711fc 100644 --- a/src/V3Randomize.cpp +++ b/src/V3Randomize.cpp @@ -1370,6 +1370,8 @@ class ConstraintExprVisitor final : public VNVisitor { powerp->user1(true); } } else if (exponent < 0) { + // Limit chain of divisions to max 2, because operations are on integers. + // Two divisions are needed to preserve the sign. powerp = new AstDivS{fl, powerp, basep->cloneTreePure(false)}; powerp->user1(true); if (exponent % 2 == 0) { @@ -1414,6 +1416,8 @@ class ConstraintExprVisitor final : public VNVisitor { powerp->user1(true); } } else if (exponent < 0) { + // Only one division in needed because operations are on integers and base is unsigned. + // More divisions would still result in same results. powerp = new AstDiv{fl, powerp, basep->cloneTreePure(false)}; powerp->user1(true); }