From 5e5dcdbdbd66a60c5b472726e060d2c2e78c9bb1 Mon Sep 17 00:00:00 2001 From: Geza Lore Date: Sun, 1 Feb 2026 13:12:18 +0000 Subject: [PATCH] Optimize right shifts as clean (#6981) --- include/verilated_funcs.h | 8 ++++---- src/V3AstNodeExpr.h | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/include/verilated_funcs.h b/include/verilated_funcs.h index 746fe359c..92c1add6c 100644 --- a/include/verilated_funcs.h +++ b/include/verilated_funcs.h @@ -1976,19 +1976,19 @@ static inline QData VL_SHIFTL_QQW(int obits, int, int rbits, QData lhs, // expression. Thus consider this when optimizing. (And perhaps have 2 funcs?) static inline IData VL_SHIFTR_III(int obits, int, int, IData lhs, IData rhs) VL_PURE { if (VL_UNLIKELY(rhs >= VL_IDATASIZE)) return 0; - return lhs >> rhs; // Small is common so assumed not clean + return lhs >> rhs; } static inline IData VL_SHIFTR_IIQ(int obits, int, int, IData lhs, QData rhs) VL_PURE { if (VL_UNLIKELY(rhs >= VL_IDATASIZE)) return 0; - return VL_CLEAN_QQ(obits, obits, lhs >> rhs); + return lhs >> rhs; } static inline QData VL_SHIFTR_QQI(int obits, int, int, QData lhs, IData rhs) VL_PURE { if (VL_UNLIKELY(rhs >= VL_QUADSIZE)) return 0; - return lhs >> rhs; // Small is common so assumed not clean + return lhs >> rhs; } static inline QData VL_SHIFTR_QQQ(int obits, int, int, QData lhs, QData rhs) VL_PURE { if (VL_UNLIKELY(rhs >= VL_QUADSIZE)) return 0; - return VL_CLEAN_QQ(obits, obits, lhs >> rhs); + return lhs >> rhs; } static inline WDataOutP VL_SHIFTR_WWI(int obits, int, int, WDataOutP owp, WDataInP const lwp, IData rd) VL_MT_SAFE { diff --git a/src/V3AstNodeExpr.h b/src/V3AstNodeExpr.h index e1dc45d03..85ac00f95 100644 --- a/src/V3AstNodeExpr.h +++ b/src/V3AstNodeExpr.h @@ -3688,7 +3688,7 @@ public: string emitSimpleOperator() override { return (rhsp()->isWide() || rhsp()->isQuad()) ? "" : ">>"; } - bool cleanOut() const override { return false; } + bool cleanOut() const override { return true; } bool cleanLhs() const override { return true; } bool cleanRhs() const override { return true; } // LHS size might be > output size, so don't want to force size @@ -3710,7 +3710,7 @@ public: string emitVerilog() override { return "%k(%l %f>> %r)"; } string emitC() override { return "VL_SHIFTR_%nq%lq%rq(%nw,%lw,%rw, %P, %li, %ri)"; } string emitSimpleOperator() override { return ""; } - bool cleanOut() const override { return false; } + bool cleanOut() const override { return true; } bool cleanLhs() const override { return true; } bool cleanRhs() const override { return true; } // LHS size might be > output size, so don't want to force size