Allow Liberty floats as strings for `voltage_map` and `capacitive_load_unit` (#280)

* Allow Liberty floats as strings for voltage_map and capacitive_load_unit

* Update liberty_float_as_str.lib

* Use valid bool

* Remove unused include
This commit is contained in:
Akash Levy 2025-08-01 17:41:56 -07:00 committed by GitHub
parent 88c7779680
commit 2e903ab4da
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 99 additions and 3 deletions

View File

@ -26,6 +26,7 @@
#include <cctype> #include <cctype>
#include <cstdlib> #include <cstdlib>
#include <string>
#include "EnumNameMap.hh" #include "EnumNameMap.hh"
#include "Report.hh" #include "Report.hh"
@ -873,8 +874,23 @@ LibertyReader::visitCapacitiveLoadUnit(LibertyAttr *attr)
LibertyAttrValueIterator value_iter(attr->values()); LibertyAttrValueIterator value_iter(attr->values());
if (value_iter.hasNext()) { if (value_iter.hasNext()) {
LibertyAttrValue *value = value_iter.next(); LibertyAttrValue *value = value_iter.next();
bool valid = false;
float scale;
if (value->isFloat()) { if (value->isFloat()) {
float scale = value->floatValue(); scale = value->floatValue();
valid = true;
}
else if (value->isString()) {
try {
scale = std::stof(value->stringValue());
valid = true;
}
catch (...) {
valid = false;
}
}
if (valid) {
if (value_iter.hasNext()) { if (value_iter.hasNext()) {
value = value_iter.next(); value = value_iter.next();
if (value->isString()) { if (value->isString()) {
@ -968,10 +984,24 @@ LibertyReader::visitVoltageMap(LibertyAttr *attr)
const char *supply_name = value->stringValue(); const char *supply_name = value->stringValue();
if (value_iter.hasNext()) { if (value_iter.hasNext()) {
value = value_iter.next(); value = value_iter.next();
bool valid = false;
float voltage;
if (value->isFloat()) { if (value->isFloat()) {
float voltage = value->floatValue(); voltage = value->floatValue();
library_->addSupplyVoltage(supply_name, voltage); valid = true;
} }
else if (value->isString()) {
try {
voltage = std::stof(value->stringValue());
valid = true;
}
catch (...) {
valid = false;
}
}
if (valid)
library_->addSupplyVoltage(supply_name, voltage);
else else
libWarn(1166, attr, "voltage_map voltage is not a float."); libWarn(1166, attr, "voltage_map voltage is not a float.");
} }

View File

@ -0,0 +1,55 @@
library (liberty_float_as_str) {
delay_model : "table_lookup";
simulation : false;
capacitive_load_unit ("1","fF");
leakage_power_unit : "1pW";
current_unit : "1A";
pulling_resistance_unit : "1kohm";
time_unit : "1ns";
voltage_unit : "1v";
library_features : "report_delay_calculation";
input_threshold_pct_rise : 50;
input_threshold_pct_fall : 50;
output_threshold_pct_rise : 50;
output_threshold_pct_fall : 50;
slew_lower_threshold_pct_rise : 30;
slew_lower_threshold_pct_fall : 30;
slew_upper_threshold_pct_rise : 70;
slew_upper_threshold_pct_fall : 70;
slew_derate_from_library : 1.0;
nom_process : 1.0;
nom_temperature : 85.0;
nom_voltage : 0.75;
voltage_map ("VDD", "0.65");
voltage_map ("VSS", "0");
voltage_map ("VCC", "-0.1");
voltage_map ("VBB", 0.1);
voltage_map ("GND", 0);
cell (my_inv) {
pin (A) {
capacitance : 1;
direction : "input";
}
pin (Y) {
function : "!A";
direction : "output";
timing () {
related_pin : "A";
timing_sense : "negative_unate";
cell_rise (scalar) {
values ("1");
}
cell_fall (scalar) {
values ("1");
}
rise_transition (scalar) {
values ("1");
}
fall_transition (scalar) {
values ("1");
}
}
}
}
}

View File

@ -0,0 +1,7 @@
time 1ns
capacitance 1fF
resistance 1kohm
voltage 1v
current 1A
power 1pW
distance 1um

View File

@ -0,0 +1,3 @@
# liberty with float as string in voltage_map and capacitive_load_unit
read_liberty liberty_float_as_str.lib
report_units

View File

@ -147,6 +147,7 @@ record_sta_tests {
liberty_arcs_one2one_2 liberty_arcs_one2one_2
liberty_backslash_eol liberty_backslash_eol
liberty_ccsn liberty_ccsn
liberty_float_as_str
liberty_latch3 liberty_latch3
path_group_names path_group_names
prima3 prima3