From 45d7312dfc9c85445e8e2298a03ec4771b2bd76d Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Thu, 8 Sep 2016 22:04:14 -0400 Subject: [PATCH] Improve Verilation performance on internal strings, msg1975. --- Changes | 2 ++ src/V3Ast.cpp | 69 +++++++++++++++++++++++++++++---------------------- 2 files changed, 41 insertions(+), 30 deletions(-) diff --git a/Changes b/Changes index 2095c0bad..f739e6fdb 100644 --- a/Changes +++ b/Changes @@ -10,6 +10,8 @@ indicates the contributor was also the author of the fix; Thanks! **** Fix error on wide numbers that represent small msb/lsb, msg1991. [Mandy Xu] +**** Improve Verilation performance on internal strings, msg1975. [Johan Bjork] + * Verilator 3.886 2016-07-30 diff --git a/src/V3Ast.cpp b/src/V3Ast.cpp index 3bc51653f..47bf1737f 100644 --- a/src/V3Ast.cpp +++ b/src/V3Ast.cpp @@ -166,44 +166,53 @@ string AstNode::vcdName(const string& namein) { } string AstNode::prettyName(const string& namein) { + // This function is somewhat hot, so we short-circuit some compares string pretty; pretty = ""; + pretty.reserve(namein.length()); for (const char* pos = namein.c_str(); *pos; ) { - if (0==strncmp(pos,"__BRA__",7)) { - pretty += "["; - pos += 7; - } - else if (0==strncmp(pos,"__KET__",7)) { - pretty += "]"; - pos += 7; - } - else if (0==strncmp(pos,"__DOT__",7)) { - pretty += "."; - pos += 7; - } - else if (0==strncmp(pos,"->",2)) { + if (pos[0]=='-' && pos[1]=='>') { // -> pretty += "."; pos += 2; + continue; } - else if (0==strncmp(pos,"__PVT__",7)) { - pretty += ""; - pos += 7; - } - else if (pos[0]=='_' && pos[1]=='_' && pos[2]=='0' - && isxdigit(pos[3]) && isxdigit(pos[4])) { - char value = 0; - value += 16*(isdigit(pos[3]) ? (pos[3]-'0') : (tolower(pos[3])-'a'+10)); - value += (isdigit(pos[4]) ? (pos[4]-'0') : (tolower(pos[4])-'a'+10)); - pretty += value; - pos += 5; - } - else { - pretty += pos[0]; - ++pos; + if (pos[0]=='_' && pos[1]=='_') { // Short-circuit + if (0==strncmp(pos,"__BRA__",7)) { + pretty += "["; + pos += 7; + continue; + } + if (0==strncmp(pos,"__KET__",7)) { + pretty += "]"; + pos += 7; + continue; + } + if (0==strncmp(pos,"__DOT__",7)) { + pretty += "."; + pos += 7; + continue; + } + if (0==strncmp(pos,"__PVT__",7)) { + pretty += ""; + pos += 7; + continue; + } + if (pos[0]=='_' && pos[1]=='_' && pos[2]=='0' + && isxdigit(pos[3]) && isxdigit(pos[4])) { + char value = 0; + value += 16*(isdigit(pos[3]) ? (pos[3]-'0') : (tolower(pos[3])-'a'+10)); + value += (isdigit(pos[4]) ? (pos[4]-'0') : (tolower(pos[4])-'a'+10)); + pretty += value; + pos += 5; + continue; + } } + // Default + pretty += pos[0]; + ++pos; } - if (pretty.substr(0,4) == "TOP.") pretty.replace(0,4,""); - if (pretty.substr(0,5) == "TOP->") pretty.replace(0,5,""); + if (pretty[0]=='T' && pretty.substr(0,4) == "TOP.") pretty.replace(0,4,""); + if (pretty[0]=='T' && pretty.substr(0,5) == "TOP->") pretty.replace(0,5,""); return pretty; }