vcd min time resolves #165

Signed-off-by: James Cherry <cherry@parallaxsw.com>
This commit is contained in:
James Cherry 2025-09-18 08:47:43 -07:00
parent c020334e07
commit 892a9a4a3d
3 changed files with 38 additions and 18 deletions

View File

@ -52,8 +52,8 @@ VcdParse::read(const char *filename,
Stats stats(debug_, report_);
filename_ = filename;
reader_ = reader;
file_line_ = 1;
stmt_line_ = 1;
file_line_ = 0;
stmt_line_ = 0;
std::string token = getToken();
while (!token.empty()) {
if (token == "$date")
@ -205,11 +205,19 @@ void
VcdParse::parseVarValues()
{
string token = getToken();
bool first_time = true;
while (!token.empty()) {
char char0 = toupper(token[0]);
if (char0 == '#' && token.size() > 1) {
prev_time_ = time_;
time_ = stoll(token.substr(1));
VcdTime time = stoll(token.substr(1));
if (first_time) {
prev_time_ = time;
first_time = false;
reader_->setTimeMin(time);
}
else
prev_time_ = time_;
time_ = time;
if (time_ > prev_time_)
reader_->varMinDeltaTime(time_ - prev_time_);
}
@ -286,20 +294,18 @@ VcdParse::getToken()
{
string token;
int ch = gzgetc(stream_);
if (ch == '\n')
file_line_++;
// skip whitespace
while (ch != EOF && isspace(ch)) {
ch = gzgetc(stream_);
if (ch == '\n')
file_line_++;
ch = gzgetc(stream_);
}
while (ch != EOF && !isspace(ch)) {
token.push_back(ch);
ch = gzgetc(stream_);
if (ch == '\n')
file_line_++;
}
if (ch == '\n')
file_line_++;
if (ch == EOF)
return "";
else

View File

@ -104,7 +104,8 @@ public:
virtual void setTimeUnit(const std::string &time_unit,
double time_unit_scale,
double time_scale) = 0;
virtual void setTimeMax(VcdTime time_max) = 0;
virtual void setTimeMin(VcdTime time) = 0;
virtual void setTimeMax(VcdTime time) = 0;
virtual void varMinDeltaTime(VcdTime min_delta_time) = 0;
virtual bool varIdValid(const std::string &id) = 0;
virtual void makeVar(const VcdScope &scope,

View File

@ -127,6 +127,7 @@ public:
Report *report,
Debug *debug);
VcdTime timeMax() const { return time_max_; }
VcdTime timeMin() const { return time_min_; }
const VcdIdCountsMap &countMap() const { return vcd_count_map_; }
double timeScale() const { return time_scale_; }
@ -137,7 +138,8 @@ public:
void setTimeUnit(const string &time_unit,
double time_unit_scale,
double time_scale) override;
void setTimeMax(VcdTime time_max) override;
void setTimeMin(VcdTime time) override;
void setTimeMax(VcdTime time) override;
void varMinDeltaTime(VcdTime) override {}
bool varIdValid(const string &id) override;
void makeVar(const VcdScope &scope,
@ -164,6 +166,7 @@ private:
Debug *debug_;
double time_scale_;
VcdTime time_min_;
VcdTime time_max_;
VcdIdCountsMap vcd_count_map_;
};
@ -177,7 +180,8 @@ VcdCountReader::VcdCountReader(const char *scope,
report_(report),
debug_(debug),
time_scale_(1.0),
time_max_(0.0)
time_min_(0),
time_max_(0)
{
}
@ -190,9 +194,15 @@ VcdCountReader::setTimeUnit(const string &,
}
void
VcdCountReader::setTimeMax(VcdTime time_max)
VcdCountReader::setTimeMin(VcdTime time)
{
time_max_ = time_max;
time_min_ = time;
}
void
VcdCountReader::setTimeMax(VcdTime time)
{
time_max_ = time;
}
bool
@ -400,14 +410,16 @@ ReadVcdActivities::readActivities()
void
ReadVcdActivities::setActivities()
{
VcdTime time_min = vcd_reader_.timeMin();
VcdTime time_max = vcd_reader_.timeMax();
VcdTime time_delta = time_max - time_min;
double time_scale = vcd_reader_.timeScale();
for (auto& [id, vcd_counts] : vcd_reader_.countMap()) {
for (const VcdCount &vcd_count : vcd_counts) {
double transition_count = vcd_count.transitionCount();
VcdTime high_time = vcd_count.highTime(time_max);
float duty = static_cast<double>(high_time) / time_max;
float density = transition_count / (time_max * time_scale);
float duty = static_cast<double>(high_time) / time_delta;
float density = transition_count / (time_delta * time_scale);
if (debug_->check("read_vcd_activities", 1)) {
for (const Pin *pin : vcd_count.pins()) {
debugPrint(debug_, "read_vcd_activities", 1,
@ -433,8 +445,9 @@ ReadVcdActivities::checkClkPeriod(const Pin *pin,
double transition_count)
{
VcdTime time_max = vcd_reader_.timeMax();
VcdTime time_min = vcd_reader_.timeMin();
double time_scale = vcd_reader_.timeScale();
double sim_period = time_max * time_scale / (transition_count / 2.0);
double sim_period = (time_max - time_min) * time_scale / (transition_count / 2.0);
ClockSet *clks = sdc_->findLeafPinClocks(pin);
if (clks) {
for (Clock *clk : *clks) {
@ -449,4 +462,4 @@ ReadVcdActivities::checkClkPeriod(const Pin *pin,
}
}
}
} // namespace