From fd53832b6e4a5424b03b6784b21a3718a41054d3 Mon Sep 17 00:00:00 2001 From: James Cherry Date: Fri, 15 Dec 2023 17:19:19 -0700 Subject: [PATCH] TableAxis::findAxisIndex axis values are always ascending Signed-off-by: James Cherry --- liberty/LibertyReader.cc | 23 +++++++++++++++++------ liberty/TableModel.cc | 28 +++++++++++++--------------- parasitics/SpefReader.cc | 2 +- 3 files changed, 31 insertions(+), 22 deletions(-) diff --git a/liberty/LibertyReader.cc b/liberty/LibertyReader.cc index f0b026aa..a5350d7a 100644 --- a/liberty/LibertyReader.cc +++ b/liberty/LibertyReader.cc @@ -1370,15 +1370,14 @@ LibertyReader::makeAxis(int index, float scale = tableVariableUnit(axis_var, units)->scale(); scaleFloats(axis_values, scale); } - return std::make_shared(axis_var, axis_values); + return make_shared(axis_var, axis_values); } else if (axis_values) { libWarn(62, group, "missing variable_%d attribute.", index + 1); delete axis_values; axis_values_[index] = nullptr; } - // No warning for missing index_xx attributes because they are - // not required by ic_shell. + // No warning for missing index_xx attributes because they are not required. return nullptr; } @@ -1448,8 +1447,20 @@ LibertyReader::visitIndex(int index, // Ignore index_xx in ecsm_waveform groups. && !stringEq(libertyGroup()->type(), "ecsm_waveform")) { FloatSeq *axis_values = readFloatSeq(attr, 1.0F); - if (axis_values) + if (axis_values) { + if (axis_values->empty()) + libWarn(172, attr, "missing table index values."); + else { + float prev = (*axis_values)[0]; + for (size_t i = 1; i < axis_values->size(); i++) { + float value = (*axis_values)[i]; + if (value <= prev) + libWarn(173, attr, "non-increasing table index values."); + prev = value; + } + } axis_values_[index] = axis_values; + } } } @@ -4366,7 +4377,7 @@ LibertyReader::makeTableAxis(int index) const Units *units = library_->units(); float scale = tableVariableUnit(var, units)->scale(); scaleFloats(values, scale); - axis_[index] = std::make_shared(var, values); + axis_[index] = make_shared(var, values); } } @@ -5395,7 +5406,7 @@ RelatedPortGroup::setIsOneToOne(bool one) TimingGroup::TimingGroup(int line) : RelatedPortGroup(line), - attrs_(std::make_shared()), + attrs_(make_shared()), related_output_port_name_(nullptr), receiver_model_(nullptr) { diff --git a/liberty/TableModel.cc b/liberty/TableModel.cc index 4d7fe4df..43063b56 100644 --- a/liberty/TableModel.cc +++ b/liberty/TableModel.cc @@ -1413,7 +1413,7 @@ Table3::report(const Units *units, line = unit2->asString(axis2_->axisValue(axis_index2),digits); line += " |"; for (size_t axis_index3 = 0; axis_index3 < axis3_->size(); axis_index3++) { - line += table_unit->asString(value(axis_index1, axis_index2, axis_index3), digits); + line += table_unit->asString(value(axis_index1, axis_index2, axis_index3),digits); line += " "; } report->reportLineString(line); @@ -1448,19 +1448,18 @@ TableAxis::inBounds(float value) const size_t TableAxis::findAxisIndex(float value) const { - int max = static_cast(values_->size()) - 1; - if (value <= (*values_)[0] || max == 0) + size_t size = values_->size(); + if (size <= 1 || value <= (*values_)[0]) return 0; - else if (value >= (*values_)[max]) - // Return max-1 for value too large so interpolation pts are index,index+1. - return max - 1; + else if (value >= (*values_)[size - 1]) + // Return max_index-1 for value too large so interpolation pts are index,index+1. + return size - 2; else { int lower = -1; - int upper = max + 1; - bool ascend = ((*values_)[max] >= (*values_)[0]); + int upper = size; while (upper - lower > 1) { int mid = (upper + lower) >> 1; - if ((value >= (*values_)[mid]) == ascend) + if (value >= (*values_)[mid]) lower = mid; else upper = mid; @@ -1475,13 +1474,12 @@ TableAxis::findAxisIndex(float value, size_t &index, bool &exists) const { - int max = static_cast(values_->size()) - 1; - if (!values_->empty() + size_t size = values_->size(); + if (size != 0 && value >= (*values_)[0] - && value <= (*values_)[max]) { + && value <= (*values_)[size - 1]) { int lower = -1; - int upper = max + 1; - bool ascend = ((*values_)[max] >= (*values_)[0]); + int upper = size; while (upper - lower > 1) { int mid = (upper + lower) >> 1; if (value == (*values_)[mid]) { @@ -1489,7 +1487,7 @@ TableAxis::findAxisIndex(float value, exists = true; return; } - if ((value > (*values_)[mid]) == ascend) + if (value > (*values_)[mid]) lower = mid; else upper = mid; diff --git a/parasitics/SpefReader.cc b/parasitics/SpefReader.cc index 99e4bd57..cdff33a4 100644 --- a/parasitics/SpefReader.cc +++ b/parasitics/SpefReader.cc @@ -729,6 +729,6 @@ int SpefParse_error(const char *msg) { spefFlushBuffer(); - sta::spef_reader->warn(179, "%s.", msg); + sta::spef_reader->warn(707, "%s.", msg); return 0; }