Files
OpenSTA/include/sta/TableModel.hh
T

588 lines
19 KiB
C++
Raw Normal View History

2018-09-28 08:54:21 -07:00
// OpenSTA, Static Timing Analyzer
2025-01-21 18:54:33 -07:00
// Copyright (c) 2025, Parallax Software, Inc.
2018-09-28 08:54:21 -07:00
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
2022-01-04 10:17:08 -07:00
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2018-09-28 08:54:21 -07:00
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
2022-01-04 10:17:08 -07:00
// along with this program. If not, see <https://www.gnu.org/licenses/>.
2025-01-21 18:54:33 -07:00
//
// The origin of this software must not be misrepresented; you must not
// claim that you wrote the original software.
//
// Altered source versions must be plainly marked as such, and must not be
// misrepresented as being the original software.
//
// This notice may not be removed or altered from any source distribution.
2018-09-28 08:54:21 -07:00
2020-02-15 17:13:16 -07:00
#pragma once
2018-09-28 08:54:21 -07:00
#include <string>
2022-06-25 16:31:18 -07:00
#include <memory>
2020-04-05 14:53:44 -07:00
#include "MinMax.hh"
#include "Vector.hh"
#include "Transition.hh"
#include "LibertyClass.hh"
#include "TimingModel.hh"
2018-09-28 08:54:21 -07:00
namespace sta {
class Unit;
class Units;
class Report;
class Table;
2023-03-22 09:57:54 -07:00
class OutputWaveforms;
2023-03-23 07:01:04 -07:00
class Table1;
2023-02-08 09:23:24 -07:00
typedef Vector<float> FloatSeq;
typedef Vector<FloatSeq*> FloatTable;
2023-03-23 07:01:04 -07:00
typedef Vector<Table1*> Table1Seq;
2024-06-27 13:57:58 -07:00
typedef Table1 Waveform;
2018-09-28 08:54:21 -07:00
TableAxisVariable
stringTableAxisVariable(const char *variable);
const char *
tableVariableString(TableAxisVariable variable);
const Unit *
tableVariableUnit(TableAxisVariable variable,
const Units *units);
class GateTableModel : public GateTimingModel
{
public:
2023-11-19 10:04:45 -07:00
GateTableModel(LibertyCell *cell,
TableModel *delay_model,
2018-11-26 09:15:52 -08:00
TableModel *delay_sigma_models[EarlyLate::index_count],
TableModel *slew_model,
2023-02-08 09:23:24 -07:00
TableModel *slew_sigma_models[EarlyLate::index_count],
ReceiverModelPtr receiver_model,
2023-03-22 09:57:54 -07:00
OutputWaveforms *output_waveforms);
2018-09-28 08:54:21 -07:00
virtual ~GateTableModel();
2023-11-19 10:04:45 -07:00
void gateDelay(const Pvt *pvt,
2023-03-24 15:15:57 -07:00
float in_slew,
float load_cap,
bool pocv_enabled,
// Return values.
ArcDelay &gate_delay,
Slew &drvr_slew) const override;
2024-06-27 13:57:58 -07:00
// deprecated 2024-01-07
// related_out_cap arg removed.
void gateDelay(const Pvt *pvt,
float in_slew,
float load_cap,
float related_out_cap,
bool pocv_enabled,
ArcDelay &gate_delay,
Slew &drvr_slew) const __attribute__ ((deprecated));
2025-05-22 09:25:56 -07:00
std::string reportGateDelay(const Pvt *pvt,
float in_slew,
float load_cap,
bool pocv_enabled,
int digits) const override;
2023-11-19 10:04:45 -07:00
float driveResistance(const Pvt *pvt) const override;
2018-09-28 08:54:21 -07:00
const TableModel *delayModel() const { return delay_model_; }
const TableModel *slewModel() const { return slew_model_; }
2023-12-13 14:41:59 -07:00
const ReceiverModel *receiverModel() const { return receiver_model_.get(); }
2023-03-22 09:57:54 -07:00
OutputWaveforms *outputWaveforms() const { return output_waveforms_; }
2018-09-28 08:54:21 -07:00
// Check the axes before making the model.
// Return true if the model axes are supported.
2023-12-13 14:41:59 -07:00
static bool checkAxes(const TablePtr &table);
2018-09-28 08:54:21 -07:00
protected:
2023-11-19 10:04:45 -07:00
void maxCapSlew(float in_slew,
2018-09-28 08:54:21 -07:00
const Pvt *pvt,
float &slew,
float &cap) const;
2023-03-24 15:15:57 -07:00
void setIsScaled(bool is_scaled) override;
2023-12-12 15:32:30 -07:00
float axisValue(const TableAxis *axis,
2018-09-28 08:54:21 -07:00
float load_cap,
float in_slew,
float related_out_cap) const;
2023-11-19 10:04:45 -07:00
float findValue(const Pvt *pvt,
2018-09-28 08:54:21 -07:00
const TableModel *model,
float in_slew,
float load_cap,
float related_out_cap) const;
2025-05-22 09:25:56 -07:00
std::string reportTableLookup(const char *result_name,
const Pvt *pvt,
const TableModel *model,
float in_slew,
float load_cap,
float related_out_cap,
int digits) const;
2018-09-28 08:54:21 -07:00
void findAxisValues(const TableModel *model,
float in_slew,
float load_cap,
float related_out_cap,
// Return values.
float &axis_value1,
float &axis_value2,
float &axis_value3) const;
2023-12-12 15:32:30 -07:00
static bool checkAxis(const TableAxis *axis);
2018-09-28 08:54:21 -07:00
TableModel *delay_model_;
2018-11-26 09:15:52 -08:00
TableModel *delay_sigma_models_[EarlyLate::index_count];
2018-09-28 08:54:21 -07:00
TableModel *slew_model_;
2018-11-26 09:15:52 -08:00
TableModel *slew_sigma_models_[EarlyLate::index_count];
2023-02-08 09:23:24 -07:00
ReceiverModelPtr receiver_model_;
2023-03-22 09:57:54 -07:00
OutputWaveforms *output_waveforms_;
2018-09-28 08:54:21 -07:00
};
class CheckTableModel : public CheckTimingModel
{
public:
2023-11-19 10:04:45 -07:00
explicit CheckTableModel(LibertyCell *cell,
TableModel *model,
2019-06-04 08:12:22 -07:00
TableModel *sigma_models[EarlyLate::index_count]);
2018-09-28 08:54:21 -07:00
virtual ~CheckTableModel();
ArcDelay checkDelay(const Pvt *pvt,
float from_slew,
float to_slew,
float related_out_cap,
bool pocv_enabled) const override;
2025-05-22 09:25:56 -07:00
std::string reportCheckDelay(const Pvt *pvt,
float from_slew,
const char *from_slew_annotation,
float to_slew,
float related_out_cap,
bool pocv_enabled,
int digits) const override;
2022-06-06 20:57:09 -07:00
const TableModel *model() const { return model_; }
2018-09-28 08:54:21 -07:00
// Check the axes before making the model.
// Return true if the model axes are supported.
2023-01-18 10:23:03 -07:00
static bool checkAxes(const TablePtr table);
2018-09-28 08:54:21 -07:00
protected:
2023-03-24 15:15:57 -07:00
void setIsScaled(bool is_scaled) override;
2023-11-19 10:04:45 -07:00
float findValue(const Pvt *pvt,
2019-01-26 23:03:01 -08:00
const TableModel *model,
float from_slew,
float to_slew,
float related_out_cap) const;
2018-09-28 08:54:21 -07:00
void findAxisValues(float from_slew,
float to_slew,
float related_out_cap,
// Return values.
float &axis_value1,
float &axis_value2,
float &axis_value3) const;
2023-12-12 15:32:30 -07:00
float axisValue(const TableAxis *axis,
2018-09-28 08:54:21 -07:00
float load_cap,
float in_slew,
float related_out_cap) const;
2025-05-22 09:25:56 -07:00
std::string reportTableDelay(const char *result_name,
const Pvt *pvt,
const TableModel *model,
float from_slew,
const char *from_slew_annotation,
float to_slew,
float related_out_cap,
int digits) const;
2023-12-12 15:32:30 -07:00
static bool checkAxis(const TableAxis *axis);
2018-09-28 08:54:21 -07:00
TableModel *model_;
2019-01-26 23:03:01 -08:00
TableModel *sigma_models_[EarlyLate::index_count];
2018-09-28 08:54:21 -07:00
};
// Wrapper class for Table to apply scale factors.
class TableModel
{
public:
2023-01-18 10:23:03 -07:00
TableModel(TablePtr table,
2022-06-06 20:57:09 -07:00
TableTemplate *tbl_template,
2018-09-28 08:54:21 -07:00
ScaleFactorType scale_factor_type,
2023-10-04 14:33:09 -07:00
const RiseFall *rf);
2018-09-28 08:54:21 -07:00
void setScaleFactorType(ScaleFactorType type);
int order() const;
2022-06-06 20:57:09 -07:00
TableTemplate *tblTemplate() const { return tbl_template_; }
2023-12-12 15:32:30 -07:00
const TableAxis *axis1() const;
const TableAxis *axis2() const;
const TableAxis *axis3() const;
2018-09-28 08:54:21 -07:00
void setIsScaled(bool is_scaled);
2022-06-06 20:57:09 -07:00
float value(size_t index1,
size_t index2,
size_t index3) const;
2018-09-28 08:54:21 -07:00
// Table interpolated lookup.
float findValue(float value1,
float value2,
float value3) const;
// Table interpolated lookup with scale factor.
2023-11-19 10:04:45 -07:00
float findValue(const LibertyCell *cell,
2018-09-28 08:54:21 -07:00
const Pvt *pvt,
float value1,
float value2,
float value3) const;
2025-05-22 09:25:56 -07:00
std::string reportValue(const char *result_name,
const LibertyCell *cell,
const Pvt *pvt,
float value1,
const char *comment1,
float value2,
float value3,
const Unit *table_unit,
int digits) const;
std::string report(const Units *units,
Report *report) const;
2018-09-28 08:54:21 -07:00
protected:
2023-11-19 10:04:45 -07:00
float scaleFactor(const LibertyCell *cell,
2018-09-28 08:54:21 -07:00
const Pvt *pvt) const;
2025-05-22 09:25:56 -07:00
std::string reportPvtScaleFactor(const LibertyCell *cell,
const Pvt *pvt,
int digits) const;
2018-09-28 08:54:21 -07:00
2023-01-18 10:23:03 -07:00
TablePtr table_;
2022-06-06 20:57:09 -07:00
TableTemplate *tbl_template_;
2019-03-12 17:25:53 -07:00
// ScaleFactorType gcc barfs if this is dcl'd.
unsigned scale_factor_type_:scale_factor_bits;
2023-03-07 17:03:26 -07:00
unsigned rf_index_:RiseFall::index_bit_count;
2018-09-28 08:54:21 -07:00
bool is_scaled_:1;
};
2023-02-08 09:23:24 -07:00
// Abstract base class for 0, 1, 2, or 3 dimesnion float tables.
2018-09-28 08:54:21 -07:00
class Table
{
public:
Table() {}
virtual ~Table() {}
void setScaleFactorType(ScaleFactorType type);
virtual int order() const = 0;
2023-12-12 15:32:30 -07:00
virtual const TableAxis *axis1() const { return nullptr; }
virtual const TableAxis *axis2() const { return nullptr; }
virtual const TableAxis *axis3() const { return nullptr; }
2018-09-28 08:54:21 -07:00
void setIsScaled(bool is_scaled);
2022-06-06 20:57:09 -07:00
virtual float value(size_t axis_idx1,
size_t axis_idx2,
size_t axis_idx3) const = 0;
2018-09-28 08:54:21 -07:00
// Table interpolated lookup.
2023-03-23 07:01:04 -07:00
virtual float findValue(float axis_value1,
float axis_value2,
float axis_value3) const = 0;
2018-09-28 08:54:21 -07:00
// Table interpolated lookup with scale factor.
float findValue(const LibertyLibrary *library,
const LibertyCell *cell,
const Pvt *pvt,
2023-03-23 07:01:04 -07:00
float axis_value1,
float axis_value2,
float axis_value3) const;
2025-05-22 09:25:56 -07:00
virtual std::string reportValue(const char *result_name,
const LibertyCell *cell,
const Pvt *pvt,
float value1,
const char *comment1,
float value2,
float value3,
const Unit *table_unit,
int digits) const = 0;
2018-09-28 08:54:21 -07:00
virtual void report(const Units *units,
Report *report) const = 0;
};
// Zero dimension (scalar) table.
class Table0 : public Table
{
public:
Table0(float value);
2023-03-24 15:15:57 -07:00
int order() const override { return 0; }
float value(size_t axis_index1,
size_t axis_index2,
size_t axis_index3) const override;
float findValue(float axis_value1,
float axis_value2,
float axis_value3) const override;
2025-05-22 09:25:56 -07:00
std::string reportValue(const char *result_name,
const LibertyCell *cell,
const Pvt *pvt,
float value1,
const char *comment1,
float value2,
float value3,
const Unit *table_unit,
int digits) const override;
2023-03-24 15:15:57 -07:00
void report(const Units *units,
Report *report) const override;
2018-09-28 08:54:21 -07:00
using Table::findValue;
private:
float value_;
};
// One dimensional table.
class Table1 : public Table
{
public:
2023-03-22 09:57:54 -07:00
Table1();
2018-09-28 08:54:21 -07:00
Table1(FloatSeq *values,
2022-06-25 16:31:18 -07:00
TableAxisPtr axis1);
2018-09-28 08:54:21 -07:00
virtual ~Table1();
2023-03-22 09:57:54 -07:00
Table1(Table1 &&table);
2024-02-27 10:00:48 -07:00
Table1(const Table1 &table);
2023-03-22 09:57:54 -07:00
Table1 &operator= (Table1 &&table);
2023-03-24 15:15:57 -07:00
int order() const override { return 1; }
2023-12-12 15:32:30 -07:00
const TableAxis *axis1() const override { return axis1_.get(); }
2023-12-13 14:41:59 -07:00
const TableAxisPtr axis1ptr() const { return axis1_; }
2023-03-24 15:15:57 -07:00
float value(size_t axis_index1,
size_t axis_index2,
size_t axis_index3) const override;
float findValue(float value1,
float value2,
float value3) const override;
2025-05-22 09:25:56 -07:00
std::string reportValue(const char *result_name,
const LibertyCell *cell,
const Pvt *pvt,
float value1,
const char *comment1,
float value2,
float value3,
const Unit *table_unit,
int digits) const override;
2023-03-24 15:15:57 -07:00
void report(const Units *units,
Report *report) const override;
// Table1 specific functions.
2022-06-06 20:57:09 -07:00
float value(size_t index1) const;
2023-03-23 07:01:04 -07:00
void findValue(float axis_value1,
// Return values.
float &value,
bool &extrapolated) const;
2023-03-24 15:15:57 -07:00
float findValue(float axis_value1) const;
2023-03-30 18:52:43 -07:00
float findValueClip(float axis_value1) const;
2023-03-22 09:57:54 -07:00
FloatSeq *values() const { return values_; }
2018-09-28 08:54:21 -07:00
using Table::findValue;
private:
FloatSeq *values_;
2022-06-25 16:31:18 -07:00
TableAxisPtr axis1_;
2018-09-28 08:54:21 -07:00
};
// Two dimensional table.
class Table2 : public Table
{
public:
Table2(FloatTable *values,
2022-06-25 16:31:18 -07:00
TableAxisPtr axis1,
TableAxisPtr axis2);
2018-09-28 08:54:21 -07:00
virtual ~Table2();
2023-03-24 15:15:57 -07:00
int order() const override { return 2; }
2023-12-12 15:32:30 -07:00
const TableAxis *axis1() const override { return axis1_.get(); }
const TableAxis *axis2() const override { return axis2_.get(); }
2023-03-24 15:15:57 -07:00
float value(size_t axis_index1,
size_t axis_index2,
size_t axis_index3) const override;
float findValue(float value1,
float value2,
float value3) const override;
2025-05-22 09:25:56 -07:00
std::string reportValue(const char *result_name,
const LibertyCell *cell,
const Pvt *pvt,
float value1,
const char *comment1,
float value2,
float value3,
const Unit *table_unit,
int digits) const override;
2023-03-24 15:15:57 -07:00
void report(const Units *units,
Report *report) const override;
// Table2 specific functions.
2023-03-23 07:01:04 -07:00
float value(size_t axis_index1,
size_t axis_index2) const;
2023-02-08 09:23:24 -07:00
FloatTable *values3() { return values_; }
2023-03-24 15:15:57 -07:00
2018-09-28 08:54:21 -07:00
using Table::findValue;
protected:
FloatTable *values_;
// Row.
2022-06-25 16:31:18 -07:00
TableAxisPtr axis1_;
2018-09-28 08:54:21 -07:00
// Column.
2022-06-25 16:31:18 -07:00
TableAxisPtr axis2_;
2018-09-28 08:54:21 -07:00
};
// Three dimensional table.
class Table3 : public Table2
{
public:
Table3(FloatTable *values,
2022-06-25 16:31:18 -07:00
TableAxisPtr axis1,
TableAxisPtr axis2,
TableAxisPtr axis3);
virtual ~Table3() {}
2023-03-24 15:15:57 -07:00
int order() const override { return 3; }
2023-12-12 15:32:30 -07:00
const TableAxis *axis1() const override { return axis1_.get(); }
const TableAxis *axis2() const override { return axis2_.get(); }
const TableAxis *axis3() const override { return axis3_.get(); }
2023-03-24 15:15:57 -07:00
float value(size_t axis_index1,
size_t axis_index2,
size_t axis_index3) const override;
float findValue(float value1,
float value2,
float value3) const override;
2025-05-22 09:25:56 -07:00
std::string reportValue(const char *result_name,
const LibertyCell *cell,
const Pvt *pvt,
float value1,
const char *comment1,
float value2,
float value3,
const Unit *table_unit,
int digits) const override;
2023-03-24 15:15:57 -07:00
void report(const Units *units,
Report *report) const override;
2018-09-28 08:54:21 -07:00
using Table::findValue;
private:
2022-06-25 16:31:18 -07:00
TableAxisPtr axis3_;
2018-09-28 08:54:21 -07:00
};
class TableAxis
{
public:
TableAxis(TableAxisVariable variable,
FloatSeq *values);
~TableAxis();
TableAxisVariable variable() const { return variable_; }
2023-02-08 09:23:24 -07:00
const char *variableString() const;
const Unit *unit(const Units *units);
2018-09-28 08:54:21 -07:00
size_t size() const { return values_->size(); }
2023-05-10 09:03:17 -07:00
bool inBounds(float value) const;
2018-09-28 08:54:21 -07:00
float axisValue(size_t index) const { return (*values_)[index]; }
// Find the index for value such that axis[index] <= value < axis[index+1].
size_t findAxisIndex(float value) const;
2023-02-08 09:23:24 -07:00
void findAxisIndex(float value,
// Return values.
size_t &index,
bool &exists) const;
2024-06-27 13:57:58 -07:00
size_t findAxisClosestIndex(float value) const;
2022-06-11 16:28:13 -07:00
FloatSeq *values() const { return values_; }
2024-06-27 13:57:58 -07:00
float min() const;
float max() const;
2018-09-28 08:54:21 -07:00
private:
TableAxisVariable variable_;
FloatSeq *values_;
};
2023-02-08 09:23:24 -07:00
////////////////////////////////////////////////////////////////
class ReceiverModel
{
public:
~ReceiverModel();
void setCapacitanceModel(TableModel *table_model,
size_t segment,
2025-03-30 15:27:53 -07:00
const RiseFall *rf);
2023-02-08 09:23:24 -07:00
static bool checkAxes(TablePtr table);
private:
std::vector<TableModel*> capacitance_models_;
2023-02-08 09:23:24 -07:00
};
2023-03-22 09:57:54 -07:00
// Two dimensional (slew/cap) table of one dimensional time/current tables.
class OutputWaveforms
2023-02-08 09:23:24 -07:00
{
public:
2023-03-22 09:57:54 -07:00
OutputWaveforms(TableAxisPtr slew_axis,
TableAxisPtr cap_axis,
2023-03-30 18:52:43 -07:00
const RiseFall *rf,
2023-03-23 07:01:04 -07:00
Table1Seq &current_waveforms,
2024-02-11 11:45:40 -07:00
Table1 *ref_times);
2023-03-22 09:57:54 -07:00
~OutputWaveforms();
2023-03-30 18:52:43 -07:00
const RiseFall *rf() const { return rf_; }
2023-12-13 14:41:59 -07:00
const TableAxis *slewAxis() const { return slew_axis_.get(); }
const TableAxis *capAxis() const { return cap_axis_.get(); }
2024-06-27 13:57:58 -07:00
// Make voltage wavefroms from liberty time/current values.
// Required before voltageTime, timeVoltage, voltageCurrent.
2024-07-31 16:36:24 -07:00
void ensureVoltageWaveforms(float vdd);
2023-05-24 16:52:29 -06:00
float timeCurrent(float slew,
float cap,
float time);
2023-12-31 14:05:58 -07:00
float timeVoltage(float slew,
float cap,
float time);
2024-06-27 13:57:58 -07:00
float voltageTime(float in_slew,
float load_cap,
float voltage);
2023-05-24 16:52:29 -06:00
float voltageCurrent(float slew,
float cap,
float volt);
2023-03-23 07:01:04 -07:00
float referenceTime(float slew);
2024-06-27 13:57:58 -07:00
float beginTime(float slew,
float cap);
float endTime(float slew,
float cap);
2023-12-13 14:41:59 -07:00
static bool checkAxes(const TableTemplate *tbl_template);
2023-02-08 09:23:24 -07:00
2024-06-27 13:57:58 -07:00
Table1 currentWaveform(float slew,
float cap);
// Waveform closest to slew/cap; no interpolation.
const Table1 *currentWaveformRaw(float slew,
float cap);
Table1 voltageWaveform(float in_slew,
float load_cap);
// Waveform closest to slew/cap; no interpolation.
const Table1 *voltageWaveformRaw(float slew,
float cap);
Table1 voltageCurrentWaveform(float slew,
float cap);
// V/I for last segment of min slew/max cap.
float finalResistance();
2023-02-08 09:23:24 -07:00
private:
2024-02-08 20:13:25 -07:00
void findVoltages(size_t wave_index,
float cap);
2023-12-31 14:05:58 -07:00
float waveformValue(float slew,
float cap,
float axis_value,
Table1Seq &waveforms);
2024-06-27 13:57:58 -07:00
float beginEndTime(float slew,
float cap,
bool begin);
double voltageTime1(double volt,
double dx1,
double dx2,
size_t wave_index00,
size_t wave_index01,
size_t wave_index10,
size_t wave_index11);
float voltageTime2(float volt,
2023-12-31 14:05:58 -07:00
size_t wave_index);
2023-03-23 07:01:04 -07:00
2023-02-08 09:23:24 -07:00
// Row.
2023-03-22 09:57:54 -07:00
TableAxisPtr slew_axis_;
2023-02-08 09:23:24 -07:00
// Column.
2023-03-22 09:57:54 -07:00
TableAxisPtr cap_axis_;
2023-03-30 18:52:43 -07:00
const RiseFall *rf_;
2024-06-27 13:57:58 -07:00
Table1Seq current_waveforms_; // from liberty
2023-12-31 14:05:58 -07:00
Table1Seq voltage_waveforms_;
2023-05-24 16:52:29 -06:00
Table1Seq voltage_currents_;
2023-03-23 07:01:04 -07:00
Table1 *ref_times_;
2023-05-09 19:42:53 -07:00
float vdd_;
2024-06-27 13:57:58 -07:00
static constexpr size_t voltage_waveform_step_count_ = 100;
2023-03-22 09:57:54 -07:00
};
class DriverWaveform
{
public:
2025-05-22 09:25:56 -07:00
DriverWaveform(const std::string &name,
2023-03-22 09:57:54 -07:00
TablePtr waveforms);
2025-03-30 15:27:53 -07:00
const char *name() const { return name_.c_str(); }
2023-03-22 09:57:54 -07:00
Table1 waveform(float slew);
private:
2025-05-22 09:25:56 -07:00
std::string name_;
2023-03-22 09:57:54 -07:00
TablePtr waveforms_;
2023-02-08 09:23:24 -07:00
};
2018-09-28 08:54:21 -07:00
} // namespace