From efb83c55de537368a8fbdd6b56a3263baa335437 Mon Sep 17 00:00:00 2001 From: Geza Lore Date: Wed, 3 Jun 2026 08:42:48 +0100 Subject: [PATCH] Optimize VL_SFORMAT when result is string (#7702) Omit unused bit width parameter. Emit rule is simple enough to change and the unused parameter just bloats code size. --- include/verilated.cpp | 4 +--- include/verilated_funcs.h | 4 ++-- src/V3EmitCFunc.cpp | 6 ++++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/include/verilated.cpp b/include/verilated.cpp index 3a6d4e746..31cd07ba6 100644 --- a/include/verilated.cpp +++ b/include/verilated.cpp @@ -1888,9 +1888,7 @@ void VL_SFORMAT_NX(int obits, EData* destp, const std::string& format, int argc, _vl_string_to_vint(obits, destp, t_output.length(), t_output.c_str()); } -void VL_SFORMAT_NX(int obits_ignored, std::string& output, const std::string& format, int argc, - ...) VL_MT_SAFE { - (void)obits_ignored; // So VL_SFORMAT_NNX function signatures all match +void VL_SFORMAT_NX(std::string& output, const std::string& format, int argc, ...) VL_MT_SAFE { std::string temp_output; va_list ap; va_start(ap, argc); diff --git a/include/verilated_funcs.h b/include/verilated_funcs.h index c9bd55c04..0fefe9e25 100644 --- a/include/verilated_funcs.h +++ b/include/verilated_funcs.h @@ -3668,8 +3668,8 @@ extern void VL_WRITEMEM_N(bool hex, int bits, QData depth, int array_lsb, QData end) VL_MT_SAFE; extern IData VL_SSCANF_INNX(int lbits, const std::string& ld, const std::string& format, int argc, ...) VL_MT_SAFE; -extern void VL_SFORMAT_NX(int obits_ignored, std::string& output, const std::string& format, - int argc, ...) VL_MT_SAFE; +extern void VL_SFORMAT_NX(std::string& output, const std::string& format, int argc, + ...) VL_MT_SAFE; extern std::string VL_SFORMATF_N_NX(const std::string& format, int argc, ...) VL_MT_SAFE; extern void VL_TIMEFORMAT_IINI(bool hasUnits, int units, bool hasPrecision, int precision, bool hasSuffix, const std::string& suffix, bool hasWidth, int width, diff --git a/src/V3EmitCFunc.cpp b/src/V3EmitCFunc.cpp index 5b1d2444c..5570825bd 100644 --- a/src/V3EmitCFunc.cpp +++ b/src/V3EmitCFunc.cpp @@ -224,8 +224,10 @@ bool EmitCFunc::displayEmitHeader(AstNode* nodep) { } else if (const AstSFormat* const dispp = VN_CAST(nodep, SFormat)) { isStmt = true; puts("VL_SFORMAT_NX("); - puts(cvtToStr(dispp->lhsp()->widthMin())); - putbs(","); + if (!dispp->lhsp()->dtypep()->isString()) { + puts(cvtToStr(dispp->lhsp()->widthMin())); + putbs(","); + } iterateConst(dispp->lhsp()); emitDatap(dispp->lhsp()); putbs(",");