Files
OpenSTA/include/sta/TableModel.hh
T

568 lines
18 KiB
C++
Raw Normal View History

2018-09-28 08:54:21 -07:00
// OpenSTA, Static Timing Analyzer
2023-02-18 17:55:40 -07:00
// Copyright (c) 2023, 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/>.
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 {
using std::string;
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;
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:
GateTableModel(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-03-24 15:15:57 -07:00
void gateDelay(const LibertyCell *cell,
const Pvt *pvt,
float in_slew,
float load_cap,
float related_out_cap,
bool pocv_enabled,
// Return values.
ArcDelay &gate_delay,
Slew &drvr_slew) const override;
string reportGateDelay(const LibertyCell *cell,
const Pvt *pvt,
float in_slew,
float load_cap,
float related_out_cap,
bool pocv_enabled,
int digits) const override;
float driveResistance(const LibertyCell *cell,
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-03-22 09:57:54 -07:00
ReceiverModelPtr receiverModel() const { return receiver_model_; }
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-01-18 10:23:03 -07:00
static bool checkAxes(const TablePtr table);
2018-09-28 08:54:21 -07:00
protected:
void maxCapSlew(const LibertyCell *cell,
float in_slew,
const Pvt *pvt,
float &slew,
float &cap) const;
2023-03-24 15:15:57 -07:00
void setIsScaled(bool is_scaled) override;
2022-06-25 16:31:18 -07:00
float axisValue(TableAxisPtr axis,
2018-09-28 08:54:21 -07:00
float load_cap,
float in_slew,
float related_out_cap) const;
float findValue(const LibertyLibrary *library,
const LibertyCell *cell,
const Pvt *pvt,
const TableModel *model,
float in_slew,
float load_cap,
float related_out_cap) const;
2023-03-24 15:15:57 -07:00
string reportTableLookup(const char *result_name,
const LibertyLibrary *library,
const LibertyCell *cell,
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;
2022-06-25 16:31:18 -07:00
static bool checkAxis(TableAxisPtr 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:
2019-06-04 08:12:22 -07:00
explicit CheckTableModel(TableModel *model,
TableModel *sigma_models[EarlyLate::index_count]);
2018-09-28 08:54:21 -07:00
virtual ~CheckTableModel();
2023-03-24 15:15:57 -07:00
void checkDelay(const LibertyCell *cell,
const Pvt *pvt,
float from_slew,
float to_slew,
float related_out_cap,
bool pocv_enabled,
// Return values.
ArcDelay &margin) const override;
string reportCheckDelay(const LibertyCell *cell,
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;
2019-01-26 23:03:01 -08:00
float findValue(const LibertyLibrary *library,
const LibertyCell *cell,
const Pvt *pvt,
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;
2022-06-25 16:31:18 -07:00
float axisValue(TableAxisPtr axis,
2018-09-28 08:54:21 -07:00
float load_cap,
float in_slew,
float related_out_cap) const;
2023-03-24 15:15:57 -07:00
string reportTableDelay(const char *result_name,
const LibertyLibrary *library,
const LibertyCell *cell,
const Pvt *pvt,
const TableModel *model,
float from_slew,
const char *from_slew_annotation,
float to_slew,
float related_out_cap,
int digits) const;
2022-06-25 16:31:18 -07:00
static bool checkAxis(TableAxisPtr 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,
2019-11-11 15:30:19 -07:00
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_; }
2022-06-25 16:31:18 -07:00
TableAxisPtr axis1() const;
TableAxisPtr axis2() const;
TableAxisPtr 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.
float findValue(const LibertyLibrary *library,
const LibertyCell *cell,
const Pvt *pvt,
float value1,
float value2,
float value3) const;
2023-03-24 15:15:57 -07:00
string reportValue(const char *result_name,
const LibertyLibrary *library,
const LibertyCell *cell,
const Pvt *pvt,
float value1,
const char *comment1,
float value2,
float value3,
const Unit *table_unit,
int digits) const;
string report(const Units *units,
Report *report) const;
2018-09-28 08:54:21 -07:00
protected:
float scaleFactor(const LibertyLibrary *library,
const LibertyCell *cell,
const Pvt *pvt) const;
2023-03-24 15:15:57 -07:00
string reportPvtScaleFactor(const LibertyLibrary *library,
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;
2022-06-25 16:31:18 -07:00
virtual TableAxisPtr axis1() const { return nullptr; }
virtual TableAxisPtr axis2() const { return nullptr; }
virtual TableAxisPtr 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;
2023-03-24 15:15:57 -07:00
virtual string reportValue(const char *result_name,
const LibertyLibrary *library,
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;
string reportValue(const char *result_name,
const LibertyLibrary *library,
const LibertyCell *cell,
const Pvt *pvt,
float value1,
const char *comment1,
float value2,
float value3,
const Unit *table_unit,
int digits) const override;
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);
Table1 &operator= (Table1 &&table);
2023-03-24 15:15:57 -07:00
int order() const override { return 1; }
TableAxisPtr axis1() const override { return axis1_; }
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;
string reportValue(const char *result_name,
const LibertyLibrary *library,
const LibertyCell *cell,
const Pvt *pvt,
float value1,
const char *comment1,
float value2,
float value3,
const Unit *table_unit,
int digits) const override;
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-05-24 16:52:29 -06:00
float findValueClipZero(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; }
TableAxisPtr axis1() const override { return axis1_; }
TableAxisPtr axis2() const override { return axis2_; }
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;
string reportValue(const char *result_name,
const LibertyLibrary *library,
const LibertyCell *cell,
const Pvt *pvt,
float value1,
const char *comment1,
float value2,
float value3,
const Unit *table_unit,
int digits) const override;
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; }
TableAxisPtr axis1() const override { return axis1_; }
TableAxisPtr axis2() const override { return axis2_; }
TableAxisPtr axis3() const override { return axis3_; }
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;
string reportValue(const char *result_name,
const LibertyLibrary *library,
const LibertyCell *cell,
const Pvt *pvt,
float value1,
const char *comment1,
float value2,
float value3,
const Unit *table_unit,
int digits) const override;
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;
2022-06-11 16:28:13 -07:00
FloatSeq *values() const { return values_; }
2023-03-22 09:57:54 -07:00
float min() const { return (*values_)[0]; }
float max() const { return (*values_)[values_->size() - 1]; }
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();
~ReceiverModel();
void setCapacitanceModel(TableModel *table_model,
int index,
RiseFall *rf);
static bool checkAxes(TablePtr table);
private:
TableModel *capacitance_models_[2][RiseFall::index_count];
};
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,
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-05-24 16:52:29 -06:00
TableAxisPtr slewAxis() const { return slew_axis_; }
TableAxisPtr capAxis() const { return cap_axis_; }
2023-03-23 07:01:04 -07:00
Table1 voltageWaveform(float in_slew,
float load_cap);
2023-05-06 15:34:41 -07:00
float voltageTime(float in_slew,
float load_cap,
float voltage);
2023-05-03 22:08:51 -07:00
const Table1 *currentWaveform(float slew,
float cap);
2023-05-24 16:52:29 -06:00
float timeCurrent(float slew,
float cap,
float time);
float voltageCurrent(float slew,
float cap,
float volt);
2023-03-23 07:01:04 -07:00
float referenceTime(float slew);
2023-05-09 19:42:53 -07:00
void setVdd(float vdd);
2023-03-23 07:01:04 -07:00
static bool checkAxes(TableTemplate *tbl_template);
2023-02-08 09:23:24 -07:00
private:
2023-05-06 15:34:41 -07:00
float voltageTime1(float voltage,
size_t wave_index,
float cap);
FloatSeq *voltageTimes(size_t wave_index,
float cap);
2023-05-24 16:52:29 -06:00
void findVoltages(size_t wave_index,
float cap);
const Table1 *voltageCurrents(size_t wave_index,
float cap);
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_;
2023-03-23 07:01:04 -07:00
Table1Seq current_waveforms_;
2023-05-24 16:52:29 -06:00
Table1Seq voltage_currents_;
2023-05-06 15:34:41 -07:00
FloatTable voltage_times_;
2023-03-23 07:01:04 -07:00
Table1 *ref_times_;
2023-05-09 19:42:53 -07:00
float vdd_;
2023-05-06 15:34:41 -07:00
static constexpr size_t voltage_waveform_step_count_ = 20;
2023-03-22 09:57:54 -07:00
};
class DriverWaveform
{
public:
DriverWaveform(const char *name,
TablePtr waveforms);
~DriverWaveform();
const char *name() const { return name_; }
Table1 waveform(float slew);
private:
const char *name_;
TablePtr waveforms_;
2023-02-08 09:23:24 -07:00
};
2018-09-28 08:54:21 -07:00
} // namespace